1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +00:00

Add some basic signal support.

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)
This commit is contained in:
Andreas Kling 2018-11-06 10:46:40 +01:00
parent 52d502e11f
commit 153ea704af
13 changed files with 240 additions and 30 deletions

View file

@ -22,5 +22,11 @@ sighandler_t signal(int signum, sighandler_t handler)
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);
}
}

View file

@ -11,8 +11,10 @@ typedef uint32_t sigset_t;
typedef void siginfo_t;
struct sigaction {
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t*, void*);
union {
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t*, void*);
};
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
@ -20,11 +22,16 @@ struct sigaction {
int kill(pid_t, int sig);
sighandler_t signal(int sig, sighandler_t);
int sigaction(int signum, const struct sigaction* act, struct sigaction* old_act);
#define SIG_DFL ((__sighandler_t)0)
#define SIG_ERR ((__sighandler_t)-1)
#define SIG_IGN ((__sighandler_t)1)
#define SA_NOCLDSTOP 1
#define SA_NOCLDWAIT 2
#define SA_SIGINFO 4
#define SIG_BLOCK 0
#define SIG_UNBLOCK 1
#define SIG_SETMASK 2

View file

@ -5,15 +5,15 @@
__BEGIN_DECLS
void* malloc(size_t);
void* malloc(size_t) __MALLOC;
void free(void*);
void* calloc(size_t nmemb, size_t);
void* realloc(void *ptr, size_t);
char* getenv(const char* name);
int atoi(const char*);
void exit(int status);
void abort();
void exit(int status) __NORETURN;
void abort() __NORETURN;
__END_DECLS

View file

@ -4,6 +4,7 @@
#define ALWAYS_INLINE inline __attribute__ ((always_inline))
#define __NORETURN __attribute__ ((noreturn))
#define __MALLOC __attribute__ ((malloc))
#ifdef __cplusplus
#define __BEGIN_DECLS extern "C" {