diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/proc.c | 10 | ||||
-rw-r--r-- | src/kernel/proc.h | 1 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 6 |
3 files changed, 12 insertions, 5 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 19b09a8..e504a5d 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -90,3 +90,13 @@ struct process *_process_find_recursive( struct process *process_find(enum process_state target) { return _process_find_recursive(target, process_first); } + +handle_t process_find_handle(struct process *proc) { + handle_t handle; + for (handle = 0; handle < HANDLE_MAX; handle++) { + if (proc->handles[handle].type == HANDLE_EMPTY) + break; + } + if (handle == HANDLE_MAX) handle = -1; + return handle; +} diff --git a/src/kernel/proc.h b/src/kernel/proc.h index ed7c656..447dac8 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -43,3 +43,4 @@ _Noreturn void process_switch(struct process *proc); _Noreturn void process_switch_any(void); // switches to any running process struct process *process_find(enum process_state); +handle_t process_find_handle(struct process *proc); // finds the first free handle diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 98df4f3..002f3fd 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -75,11 +75,7 @@ handle_t _syscall_fs_open(const user_ptr path, int len) { if (len > PATH_MAX) return -1; // find the first free handle - for (handle = 0; handle < HANDLE_MAX; handle++) { - if (process_current->handles[handle].type == HANDLE_EMPTY) - break; - } - if (handle == HANDLE_MAX) return -1; + handle = process_find_handle(process_current); // copy the path to the kernel virt_iter_new(&iter, path, len, process_current->pages, true, false); |