Kernel/LibC: Cleanup, fix and implement a lot of signal code

This patch implements sigsets and some of their usages
This commit is contained in:
2024-08-01 17:01:18 +03:00
parent 838d31fa41
commit 6de350ce9d
7 changed files with 180 additions and 45 deletions

View File

@@ -1,20 +1,67 @@
#include <BAN/Assert.h>
#include <signal.h>
#include <sys/syscall.h>
#include <unistd.h>
static_assert(sizeof(sigset_t) * 8 >= _SIGMAX);
int kill(pid_t pid, int sig)
{
return syscall(SYS_KILL, pid, sig);
}
int raise(int sig)
{
// FIXME: won't work after multithreaded
return kill(getpid(), sig);
}
int kill(pid_t pid, int sig)
int sigaction(int sig, const struct sigaction* __restrict act, struct sigaction* __restrict oact)
{
return syscall(SYS_KILL, pid, sig);
return syscall(SYS_SIGACTION, sig, act, oact);
}
int sigaddset(sigset_t* set, int signo)
{
*set |= 1ull << signo;
return 0;
}
int sigemptyset(sigset_t* set)
{
*set = 0;
return 0;
}
int sigfillset(sigset_t* set)
{
*set = (1ull << _SIGMAX) - 1;
return 0;
}
int sigismember(const sigset_t* set, int signo)
{
return (*set >> signo) & 1;
}
void (*signal(int sig, void (*func)(int)))(int)
{
long ret = syscall(SYS_SIGNAL, sig, func);
return (void (*)(int))ret;
struct sigaction act;
act.sa_handler = func;
act.sa_flags = 0;
int ret = sigaction(sig, &act, nullptr);
if (ret == -1)
return SIG_ERR;
return func;
}
int sigpending(sigset_t* set)
{
return syscall(SYS_SIGPENDING, set);
}
int sigprocmask(int how, const sigset_t* __restrict set, sigset_t* __restrict oset)
{
return syscall(SYS_SIGPROCMASK, how, set, oset);
}