Signals to processes in userspace now work again.

Ugh, how am I going to dispatch signals to processes in the kernel?
This commit is contained in:
Andreas Kling 2018-11-07 19:03:44 +01:00
parent dd887e158b
commit c8b308910e
Notes: sideshowbarker 2024-07-19 18:32:22 +09:00
2 changed files with 25 additions and 3 deletions

View file

@ -789,7 +789,7 @@ void Process::dispatch_signal(byte signal)
if ((ret_cs & 3) == 0) {
// FIXME: Handle send_signal to process currently in kernel code.
kprintf("Boo! dispatch_signal with return to %w:%x\n", ret_cs, ret_eip);
kprintf("Boo! dispatch_signal in %s(%u) with return to %w:%x\n", name().characters(), pid(), ret_cs, ret_eip);
ASSERT_NOT_REACHED();
}
@ -827,6 +827,8 @@ void Process::dispatch_signal(byte signal)
push_value_on_stack(m_return_from_signal_trampoline.get());
m_pending_signals &= ~(1 << signal);
dbgprintf("signal: Okay, %s(%u) has been primed\n", name().characters(), pid());
}

View file

@ -33,10 +33,17 @@ static int sh_pwd(int, const char**)
return 0;
}
static volatile bool g_got_signal = false;
void did_receive_signal(int signum)
{
printf("\nMy word, I've received a signal with number %d\n", signum);
//exit(0);
g_got_signal = true;
}
void handle_sigint(int signum)
{
printf("Interrupt received by sh\n");
}
static int sh_busy(int, const char**)
@ -48,11 +55,14 @@ static int sh_busy(int, const char**)
sa.sa_restorer = nullptr;
int rc = sigaction(SIGUSR1, &sa, nullptr);
assert(rc == 0);
printf("listening for SIGUSR1 while looping in userspace...\n");
printf("listening for signal SIGUSR1 while looping in userspace...\n");
for (;;) {
for (volatile int i = 0; i < 100000; ++i)
;
if (g_got_signal)
break;
}
g_got_signal = false;
return 0;
}
@ -280,6 +290,16 @@ int main(int, char**)
g->sid = setsid();
tcsetpgrp(0, getpgrp());
{
struct sigaction sa;
sa.sa_handler = handle_sigint;
sa.sa_flags = 0;
sa.sa_mask = 0;
sa.sa_restorer = nullptr;
int rc = sigaction(SIGINT, &sa, nullptr);
assert(rc == 0);
}
int rc = gethostname(g->hostname, sizeof(g->hostname));
if (rc < 0)
perror("gethostname");