signal: add signal_returnmask and other fixes

This commit is contained in:
Matheus
2024-09-12 22:08:57 -03:00
parent cf3e58ffe1
commit 31c7cf881c
6 changed files with 15 additions and 12 deletions
+2 -2
View File
@@ -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;
+1
View File
@@ -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);
+1 -1
View File
@@ -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;
+9 -5
View File
@@ -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));
+1 -1
View File
@@ -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)
+1 -3
View File
@@ -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;
}