Skip to content

Commit

Permalink
Processes: System continues to work if error (fault) occured.
Browse files Browse the repository at this point in the history
Syscalls: Add writing functionality
  • Loading branch information
NDRAEY committed Jul 27, 2024
1 parent 823add2 commit 9489fe4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 6 deletions.
5 changes: 3 additions & 2 deletions kernel/include/sys/file_descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ struct fd_info {
};

void file_descriptors_init();
void file_descriptor_allocate(const char *filename, const char *mode, int *out);
void file_descriptor_allocate(const char *filename, size_t mode, int *out);
void file_descriptor_read(int descriptor_number, size_t count, void* buffer);
void file_descriptor_write(int descriptor_number, size_t count, const void* buffer);
void file_descriptor_close(int descriptor_number);
void file_descriptor_seek(int descriptor_number, ssize_t value, size_t whence);
void file_descriptor_tell(int descriptor_number, int* out);
void file_descriptor_tell(int descriptor_number, int* out);
2 changes: 1 addition & 1 deletion kernel/include/sys/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

typedef size_t syscall_fn_t (size_t, size_t, size_t);

#define NUM_CALLS 19
#define NUM_CALLS 20

void init_syscalls(void);
extern size_t syscall_entry_call(void* entry_point, void* param1, void* param2, void* param3);
Expand Down
7 changes: 6 additions & 1 deletion kernel/src/sys/cpu_isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ _Noreturn void sod_screen_legacy(registers_t regs, char* title, char* msg, uint3

qemu_err("PROCESS CAUSED THE EXCEPTION: nr. %d", get_current_proc()->pid);

if(get_current_proc()->pid != 0) {
qemu_note("EXIT HERE");
blyat_fire();
}

__asm__ volatile("cli"); // Disable interrupts
__asm__ volatile("hlt"); // Halt

Expand Down Expand Up @@ -212,7 +217,7 @@ void page_fault(registers_t regs){
}
qemu_log("at address (virtual) %x",fault_addr);

tty_printf("Page fault: ");
tty_printf("Process nr.%d caused page fault: ", get_current_proc()->pid);
if (present){
tty_printf("NOT PRESENT, ");
}
Expand Down
23 changes: 21 additions & 2 deletions kernel/src/sys/file_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void file_descriptors_init() {
qemu_log("File descriptors initialized");
}

void file_descriptor_allocate(const char *filename, const char *mode, int *out) {
FILE* file = fopen(filename, mode);
void file_descriptor_allocate(const char *filename, size_t mode, int *out) {
FILE* file = fopen_binmode(filename, mode);

if(!file) {
*out = -1;
Expand Down Expand Up @@ -70,6 +70,25 @@ void file_descriptor_read(int descriptor_number, size_t count, void* buffer) {
fread(inf->file, count, 1, buffer);
}

void file_descriptor_write(int descriptor_number, size_t count, const void* buffer) {
qemu_log("FD: %d; Size: %d; Buffer: %x", descriptor_number, count, buffer);

if(descriptor_number < 0 || descriptor_number >= last_descriptor_number) {
qemu_err("Invalid descriptor: %d!", descriptor_number);
return;
}

if(!file_descriptor_get(descriptor_number)) {
return;
}

struct fd_info* inf = file_descriptor_get(descriptor_number);

qemu_note("Read: %d bytes (buffer at: %x)", count, buffer);

fwrite(inf->file, count, 1, buffer);
}

void file_descriptor_close(int descriptor_number) {
if(descriptor_number < 0 || descriptor_number >= last_descriptor_number)
return;
Expand Down
1 change: 1 addition & 0 deletions kernel/src/sys/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void init_syscalls(void){
calls_table[16] = (syscall_fn_t *)syscall_datetime;
calls_table[17] = (syscall_fn_t *)syscall_exit;
calls_table[18] = (syscall_fn_t *)syscall_memory_realloc;
calls_table[19] = (syscall_fn_t *)file_descriptor_write;

qemu_ok("System calls initialized!");
}
Binary file added ramdisk/empty
Binary file not shown.
Binary file added ramdisk/filetest
Binary file not shown.

0 comments on commit 9489fe4

Please sign in to comment.