Skip to content

Commit

Permalink
syscalls: allow for blocking syscalls
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 7, 2024
1 parent a910e3e commit e5a0685
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/include/kernel/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
10 changes: 9 additions & 1 deletion src/syscalls/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -42,6 +46,8 @@ void syscallDispatchGetUID(SyscallRequest *req) {
} else {
req->ret = p->user;
}

req->unblock = true;
}

void syscallDispatchGetGID(SyscallRequest *req) {
Expand All @@ -52,14 +58,16 @@ void syscallDispatchGetGID(SyscallRequest *req) {
} else {
req->ret = p->group;
}

req->unblock = true;
}

void syscallDispatchMSleep(SyscallRequest *req) {
req->ret = msleep(req->thread, req->params[0]);
}

void (*syscallDispatchTable[])(SyscallRequest *) = {
// group 1: scheduler functions
/* group 1: scheduler functions */
syscallDispatchExit, // 0 - exit()
syscallDispatchFork, // 1 - fork()
syscallDispatchYield, // 2 - yield()
Expand Down
2 changes: 1 addition & 1 deletion src/syscalls/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e5a0685

Please sign in to comment.