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:
@@ -22,7 +22,7 @@ __BEGIN_DECLS
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef int sig_atomic_t;
|
||||
typedef void* sigset_t;
|
||||
typedef unsigned long long sigset_t;
|
||||
|
||||
union sigval
|
||||
{
|
||||
|
||||
@@ -40,7 +40,6 @@ __BEGIN_DECLS
|
||||
O(SYS_DUP, dup) \
|
||||
O(SYS_DUP2, dup2) \
|
||||
O(SYS_KILL, kill) \
|
||||
O(SYS_SIGNAL, signal) \
|
||||
O(SYS_TCSETPGRP, tcsetpgrp) \
|
||||
O(SYS_GET_PID, getpid) \
|
||||
O(SYS_GET_PGID, getpgid) \
|
||||
@@ -84,6 +83,9 @@ __BEGIN_DECLS
|
||||
O(SYS_REALPATH, realpath) \
|
||||
O(SYS_TTYNAME, ttyname) \
|
||||
O(SYS_ACCESS, access) \
|
||||
O(SYS_SIGACTION, sigaction) \
|
||||
O(SYS_SIGPENDING, sigpending) \
|
||||
O(SYS_SIGPROCMASK, sigprocmask) \
|
||||
|
||||
enum Syscall
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user