summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/handle.h1
-rw-r--r--src/kernel/syscalls.c22
2 files changed, 21 insertions, 2 deletions
diff --git a/src/kernel/handle.h b/src/kernel/handle.h
index 21b4364..d502d5d 100644
--- a/src/kernel/handle.h
+++ b/src/kernel/handle.h
@@ -10,6 +10,7 @@ enum handle_type {
HANDLE_PIPE,
HANDLE_FS_FRONT,
HANDLE_FS_REQ,
+ HANDLE_NULL,
};
struct Handle {
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;