Changeset 13970


Ignore:
Timestamp:
Jul 17, 2010, 10:17:32 AM (9 years ago)
Author:
gb
Message:

Kernel side of WAIT-FOR-SIGNAL. Probably needs to be more: a better way
to tell what signals are used by the implementation, some way to revert to
default behavior when this overrides that default, etc.

(Have only tried to compile this on x86 Darwin; don't know about other
platforms yet.)

Location:
trunk/source/lisp-kernel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/imports.s

    r13337 r13970  
    4949        defimport(allocate)
    5050        defimport(deallocate)
    51         defimport(jvm_init)
     51        defimport(wait_for_signal)
    5252        defimport(tcr_frame_ptr)
    5353        defimport(register_xmacptr_dispose_function)
  • trunk/source/lisp-kernel/lisp.h

    r13627 r13970  
    9595extern FILE *dbgout;
    9696
     97void
     98install_signal_handler(int, void*, Boolean);
     99
    97100#endif /* __lisp__ */
  • trunk/source/lisp-kernel/pmcl-kernel.c

    r13954 r13970  
    757757}
    758758
    759 
    760 
    761759#ifndef WINDOWS
     760natural user_signal_semaphores[NSIG];
     761sigset_t user_signals_reserved;
     762#endif
     763
     764
     765
     766#ifndef WINDOWS
    762767void
    763768user_signal_handler (int signum, siginfo_t *info, ExceptionInformation *context)
    764769{
    765   if (signum == SIGINT) {
     770  SEMAPHORE s = (SEMAPHORE)user_signal_semaphores[signum];
     771
     772  if (s != 0) {
     773    signal_semaphore(s);
     774  }
     775  else if (signum == SIGINT) {
    766776    lisp_global(INTFLAG) = (((signum<<8) + 1) << fixnumshift);
    767777  }
     
    779789#endif
    780790
     791
    781792void
    782793register_user_signal_handler()
     
    789800  SetConsoleCtrlHandler(ControlEventHandler,TRUE);
    790801#else
    791   install_signal_handler(SIGINT, (void *)user_signal_handler);
    792   install_signal_handler(SIGTERM, (void *)user_signal_handler);
    793 #endif
    794 }
    795 
    796 
     802  install_signal_handler(SIGINT, (void *)user_signal_handler, false);
     803  install_signal_handler(SIGTERM, (void *)user_signal_handler, false);
     804  install_signal_handler(SIGQUIT, (void *)user_signal_handler, false);
     805#endif
     806}
     807
     808int
     809wait_for_signal(int signo, int seconds, int milliseconds)
     810{
     811#ifdef WINDOWS
     812  return EINVAL;
     813#else
     814  if ((signo <= 0) || (signo >= NSIG)) {
     815    return EINVAL;
     816  }
     817  if (sigismember(&user_signals_reserved,signo)) {
     818    return EINVAL;
     819  }
     820  if (user_signal_semaphores[signo] == 0) {
     821    user_signal_semaphores[signo] = (natural)new_semaphore(0);
     822    install_signal_handler(signo,(void *)user_signal_handler, false);
     823  }
     824  return wait_on_semaphore((void *)user_signal_semaphores[signo],seconds,milliseconds);
     825#endif
     826}
    797827
    798828BytePtr
     
    21222152}
    21232153
    2124 /* A horrible hack to allow us to initialize a JVM instance from lisp.
    2125    On Darwin, creating a JVM instance clobbers the thread's existing
    2126    Mach exception infrastructure, so we save and restore it here.
    2127 */
    2128 
    2129 typedef int (*jvm_initfunc)(void*,void*,void*);
    2130 
    2131 int
    2132 jvm_init(jvm_initfunc f,void*arg0,void*arg1,void*arg2)
    2133 {
    2134   int result = -1;
    2135   TCR *tcr = get_tcr(1);
    2136 #ifdef DARWIN
    2137   extern kern_return_t tcr_establish_lisp_exception_port(TCR *);
    2138 #endif
    2139  
    2140   result = f(arg0,arg1,arg2);
    2141 #ifdef DARWIN
    2142   tcr_establish_lisp_exception_port(tcr);
    2143 #endif
    2144   return result;
    2145 }
    2146  
    21472154
    21482155
  • trunk/source/lisp-kernel/ppc-exceptions.c

    r13295 r13970  
    22092209
    22102210void
    2211 install_signal_handler(int signo, void *handler)
     2211install_signal_handler(int signo, void *handler, Boolean system)
    22122212{
    22132213  struct sigaction sa;
     
    22262226
    22272227  sigaction(signo, &sa, NULL);
     2228  if (system) {
     2229    extern sigset_t user_signals_reserved;
     2230    sigaddset(&user_signals_reserved, signo);
     2231  }
     2232
    22282233}
    22292234
     
    22442249  if (install_signal_handlers_for_exceptions) {
    22452250    extern int no_sigtrap;
    2246     install_signal_handler(SIGILL, (void *)signal_handler);
     2251    install_signal_handler(SIGILL, (void *)signal_handler, true);
    22472252    if (no_sigtrap != 1) {
    2248       install_signal_handler(SIGTRAP, (void *)signal_handler);
    2249     }
    2250     install_signal_handler(SIGBUS,  (void *)signal_handler);
    2251     install_signal_handler(SIGSEGV, (void *)signal_handler);
    2252     install_signal_handler(SIGFPE, (void *)signal_handler);
     2253      install_signal_handler(SIGTRAP, (void *)signal_handler, true);
     2254    }
     2255    install_signal_handler(SIGBUS,  (void *)signal_handler, true);
     2256    install_signal_handler(SIGSEGV, (void *)signal_handler, true);
     2257    install_signal_handler(SIGFPE, (void *)signal_handler, true);
    22532258  }
    22542259 
    22552260  install_signal_handler(SIGNAL_FOR_PROCESS_INTERRUPT,
    2256                          (void *)interrupt_handler);
     2261                         (void *)interrupt_handler, true);
    22572262  signal(SIGPIPE, SIG_IGN);
    22582263}
     
    22932298  thread_kill_signal = SIG_KILL_THREAD;
    22942299
    2295   install_signal_handler(thread_suspend_signal, (void *) suspend_resume_handler);
    2296   install_signal_handler(thread_kill_signal, (void *)thread_kill_handler);
     2300  install_signal_handler(thread_suspend_signal, (void *) suspend_resume_handler, true);
     2301  install_signal_handler(thread_kill_signal, (void *)thread_kill_handler, tru);
    22972302}
    22982303
  • trunk/source/lisp-kernel/x86-exceptions.c

    r13952 r13970  
    18601860#ifndef WINDOWS
    18611861void
    1862 install_signal_handler(int signo, void * handler)
     1862install_signal_handler(int signo, void * handler, Boolean system)
    18631863{
    18641864  struct sigaction sa;
     
    18781878
    18791879  sigaction(signo, &sa, NULL);
     1880  if (system) {
     1881    extern sigset_t user_signals_reserved;
     1882    sigaddset(&user_signals_reserved, signo);
     1883  }
    18801884}
    18811885#endif
     
    20932097#endif
    20942098  ;
    2095   install_signal_handler(SIGILL, handler);
     2099  install_signal_handler(SIGILL, handler, true);
    20962100 
    2097   install_signal_handler(SIGBUS, handler);
    2098   install_signal_handler(SIGSEGV,handler);
    2099   install_signal_handler(SIGFPE, handler);
     2101  install_signal_handler(SIGBUS, handler, true);
     2102  install_signal_handler(SIGSEGV,handler, true);
     2103  install_signal_handler(SIGFPE, handler, true);
    21002104#endif
    21012105 
     
    21062110                         arbstack_interrupt_handler
    21072111#endif
    2108 );
     2112                         ,true);
    21092113  signal(SIGPIPE, SIG_IGN);
    21102114}
     
    23002304  thread_kill_signal = SIG_KILL_THREAD;
    23012305
    2302   install_signal_handler(thread_suspend_signal, (void *)SUSPEND_RESUME_HANDLER);
    2303   install_signal_handler(thread_kill_signal, (void *)THREAD_KILL_HANDLER);
     2306  install_signal_handler(thread_suspend_signal, (void *)SUSPEND_RESUME_HANDLER, true);
     2307  install_signal_handler(thread_kill_signal, (void *)THREAD_KILL_HANDLER, true);
    23042308}
    23052309#endif
Note: See TracChangeset for help on using the changeset viewer.