--- ski-1.3.2/src/linux/syscall-linux.c.~1~ 2014-01-27 12:51:58.660109271 +0100 +++ ski-1.3.2/src/linux/syscall-linux.c 2014-01-28 13:20:11.587923139 +0100 @@ -93,6 +93,7 @@ #include "interruption.h" #include "netdev.h" #include "os_support.h" +#include "itc.h" #if defined NEW_MP # error "not supported" @@ -4360,6 +4361,50 @@ asynckb (int sig) #endif +/* + * Sleep until SIGIO or SIGALRM is received; this relies on + * keyboard/ethernet input being detected via SIGIO, and the + * ITC now being emulated via setitimer() and SIGALRM. + * + * A SIGALRM might be delivered just before we enter the + * blocking (but interruptible) system call. To ensure that + * we notice that SIGALRM, the protocol is: + * + * 1. We atomically retrieve the current signal mask and block SIGALRM. + * + * 2. We check if an ITC SIGALRM has been received, if so we + * restore the signal mask and return. + * + * 3. We call pselect to atomically unblock SIGALRM and block until + * a signal is delivered. + * + * 4. We unblock SIGALRM since pselect re-blocks it. + * + * Any SIGALRM before step 1 is detected by step 2, and any SIGALRM + * after step 1 is detected via the pselect in step 3. + */ +static void +doSSC_HALT_LIGHT (void) +{ + sigset_t set, oldset; + + sigemptyset(&set); + sigaddset(&set, SIGALRM); + + if (sigprocmask(SIG_BLOCK, &set, &oldset) == -1) { + perror("sigprocmask"); + exit(1); + } + + if (itc_itimer_fired) { + sigprocmask(SIG_SETMASK, &oldset, NULL); + return; + } + + pselect (0, NULL, NULL, NULL, NULL, &oldset); + sigprocmask(SIG_SETMASK, &oldset, NULL); +} + void doSSC (HWORD num, REG arg0, REG arg1, REG arg2, REG arg3, REG *ret) { @@ -4389,6 +4434,10 @@ doSSC (HWORD num, REG arg0, REG arg1, RE progStop ("SSC breakpoint\n"); break; + case SSC_HALT_LIGHT: + doSSC_HALT_LIGHT (); + break; + case SSC_CTL_TRACE: #ifdef TRACE_DAVIDM { --- ski-1.3.2/src/ssc.h.~1~ 2008-02-05 05:11:38.000000000 +0100 +++ ski-1.3.2/src/ssc.h 2014-01-27 12:52:12.250151160 +0100 @@ -28,6 +28,7 @@ #define SSC_STOP 0 +#define SSC_HALT_LIGHT 19 #define SSC_CONSOLE_INIT 20 #define SSC_GETCHAR 21 #define SSC_PUTCHAR 31