summaryrefslogtreecommitdiff
path: root/src/kernel/syscalls.c
diff options
context:
space:
mode:
authordzwdz2023-12-25 19:08:04 +0100
committerdzwdz2023-12-25 19:08:04 +0100
commitb9f5f92bff69059471a76e73539780eedb356455 (patch)
tree55302764cbc2a6ab159cf2621dc34aab04ca4085 /src/kernel/syscalls.c
parent4e1a6f1b3c543b9fbeb882a9e97551f7c58ca65a (diff)
kernel: _sys_getnull() (basically /dev/null)
Diffstat (limited to 'src/kernel/syscalls.c')
-rw-r--r--src/kernel/syscalls.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index e449953..5f53ccb 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -166,7 +166,13 @@ static long simple_vfsop(
|| vfsop == VFSOP_WRITE
|| vfsop == VFSOP_GETSIZE);
Handle *h = proc_handle_get(proc_cur, hid);
- if (!h) SYSCALL_RETURN(-EBADF);
+ if (!h) {
+ SYSCALL_RETURN(-EBADF);
+ }
+ if (h->type != HANDLE_FILE && h->type != HANDLE_PIPE) {
+ SYSCALL_RETURN(-ENOSYS);
+ }
+
// TODO those checks really need some comprehensive tests
if (vfsop == VFSOP_READ && !h->readable)
SYSCALL_RETURN(-EACCES);
@@ -196,7 +202,9 @@ static long simple_vfsop(
/* already checked if this is the correct pipe end */
pipe_joinqueue(h, proc_cur, buf, len);
} else SYSCALL_RETURN(-ENOSYS);
- } else SYSCALL_RETURN(-ENOSYS);
+ } else {
+ panic_invalid_state();
+ }
return 0;
}
@@ -436,6 +444,15 @@ uint64_t _sys_time(int flags) {
SYSCALL_RETURN(now - proc_cur->basetime);
}
+hid_t _sys_getnull(int flags) {
+ if (flags != 0) {
+ SYSCALL_RETURN(-ENOSYS);
+ }
+
+ hid_t hid = proc_handle_init(proc_cur, HANDLE_NULL, NULL);
+ SYSCALL_RETURN((0 <= hid) ? hid : -EMFILE);
+}
+
long _sys_execbuf(void __user *ubuf, size_t len) {
if (len == 0) SYSCALL_RETURN(0);
if (len > EXECBUF_MAX_LEN)
@@ -491,6 +508,7 @@ long _syscall(long num, long a, long b, long c, long d, long e) {
break; case _SYS_WAIT2: _sys_wait2(a, b, (userptr_t)c);
break; case _SYS_GETPROCFS: _sys_getprocfs(a);
break; case _SYS_TIME: _sys_time(a);
+ break; case _SYS_GETNULL: _sys_getnull(a);
break; case _SYS_EXECBUF: _sys_execbuf((userptr_t)a, b);
break; case _SYS_DEBUG_KLOG: _sys_debug_klog((userptr_t)a, b);
break;