signals: more general changes

This commit is contained in:
Matheus
2024-05-17 18:48:57 -03:00
parent 7b0cc4c51b
commit 1b63e9b436
13 changed files with 135 additions and 54 deletions
+3
View File
@@ -127,6 +127,9 @@ syscallret_t syscall_execve(context_t *context, char *upath, char *uargv[], char
fd_close(fd);
}
memset(&_cpu()->thread->signals.stack, 0, sizeof(stack_t));
memset(&proc->signals.actions[0], 0, sizeof(sigaction_t) * NSIG);
error:
free(path);
if (argv)
+6
View File
@@ -54,6 +54,12 @@ syscallret_t syscall_fork(context_t *ctx) {
CTX_ERRNO(&nthread->context) = 0;
jobctl_addproc(proc, nproc);
memcpy(&nthread->signals.mask, &_cpu()->thread->signals.mask, sizeof(sigset_t));
memcpy(&nthread->signals.pending, &_cpu()->thread->signals.pending, sizeof(sigset_t));
memcpy(&nthread->signals.stack, &_cpu()->thread->signals.stack, sizeof(stack_t));
memcpy(&nproc->signals.pending, &proc->signals.pending, sizeof(sigset_t));
memcpy(&nproc->signals.actions, &proc->signals.actions[0], sizeof(sigaction_t) * NSIG);
ret.ret = nproc->pid;
sched_queue(nthread);
+2 -1
View File
@@ -1,6 +1,7 @@
#include <kernel/syscalls.h>
#include <arch/cpu.h>
#include <logging.h>
#include <kernel/jobctl.h>
syscallret_t syscall_kill(context_t *context, int pid, int signal) {
syscallret_t ret = {
@@ -23,7 +24,7 @@ syscallret_t syscall_kill(context_t *context, int pid, int signal) {
return ret;
}
proc_t *target = sched_getprocfrompid(pid);
proc_t *target = sched_getprocfrompid(effectivepid);
if (target == NULL && pid != 0) {
ret.errno = ESRCH;
return ret;
+2 -1
View File
@@ -37,7 +37,7 @@ syscallret_t syscall_poll(context_t *, pollfd_t *fds, size_t nfds, int timeoutms
goto cleanup;
}
polldesc_t desc;
polldesc_t desc = {0};
// when nfds is 0, poll is used as a sleep.
// therefore, initialize the desc size to one descriptor in that case.
ret.errno = poll_initdesc(&desc, nfds == 0 ? 1 : nfds);
@@ -72,6 +72,7 @@ syscallret_t syscall_poll(context_t *, pollfd_t *fds, size_t nfds, int timeoutms
if (eventcount == 0 && timeoutms != 0) {
ret.errno = poll_dowait(&desc, (timeoutms == -1 ? 0 : timeoutms) * 1000);
if (ret.errno == 0 && desc.event) {
int fd = ((uintptr_t)desc.event - (uintptr_t)desc.data) / sizeof(polldata_t);
fdsbuff[fd].revents = desc.data[fd].revents;
+6
View File
@@ -25,6 +25,12 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
proc_t *iterator = proc->child;
proc_t *desired = NULL;
if (iterator == NULL) {
ret.errno = ECHILD;
MUTEX_RELEASE(&proc->mutex);
return ret;
}
for (;;) {
if (iterator == NULL) {
if (pid > 0 && desired == NULL) {