mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +00:00
It only works for sending a signal to a process that's in userspace code. We implement reception by synthesizing a PUSHA+PUSHF in the receiving process (operating on values in the TSS.) The TSS CS:EIP is then rerouted to the signal handler and a tiny return trampoline is constructed in a dedicated region in the receiving process. Also hacked up /bin/kill to be able to send arbitrary signals (kill -N PID)
32 lines
768 B
C++
32 lines
768 B
C++
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <signal.h>
|
|
#include <Kernel/Syscall.h>
|
|
|
|
extern "C" {
|
|
|
|
int kill(pid_t pid, int sig)
|
|
{
|
|
int rc = Syscall::invoke(Syscall::PosixKill, (dword)pid, (dword)sig);
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
}
|
|
|
|
sighandler_t signal(int signum, sighandler_t handler)
|
|
{
|
|
sighandler_t old_handler = (sighandler_t)Syscall::invoke(Syscall::PosixSignal, (dword)signum, (dword)handler);
|
|
if (old_handler == SIG_ERR) {
|
|
errno = EINVAL;
|
|
return SIG_ERR;
|
|
}
|
|
errno = 0;
|
|
return old_handler;
|
|
}
|
|
|
|
int sigaction(int signum, const struct sigaction* act, struct sigaction* old_act)
|
|
{
|
|
int rc = Syscall::invoke(Syscall::Sigaction, (dword)signum, (dword)act, (dword)old_act);
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
}
|
|
|
|
}
|
|
|