From e06772a964e269d2d9abcb43a1edd868a62d4610 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Tue, 2 Jul 2024 21:58:34 +0300 Subject: enable irqs when we sleep or swap threads + Also swap checks if thread is running --- src/uapi/conf.c | 2 ++ src/uapi/proc.c | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'src/uapi') diff --git a/src/uapi/conf.c b/src/uapi/conf.c index 7925616..242239c 100644 --- a/src/uapi/conf.c +++ b/src/uapi/conf.c @@ -126,5 +126,7 @@ SYSCALL_DEFINE0(sleep)(struct tcb *t) if (!(has_cap(t->caps, CAP_POWER))) return_args1(t, ERR_PERM); + /* presumably we want to wake up on an interrupt */ + enable_irqs(); return_args1(t, sleep()); } diff --git a/src/uapi/proc.c b/src/uapi/proc.c index e87a2ec..bb4b463 100644 --- a/src/uapi/proc.c +++ b/src/uapi/proc.c @@ -181,6 +181,9 @@ SYSCALL_DEFINE1(swap)(struct tcb *t, sys_arg_t tid){ if (!s) return_args1(t, ERR_INVAL); + if (running(s)) + return_args1(t, ERR_EXT); + /* switch over to new thread */ use_tcb(s); @@ -195,6 +198,9 @@ SYSCALL_DEFINE1(swap)(struct tcb *t, sys_arg_t tid){ if (s->notify_state == NOTIFY_QUEUED) notify(s, 0); + /* if an irq handler is directly swapping to some other thread, + * interpret it as the thread being finished with its critical section */ + enable_irqs(); /* get register state for new thread */ return_args(s, get_args(s)); } -- cgit v1.3