diff options
author | dzwdz | 2023-01-06 20:45:30 +0100 |
---|---|---|
committer | dzwdz | 2023-01-06 20:45:30 +0100 |
commit | e0c7bad47a54d865ef6194643e2cd20f6094e507 (patch) | |
tree | a9c731aecaad9c08ff4e732ae5dc8941a60cddd4 /src/kernel | |
parent | aedefd551da5e50f89eeaf74a7d6e1a76760ec7b (diff) |
kernel: turn the NULLFS into an always present special handle
preparing for HANDLE_PROCFS
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/proc.c | 14 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 12 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 85992d5..6bc7754 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -287,6 +287,14 @@ handle_t process_find_free_handle(struct process *proc, handle_t start_at) { } struct handle *process_handle_get(struct process *p, handle_t id) { + if (id == HANDLE_NULLFS) { + static struct handle h = (struct handle){ + .type = HANDLE_FS_FRONT, + .backend = NULL, + .refcount = 2, + }; + return &h; + } if (id < 0 || id >= HANDLE_MAX) return NULL; return p->_handles[id]; } @@ -311,7 +319,7 @@ handle_t process_handle_dup(struct process *p, handle_t from, handle_t to) { if (to == from) return to; toh = &p->_handles[to]; - fromh = (from >= 0 && from < HANDLE_MAX) ? p->_handles[from] : NULL; + fromh = process_handle_get(p, from); if (*toh) handle_close(*toh); *toh = fromh; @@ -321,7 +329,9 @@ handle_t process_handle_dup(struct process *p, handle_t from, handle_t to) { } struct handle *process_handle_take(struct process *p, handle_t hid) { - if (hid < 0 || hid >= HANDLE_MAX) return NULL; + if (hid < 0 || hid >= HANDLE_MAX) { + return process_handle_get(p, hid); + } struct handle *h = p->_handles[hid]; p->_handles[hid] = NULL; return h; diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 88e98c6..2ace0f4 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -145,13 +145,11 @@ long _syscall_mount(handle_t hid, const char __user *path, long len) { len--; } - if (hid >= 0) { // mounting a real backend? - struct handle *handle = process_handle_get(process_current, hid); - if (!handle || handle->type != HANDLE_FS_FRONT) - goto fail; - backend = handle->backend; - backend->refcount++; - } // otherwise backend == NULL + struct handle *handle = process_handle_get(process_current, hid); + if (!handle || handle->type != HANDLE_FS_FRONT) + goto fail; + backend = handle->backend; + if (backend) backend->refcount++; // append to mount list // TODO move to kernel/vfs/mount.c |