mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:47:46 +00:00
Implement sending signals to blocked-in-kernel processes.
This is dirty but pretty cool! If we have a pending, unmasked signal for a process that's blocked inside the kernel, we set up alternate stacks for that process and unblock it to execute the signal handler. A slightly different return trampoline is used here: since we need to get back into the kernel, a dedicated syscall is used (sys$sigreturn.) This restores the TSS contents of the process to the state it was in while we were originally blocking in the kernel. NOTE: There's currently only one "kernel resume TSS" so signal nesting definitely won't work.
This commit is contained in:
parent
c8b308910e
commit
03a8357e84
10 changed files with 190 additions and 27 deletions
|
@ -1,10 +1,47 @@
|
|||
#include <LibC/unistd.h>
|
||||
#include <LibC/stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <AK/String.h>
|
||||
|
||||
int main(int c, char** v)
|
||||
static unsigned parseUInt(const String& str, bool& ok)
|
||||
{
|
||||
unsigned secs = 10;
|
||||
sleep(secs);
|
||||
unsigned value = 0;
|
||||
for (size_t i = 0; i < str.length(); ++i) {
|
||||
if (str[i] < '0' || str[i] > '9') {
|
||||
ok = false;
|
||||
return 0;
|
||||
}
|
||||
value = value * 10;
|
||||
value += str[i] - '0';
|
||||
}
|
||||
ok = true;
|
||||
return value;
|
||||
}
|
||||
|
||||
void handle_sigint(int)
|
||||
{
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf("usage: sleep <seconds>\n");
|
||||
return 1;
|
||||
}
|
||||
bool ok;
|
||||
unsigned secs = parseUInt(argv[1], ok);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Not a valid number of seconds: \"%s\"\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(struct sigaction));
|
||||
sa.sa_handler = handle_sigint;
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
unsigned remaining = sleep(secs);
|
||||
if (remaining) {
|
||||
printf("Sleep interrupted with %u seconds remaining.\n", remaining);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue