Changeset 5072


Ignore:
Timestamp:
Sep 2, 2006, 10:11:43 AM (18 years ago)
Author:
Gary Byers
Message:

Install a "bogus signal handler" on Darwin, to deal with apparent
race conditions/Mach kernel lossage.

Don't do the whole msg_server here; just do the exc_server thing.

Fix a couple of Mach exception-handling bugs; at least one more
may remain.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/lisp-kernel/x86-exceptions.c

    r5017 r5072  
    917917}
    918918
     919
     920#ifdef DARWIN
     921/*
     922   There seems to be a problem with thread-level exception handling;
     923   Mach seems (under some cirumstances) to conclude that there's
     924   no thread-level handler and exceptions get passed up to a
     925   handler that raises Un*x signals.  Ignore those signals so that
     926   the exception will repropagate and eventually get caught by
     927   catch_exception_raise() at the thread level.
     928
     929   Mach sucks, but no one understands how.
     930*/
     931void
     932bogus_signal_handler()
     933{
     934  /* This does nothing, but does it with signals masked */
     935}
     936#endif
     937
    919938void
    920939altstack_signal_handler(int signum, siginfo_t *info, ExceptionInformation  *context)
     
    10641083  install_signal_handler(SIGSEGV,altstack_signal_handler);
    10651084  install_signal_handler(SIGFPE, altstack_signal_handler);
     1085#else
     1086  install_signal_handler(SIGTRAP,bogus_signal_handler);
     1087  install_signal_handler(SIGILL, bogus_signal_handler);
     1088 
     1089  install_signal_handler(SIGBUS, bogus_signal_handler);
     1090  install_signal_handler(SIGSEGV,bogus_signal_handler);
     1091  install_signal_handler(SIGFPE, bogus_signal_handler);
    10661092#endif
    10671093 
     
    15411567
    15421568pthread_mutex_t _mach_exception_lock, *mach_exception_lock;
    1543 extern void pseudo_sigreturn(ExceptionInformation *);
     1569extern void pseudo_sigreturn(void);
     1570
    15441571
    15451572
     
    17301757
    17311758 
    1732   if (result != KERN_SUCCESS) {
    1733     get_tcr(true);
    1734     Bug(NULL, "Exception thread can't obtain thread state, Mach result = %d", result);
    1735   }
    17361759  stackp = (LispObj) find_foreign_rsp(ts->rsp,tcr->cs_area,tcr);
    17371760  stackp = TRUNC_DOWN(stackp, C_REDZONE_LEN, C_STK_ALIGN);
     
    19161939  int signum = 0, code = *code_vector, code1;
    19171940  TCR *tcr = TCR_FROM_EXCEPTION_PORT(exception_port);
    1918   kern_return_t kret;
     1941  kern_return_t kret, call_kret;
    19191942#ifdef X8664
    19201943  x86_thread_state64_t ts;
     
    19331956#ifdef X8664
    19341957    thread_state_count = x86_THREAD_STATE64_COUNT;
    1935     thread_get_state(thread,
    1936                      x86_THREAD_STATE64,
    1937                      (thread_state_t)&ts,
     1958    call_kret = thread_get_state(thread,
     1959                                 x86_THREAD_STATE64,
     1960                                 (thread_state_t)&ts,
    19381961                     &thread_state_count);
     1962  MACH_CHECK_ERROR("getting thread state",call_kret);
    19391963#else
    19401964    thread_state_count = x86_THREAD_STATE_COUNT;
     
    20122036
    20132037
    2014 typedef struct {
    2015   mach_msg_header_t Head;
    2016   /* start of the kernel processed data */
    2017   mach_msg_body_t msgh_body;
    2018   mach_msg_port_descriptor_t thread;
    2019   mach_msg_port_descriptor_t task;
    2020   /* end of the kernel processed data */
    2021   NDR_record_t NDR;
    2022   exception_type_t exception;
    2023   mach_msg_type_number_t codeCnt;
    2024   integer_t code[2];
    2025   mach_msg_trailer_t trailer;
    2026 } exceptionRequest;
    2027 
    2028 
    2029 boolean_t
    2030 openmcl_exc_server(mach_msg_header_t *in, mach_msg_header_t *out)
    2031 {
    2032   static NDR_record_t _NDR = {0};
    2033   kern_return_t handled;
    2034   mig_reply_error_t *reply = (mig_reply_error_t *) out;
    2035   exceptionRequest *req = (exceptionRequest *) in;
    2036 
    2037   reply->NDR = _NDR;
    2038 
    2039   out->msgh_bits = in->msgh_bits & MACH_MSGH_BITS_REMOTE_MASK;
    2040   out->msgh_remote_port = in->msgh_remote_port;
    2041   out->msgh_size = sizeof(mach_msg_header_t)+(3 * sizeof(unsigned));
    2042   out->msgh_local_port = MACH_PORT_NULL;
    2043   out->msgh_id = in->msgh_id+100;
    2044 
    2045   /* Could handle other exception flavors in the range 2401-2403 */
    2046 
    2047 
    2048   if (in->msgh_id != 2401) {
    2049     reply->RetCode = MIG_BAD_ID;
    2050     return FALSE;
    2051   }
    2052   handled = catch_exception_raise(req->Head.msgh_local_port,
    2053                                   req->thread.name,
    2054                                   req->task.name,
    2055                                   req->exception,
    2056                                   req->code,
    2057                                   req->codeCnt);
    2058   reply->RetCode = handled;
    2059   return TRUE;
    2060 }
     2038
    20612039
    20622040/*
     
    20702048  mach_port_t p = TCR_TO_EXCEPTION_PORT(arg);
    20712049
    2072   mach_msg_server(openmcl_exc_server, 2048, p, 0);
     2050  mach_msg_server(exc_server, 256, p, 0);
    20732051  /* Should never return. */
    20742052  abort();
Note: See TracChangeset for help on using the changeset viewer.