2018-11-05 16:40:48 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
2018-10-31 01:06:57 +01:00
|
|
|
#include <Kernel/Syscall.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
int kill(pid_t pid, int sig)
|
|
|
|
{
|
2018-11-06 13:23:22 +01:00
|
|
|
int rc = Syscall::invoke(Syscall::SC_kill, (dword)pid, (dword)sig);
|
2018-10-31 01:06:57 +01:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-11-11 00:20:53 +01:00
|
|
|
int killpg(int pgrp, int sig)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::SC_killpg, (dword)pgrp, (dword)sig);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-11-05 18:16:00 +01:00
|
|
|
sighandler_t signal(int signum, sighandler_t handler)
|
|
|
|
{
|
2018-11-06 13:23:22 +01:00
|
|
|
sighandler_t old_handler = (sighandler_t)Syscall::invoke(Syscall::SC_signal, (dword)signum, (dword)handler);
|
2018-11-05 18:16:00 +01:00
|
|
|
if (old_handler == SIG_ERR) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return SIG_ERR;
|
|
|
|
}
|
|
|
|
errno = 0;
|
|
|
|
return old_handler;
|
|
|
|
}
|
|
|
|
|
2018-11-06 10:46:40 +01:00
|
|
|
int sigaction(int signum, const struct sigaction* act, struct sigaction* old_act)
|
|
|
|
{
|
2018-11-06 13:23:22 +01:00
|
|
|
int rc = Syscall::invoke(Syscall::SC_sigaction, (dword)signum, (dword)act, (dword)old_act);
|
2018-11-06 10:46:40 +01:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-11-06 12:02:58 +01:00
|
|
|
int sigemptyset(sigset_t* set)
|
|
|
|
{
|
|
|
|
*set = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sigfillset(sigset_t* set)
|
|
|
|
{
|
|
|
|
*set = 0xffffffff;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sigaddset(sigset_t* set, int sig)
|
|
|
|
{
|
|
|
|
if (sig < 1 || sig > 32) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2018-11-06 15:45:16 +01:00
|
|
|
*set |= 1 << (sig);
|
2018-11-06 12:02:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sigdelset(sigset_t* set, int sig)
|
|
|
|
{
|
|
|
|
if (sig < 1 || sig > 32) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2018-11-06 15:45:16 +01:00
|
|
|
*set &= ~(1 << (sig));
|
2018-11-06 12:02:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sigismember(const sigset_t* set, int sig)
|
|
|
|
{
|
|
|
|
if (sig < 1 || sig > 32) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2018-11-06 15:45:16 +01:00
|
|
|
if (*set & (1 << (sig)))
|
2018-11-06 12:02:58 +01:00
|
|
|
return 1;
|
|
|
|
return 0;
|
2018-10-31 01:06:57 +01:00
|
|
|
}
|
|
|
|
|
2018-11-10 23:29:07 +01:00
|
|
|
int sigprocmask(int how, const sigset_t* set, sigset_t* old_set)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::SC_sigprocmask, (dword)how, (dword)set, (dword)old_set);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sigpending(sigset_t* set)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::SC_sigpending, (dword)set);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-11-06 15:45:16 +01:00
|
|
|
const char* sys_siglist[NSIG] = {
|
|
|
|
#undef __SIGNAL
|
|
|
|
#define __SIGNAL(a, b) b,
|
|
|
|
__ENUMERATE_ALL_SIGNALS
|
|
|
|
#undef __SIGNAL
|
|
|
|
};
|
|
|
|
|
2018-11-06 12:02:58 +01:00
|
|
|
}
|