Ignore:
Timestamp:
Sep 24, 2007, 2:47:31 AM (12 years ago)
Author:
gb
Message:

Don't use sigaltstack on any x86-64 platform: even if it works, it makes
it harder to deal with exceptions in foreign code (we've often gotten
segfaults from running out of space on the alt stack, the mechanism
isn't reentrant, etc.)

Try to report cases where the kernel debugger is entered due to an
exception in foreign code. Todo: make it less tempting to use (L)
in that case, maybe try to make backtrace find saved_rbp from tcr on x86-64,
etc.

File:
1 edited

Legend:

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

    r7137 r7282  
    963963  if (! handle_exception(signum, info, context, tcr, old_valence)) {
    964964    char msg[512];
     965    int foreign = (old_valence == TCR_STATE_LISP) ? 0 : debug_foreign_exception;
    965966
    966967    snprintf(msg, sizeof(msg), "Unhandled exception %d at 0x%lx, context->regs at #x%lx", signum, xpPC(context), (natural)xpGPRvector(context));
    967968   
    968     if (lisp_Debugger(context, info, signum, msg)) {
     969    if (lisp_Debugger(context, info, signum | foreign, msg)) {
    969970      SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PROPAGATE_EXCEPTION);
    970971    }
     
    11341135
    11351136
     1137#ifndef USE_SIGALTSTACK
     1138void
     1139arbstack_signal_handler(int signum, siginfo_t *info, ExceptionInformation *context)
     1140{
     1141  TCR *tcr = get_interrupt_tcr(false);
     1142  area *vs = tcr->vs_area;
     1143  BytePtr current_sp = (BytePtr) current_stack_pointer();
     1144
     1145  if ((current_sp >= vs->low) &&
     1146      (current_sp < vs->high)) {
     1147    handle_signal_on_foreign_stack(tcr,
     1148                                   signal_handler,
     1149                                   signum,
     1150                                   info,
     1151                                   context,
     1152                                   (LispObj)__builtin_return_address(0)
     1153                                   );
     1154  } else {
     1155    signal_handler(signum, info, context, tcr, 0);
     1156  }
     1157}
     1158
     1159#else
    11361160void
    11371161altstack_signal_handler(int signum, siginfo_t *info, ExceptionInformation  *context)
     
    11401164#if 1
    11411165  if (tcr->valence != TCR_STATE_LISP) {
    1142     Bug(context, "exception in foreign context");
     1166    FBug(context, "exception in foreign context");
    11431167  }
    11441168#endif
     
    11491173);
    11501174}
     1175#endif
    11511176
    11521177void
     
    13031328{
    13041329#ifndef DARWIN 
    1305   install_signal_handler(SIGILL, altstack_signal_handler);
    1306  
    1307   install_signal_handler(SIGBUS, altstack_signal_handler);
    1308   install_signal_handler(SIGSEGV,altstack_signal_handler);
    1309   install_signal_handler(SIGFPE, altstack_signal_handler);
     1330  void *handler = (void *)
     1331#ifdef USE_SIGALTSTACK
     1332    altstack_signal_handler
     1333#else
     1334    arbstack_signal_handler;
     1335#endif
     1336  ;
     1337  install_signal_handler(SIGILL, handler);
     1338 
     1339  install_signal_handler(SIGBUS, handler);
     1340  install_signal_handler(SIGSEGV,handler);
     1341  install_signal_handler(SIGFPE, handler);
    13101342#else
    13111343  install_signal_handler(SIGTRAP,bogus_signal_handler);
     
    15511583  stack_t stack;
    15521584  stack.ss_sp = a->low;
    1553   a->low += 8192;
    1554   stack.ss_size = 8192;
     1585  a->low += SIGSTKSZ*8;
     1586  stack.ss_size = SIGSTKSZ*8;
    15551587  stack.ss_flags = 0;
    15561588  mmap(stack.ss_sp,stack.ss_size, PROT_READ|PROT_WRITE|PROT_EXEC,MAP_FIXED|MAP_ANON|MAP_PRIVATE,-1,0);
     
    21012133    raise_pending_interrupt(tcr);
    21022134  } else {
    2103     Bug(NULL, "no xp here!\n");
     2135    FBug(NULL, "no xp here!\n");
    21042136  }
    21052137#ifdef DEBUG_MACH_EXCEPTIONS
Note: See TracChangeset for help on using the changeset viewer.