Changeset 7282


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.

Location:
trunk/ccl/lisp-kernel
Files:
4 edited

Legend:

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

    r6536 r7282  
    3838  debug_kill
    3939} debug_command_return;
     40
     41
    4042
    4143typedef debug_command_return (*debug_command) (ExceptionInformation *,
     
    685687   NULL,
    686688   'A'},
    687 #endif
    688689  {debug_identify_exception,
    689690   "Describe the current exception in greater detail",
     
    692693   NULL,
    693694   'D'},
     695#endif
    694696  {debug_show_registers,
    695697   "Show raw GPR/SPR register values",
     
    820822  va_list args;
    821823  debug_command_return state = debug_continue;
     824  int in_foreign_code = (why & debug_foreign_exception);
    822825
    823826  if (threads_initialized) {
     
    829832  fprintf(stderr, "\n");
    830833  va_end(args);
     834  if (in_foreign_code) {
     835    fprintf(stderr, "Exception occurred while executing foreign code\n");
     836    why = (why & ~debug_foreign_exception);
     837  }
     838
    831839  if (lisp_global(BATCH_FLAG)) {
    832840    abort();
     
    871879
    872880}
     881
     882void
     883FBug(ExceptionInformation *xp, const char *format, ...)
     884{
     885  va_list args;
     886  char s[512];
     887 
     888  va_start(args, format);
     889  vsnprintf(s, sizeof(s),format, args);
     890  va_end(args);
     891  lisp_Debugger(xp, NULL, debug_entry_bug | debug_foreign_exception , s);
     892
     893}
     894
    873895void
    874896lisp_bug(char *string)
  • trunk/ccl/lisp-kernel/lisp-exceptions.h

    r6511 r7282  
    112112
    113113void Bug(ExceptionInformation *, const char *format_string, ...);
     114void FBug(ExceptionInformation *, const char *format_string, ...);
    114115int gc_from_xp(ExceptionInformation *, signed_natural);
    115116int purify_from_xp(ExceptionInformation *, signed_natural);
     
    145146void resume_other_threads(Boolean);
    146147
     148#define debug_foreign_exception 0x80
    147149
    148150#endif /* __lisp_exceptions_h__ */
  • 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
  • trunk/ccl/lisp-kernel/x86-exceptions.h

    r6527 r7282  
    146146#undef USE_SIGALTSTACK
    147147#else
    148 #define USE_SIGALTSTACK 1
     148/* #define USE_SIGALTSTACK 1 */
     149#undef USE_SIGALTSTACK
    149150#endif
    150151
Note: See TracChangeset for help on using the changeset viewer.