diff options
author | dzwdz | 2023-08-31 01:06:41 +0200 |
---|---|---|
committer | dzwdz | 2023-08-31 01:06:41 +0200 |
commit | 6cbe58797781cb8514a62bb3ab0e3e8a5d58bce2 (patch) | |
tree | bc405a3bc28dce58f1a7141640a5e0605363224c /src/kernel | |
parent | cf7877737ff5032f8bad59d57b048f66c4813b5b (diff) |
kernel: add _sys_getprocfs in place of HANDLE_PROCFS
This makes the side-effects more explicit, and feels less hacky than
`HANDLE_PROCFS`. I don't think accessing a handle alone should have
side-effects, even if it's a "special" one.
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/proc.c | 14 | ||||
-rw-r--r-- | src/kernel/proc.h | 3 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 18 |
3 files changed, 17 insertions, 18 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c index bbf939c..1084f48 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -6,7 +6,6 @@ #include <kernel/panic.h> #include <kernel/proc.h> #include <kernel/vfs/mount.h> -#include <kernel/vfs/procfs.h> #include <shared/mem.h> #include <stdint.h> @@ -384,7 +383,6 @@ void proc_tryreap(Proc *dead) { return; /* keep the tombstone */ } - handle_close(dead->specialh.procfs); assert(dead->refcount == 0); if (parent) { /* not applicable to init */ proc_forget(dead); @@ -513,18 +511,6 @@ Handle *proc_handle_get(Proc *p, hid_t id) { .refcount = 2, /* never free */ }; return &h; - } else if (id == HANDLE_PROCFS) { - if (!p->specialh.procfs) { - Handle *h = kmalloc(sizeof *h); - proc_ns_create(p); - *h = (Handle){ - .type = HANDLE_FS_FRONT, - .backend = procfs_backend(p), - .refcount = 1, - }; - p->specialh.procfs = h; - } - return p->specialh.procfs; } else if (0 <= id && id < HANDLE_MAX) { return p->_handles[id]; } else { diff --git a/src/kernel/proc.h b/src/kernel/proc.h index 0dffe08..15da852 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -69,9 +69,6 @@ struct Proc { VfsMount *mount; Handle **_handles; /* points to Handle *[HANDLE_MAX] */ uint64_t *handles_refcount; /* works just like pages_refcount */ - struct { - Handle *procfs; - } specialh; // TODO pids should be 64bit. also typedef pid_t uint32_t globalid; /* only for internal use, don't expose to userland */ diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 0dda320..b040285 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -8,6 +8,7 @@ #include <kernel/panic.h> #include <kernel/pipe.h> #include <kernel/proc.h> +#include <kernel/vfs/procfs.h> #include <shared/mem.h> #include <stdint.h> @@ -120,7 +121,6 @@ long _sys_mount(hid_t hid, const char __user *path, long len) { // remove trailing slash // mounting something under `/this` and `/this/` should be equalivent if (path_buf[len - 1] == '/') { - if (len == 0) goto fail; len--; } @@ -404,6 +404,21 @@ int _sys_wait2(int pid, int flags, struct sys_wait2 __user *out) { return 0; // dummy } +hid_t _sys_getprocfs(int flags) { + if (flags != 0) { + SYSCALL_RETURN(-ENOSYS); + } + proc_ns_create(proc_cur); + + Handle *h; + hid_t hid = proc_handle_init(proc_cur, HANDLE_FS_FRONT, &h); + if (hid < 0) { + SYSCALL_RETURN(-EMFILE); + } + h->backend = procfs_backend(proc_cur); + SYSCALL_RETURN(hid); +} + long _sys_execbuf(void __user *ubuf, size_t len) { if (len == 0) SYSCALL_RETURN(0); if (len > EXECBUF_MAX_LEN) @@ -458,6 +473,7 @@ long _syscall(long num, long a, long b, long c, long d, long e) { break; case _SYS_GETPID: _sys_getpid(); break; case _SYS_GETPPID: _sys_getppid(); break; case _SYS_WAIT2: _sys_wait2(a, b, (userptr_t)c); + break; case _SYS_GETPROCFS: _sys_getprocfs(a); break; case _SYS_EXECBUF: _sys_execbuf((userptr_t)a, b); break; case _SYS_DEBUG_KLOG: _sys_debug_klog((userptr_t)a, b); break; |