mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-28 21:28:21 +00:00
signal: add signal_returnmask and other fixes
This commit is contained in:
@@ -61,8 +61,8 @@ typedef struct thread_t {
|
||||
sigset_t pending;
|
||||
sigset_t urgent; // always handled before returning to userspace
|
||||
sigset_t waiting; // for signal_wait
|
||||
sigset_t oldmask; // for signal_suspend
|
||||
bool suspending;
|
||||
sigset_t returnmask; // for signal_returnmask
|
||||
bool hasreturnmask;
|
||||
bool stopped;
|
||||
} signals;
|
||||
} thread_t;
|
||||
|
||||
@@ -155,6 +155,7 @@ struct thread_t;
|
||||
void signal_action(struct proc_t *proc, int signal, sigaction_t *new, sigaction_t *old);
|
||||
void signal_altstack(struct thread_t *thread, stack_t *new, stack_t *old);
|
||||
void signal_changemask(struct thread_t *thread, int how, sigset_t *new, sigset_t *old);
|
||||
void signal_returnmask(struct thread_t *thread, sigset_t *sigset);
|
||||
void signal_signalproc(struct proc_t *proc, int signal);
|
||||
void signal_signalthread(struct thread_t *thread, int signal, bool urgent);
|
||||
void signal_pending(struct thread_t *, sigset_t *sigset);
|
||||
|
||||
@@ -529,7 +529,7 @@ static void yield(context_t *context, void *) {
|
||||
|
||||
thread_t *next = runqueuenext(sleeping ? 0x0fffffff : thread->priority);
|
||||
bool gotsignal = false;
|
||||
for (int i = 0; i < NSIG && thread->proc; ++i) {
|
||||
for (int i = 1; i < NSIG && thread->proc; ++i) {
|
||||
void *action = thread->proc->signals.actions[i].address;
|
||||
if (SIGNAL_GET(&thread->signals.urgent, i)) {
|
||||
gotsignal = true;
|
||||
|
||||
@@ -139,13 +139,17 @@ void signal_pending(struct thread_t *thread, sigset_t *sigset) {
|
||||
PROCESS_LEAVE(proc);
|
||||
}
|
||||
|
||||
void signal_returnmask(struct thread_t *thread, sigset_t *sigset) {
|
||||
memcpy(&thread->signals.returnmask, sigset, sizeof(sigset_t));
|
||||
thread->signals.hasreturnmask = true;
|
||||
}
|
||||
|
||||
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;
|
||||
signal_returnmask(thread, sigset);
|
||||
|
||||
THREAD_LEAVE(thread);
|
||||
|
||||
@@ -548,11 +552,11 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
|
||||
memset(&sigframe.oldstack, 0, sizeof(stack_t));
|
||||
}
|
||||
|
||||
if (thread->signals.suspending) {
|
||||
if (thread->signals.hasreturnmask) {
|
||||
// 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;
|
||||
memcpy(&sigframe.oldmask, &thread->signals.returnmask, sizeof(sigset_t));
|
||||
thread->signals.hasreturnmask = false;
|
||||
} else {
|
||||
// else, just push the current mask
|
||||
memcpy(&sigframe.oldmask, &thread->signals.mask, sizeof(sigset_t));
|
||||
|
||||
@@ -286,7 +286,7 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
|
||||
memset(&_cpu()->thread->signals.stack, 0, sizeof(stack_t));
|
||||
|
||||
// execve keeps information about ignored signals
|
||||
for (int i = 0; i < NSIG; ++i) {
|
||||
for (int i = 1; i < NSIG; ++i) {
|
||||
bool ign = proc->signals.actions[i].address == SIG_IGN;
|
||||
memset(&proc->signals.actions[i], 0, sizeof(sigaction_t));
|
||||
if (ign)
|
||||
|
||||
@@ -125,12 +125,10 @@ syscallret_t syscall_ppoll(context_t *context, pollfd_t *fds, size_t nfds, times
|
||||
return ret;
|
||||
|
||||
signal_changemask(_cpu()->thread, SIG_SETMASK, &sigset, &savedset);
|
||||
signal_returnmask(_cpu()->thread, &savedset);
|
||||
}
|
||||
|
||||
syscallret_t ret = syscall_poll(context, fds, nfds, utimeout ? (timeout.s * 1000 + timeout.ns / 1000000) : -1);
|
||||
|
||||
if (usigset)
|
||||
signal_changemask(_cpu()->thread, SIG_SETMASK, &savedset, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user