浏览代码

Signals to processes in userspace now work again.

Ugh, how am I going to dispatch signals to processes in the kernel?
Andreas Kling 6 年之前
父节点
当前提交
c8b308910e
共有 2 个文件被更改,包括 25 次插入3 次删除
  1. 3 1
      Kernel/Process.cpp
  2. 22 2
      Userland/sh.cpp

+ 3 - 1
Kernel/Process.cpp

@@ -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());
 }
 

+ 22 - 2
Userland/sh.cpp

@@ -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");