From e5a06859c52530cb2fedd41f3e26b29c1b150cb2 Mon Sep 17 00:00:00 2001 From: jewelcodes Date: Sat, 7 Sep 2024 10:52:26 -0400 Subject: [PATCH] syscalls: allow for blocking syscalls --- src/include/kernel/syscalls.h | 2 +- src/syscalls/dispatch.c | 10 +++++++++- src/syscalls/queue.c | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/include/kernel/syscalls.h b/src/include/kernel/syscalls.h index 6cf90a4..2f5d7d6 100644 --- a/src/include/kernel/syscalls.h +++ b/src/include/kernel/syscalls.h @@ -14,7 +14,7 @@ #define MAX_SYSCALL 12 // for now typedef struct SyscallRequest { - bool busy, queued; + bool busy, queued, unblock; uint64_t function; uint64_t params[4]; diff --git a/src/syscalls/dispatch.c b/src/syscalls/dispatch.c index 32f2811..d680fb2 100644 --- a/src/syscalls/dispatch.c +++ b/src/syscalls/dispatch.c @@ -20,18 +20,22 @@ void syscallDispatchExit(SyscallRequest *req) { void syscallDispatchFork(SyscallRequest *req) { req->ret = fork(req->thread); + req->unblock = true; } void syscallDispatchYield(SyscallRequest *req) { req->ret = yield(req->thread); + req->unblock = true; } void syscallDispatchGetPID(SyscallRequest *req) { req->ret = req->thread->pid; + req->unblock = true; } void syscallDispatchGetTID(SyscallRequest *req) { req->ret = req->thread->tid; + req->unblock = true; } void syscallDispatchGetUID(SyscallRequest *req) { @@ -42,6 +46,8 @@ void syscallDispatchGetUID(SyscallRequest *req) { } else { req->ret = p->user; } + + req->unblock = true; } void syscallDispatchGetGID(SyscallRequest *req) { @@ -52,6 +58,8 @@ void syscallDispatchGetGID(SyscallRequest *req) { } else { req->ret = p->group; } + + req->unblock = true; } void syscallDispatchMSleep(SyscallRequest *req) { @@ -59,7 +67,7 @@ void syscallDispatchMSleep(SyscallRequest *req) { } void (*syscallDispatchTable[])(SyscallRequest *) = { - // group 1: scheduler functions + /* group 1: scheduler functions */ syscallDispatchExit, // 0 - exit() syscallDispatchFork, // 1 - fork() syscallDispatchYield, // 2 - yield() diff --git a/src/syscalls/queue.c b/src/syscalls/queue.c index f6b75e6..e626980 100644 --- a/src/syscalls/queue.c +++ b/src/syscalls/queue.c @@ -96,7 +96,7 @@ int syscallProcess() { platformSetContextStatus(syscall->thread->context, syscall->ret); } - if(syscall->thread->status == THREAD_BLOCKED) { + if((syscall->thread->status == THREAD_BLOCKED) && syscall->unblock) { // this way we prevent accidentally running threads that exit() syscall->thread->status = THREAD_QUEUED; syscall->thread->time = schedTimeslice(syscall->thread, syscall->thread->priority);