mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 14:38:21 +00:00
sigsuspend: proper behaviour
This commit is contained in:
@@ -59,8 +59,10 @@ typedef struct thread_t {
|
|||||||
stack_t stack;
|
stack_t stack;
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
sigset_t pending;
|
sigset_t pending;
|
||||||
sigset_t urgent;
|
sigset_t urgent; // always handled before returning to userspace
|
||||||
sigset_t waiting;
|
sigset_t waiting; // for signal_wait
|
||||||
|
sigset_t oldmask; // for signal_suspend
|
||||||
|
bool suspending;
|
||||||
bool stopped;
|
bool stopped;
|
||||||
} signals;
|
} signals;
|
||||||
} thread_t;
|
} thread_t;
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ void signal_changemask(struct thread_t *thread, int how, sigset_t *new, sigset_t
|
|||||||
void signal_signalproc(struct proc_t *proc, int signal);
|
void signal_signalproc(struct proc_t *proc, int signal);
|
||||||
void signal_signalthread(struct thread_t *thread, int signal, bool urgent);
|
void signal_signalthread(struct thread_t *thread, int signal, bool urgent);
|
||||||
void signal_pending(struct thread_t *, sigset_t *sigset);
|
void signal_pending(struct thread_t *, sigset_t *sigset);
|
||||||
|
void signal_suspend(sigset_t *sigset);
|
||||||
int signal_wait(sigset_t *sigset, timespec_t *timeout, siginfo_t *siginfo, int *signum);
|
int signal_wait(sigset_t *sigset, timespec_t *timeout, siginfo_t *siginfo, int *signum);
|
||||||
bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uint64_t syscallret, uint64_t syscallerrno);
|
bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uint64_t syscallret, uint64_t syscallerrno);
|
||||||
extern int signal_defaultactions[NSIG];
|
extern int signal_defaultactions[NSIG];
|
||||||
|
|||||||
+24
-1
@@ -139,6 +139,20 @@ void signal_pending(struct thread_t *thread, sigset_t *sigset) {
|
|||||||
PROCESS_LEAVE(proc);
|
PROCESS_LEAVE(proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void signal_suspend(sigset_t *sigset) {
|
||||||
|
thread_t *thread = _cpu()->thread;
|
||||||
|
THREAD_ENTER(thread);
|
||||||
|
|
||||||
|
memcpy(&thread->signals.oldmask, &thread->signals.mask, sizeof(sigset_t));
|
||||||
|
memcpy(&thread->signals.mask, sigset, sizeof(sigset_t));
|
||||||
|
thread->signals.suspending = true;
|
||||||
|
|
||||||
|
THREAD_LEAVE(thread);
|
||||||
|
|
||||||
|
sched_preparesleep(true);
|
||||||
|
sched_yield();
|
||||||
|
}
|
||||||
|
|
||||||
int signal_wait(sigset_t *sigset, timespec_t *timeout, siginfo_t *siginfo, int *signum) {
|
int signal_wait(sigset_t *sigset, timespec_t *timeout, siginfo_t *siginfo, int *signum) {
|
||||||
thread_t *thread = _cpu()->thread;
|
thread_t *thread = _cpu()->thread;
|
||||||
PROCESS_ENTER(thread->proc);
|
PROCESS_ENTER(thread->proc);
|
||||||
@@ -531,7 +545,16 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
|
|||||||
memcpy(&sigframe.oldstack, &thread->signals.stack, sizeof(stack_t));
|
memcpy(&sigframe.oldstack, &thread->signals.stack, sizeof(stack_t));
|
||||||
memset(&thread->signals.stack, 0, sizeof(stack_t));
|
memset(&thread->signals.stack, 0, sizeof(stack_t));
|
||||||
}
|
}
|
||||||
memcpy(&sigframe.oldmask, &thread->signals.mask, sizeof(sigset_t));
|
|
||||||
|
if (thread->signals.suspending) {
|
||||||
|
// if we were waiting in signal_suspend, push the old mask into the return frame
|
||||||
|
// of the first signal and set it to not act this way the next check
|
||||||
|
memcpy(&sigframe.oldmask, &thread->signals.oldmask, sizeof(sigset_t));
|
||||||
|
thread->signals.suspending = false;
|
||||||
|
} else {
|
||||||
|
// else, just push the current mask
|
||||||
|
memcpy(&sigframe.oldmask, &thread->signals.mask, sizeof(sigset_t));
|
||||||
|
}
|
||||||
memcpy(&sigframe.context, context, sizeof(context_t));
|
memcpy(&sigframe.context, context, sizeof(context_t));
|
||||||
memcpy(&sigframe.extracontext, &thread->extracontext, sizeof(extracontext_t));
|
memcpy(&sigframe.extracontext, &thread->extracontext, sizeof(extracontext_t));
|
||||||
// TODO siginfo
|
// TODO siginfo
|
||||||
|
|||||||
@@ -8,18 +8,12 @@ syscallret_t syscall_sigsuspend(context_t *, sigset_t *umask) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
sigset_t old;
|
|
||||||
|
|
||||||
ret.errno = usercopy_fromuser(&mask, umask, sizeof(sigset_t));
|
ret.errno = usercopy_fromuser(&mask, umask, sizeof(sigset_t));
|
||||||
if (ret.errno)
|
if (ret.errno)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
signal_changemask(_cpu()->thread, SIG_SETMASK, &mask, &old);
|
signal_suspend(&mask);
|
||||||
|
|
||||||
sched_preparesleep(true);
|
|
||||||
__assert(sched_yield() == SCHED_WAKEUP_REASON_INTERRUPTED);
|
|
||||||
|
|
||||||
signal_changemask(_cpu()->thread, SIG_SETMASK, &old, NULL);
|
|
||||||
|
|
||||||
ret.errno = EINTR;
|
ret.errno = EINTR;
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user