Changeset 9296


Ignore:
Timestamp:
Apr 26, 2008, 7:52:28 PM (11 years ago)
Author:
gb
Message:

Try to ensure that windows exception handler (mostly) runs on C stack,
always exits via restore_win64_context().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/win64/lisp-kernel/x86-exceptions.c

    r8812 r9296  
    441441                  natural arg1, natural arg2, natural arg3, natural arg4, natural arg5)
    442442{
    443   natural  callback_ptr, i;
     443  natural  callback_ptr;
    444444  int delta;
    445445  unsigned old_mxcsr = get_mxcsr();
     
    11451145#endif
    11461146
    1147 #ifdef WINDOWS
    1148 LispObj *
    1149 copy_ucontext(ExceptionInformation *context, LispObj *current, copy_ucontext_last_arg_t fp)
    1150 {
    1151 }
    1152 #else
     1147#ifndef WINDOWS
    11531148LispObj *
    11541149copy_ucontext(ExceptionInformation *context, LispObj *current, copy_ucontext_last_arg_t fp)
     
    11711166#endif
    11721167
     1168
    11731169LispObj *
    11741170find_foreign_rsp(LispObj rsp, area *foreign_area, TCR *tcr)
     
    11791175    rsp = (LispObj)(tcr->foreign_sp);
    11801176  }
    1181   return (LispObj *) ((rsp-128 & ~15));
     1177  return (LispObj *) (((rsp-128) & ~15));
    11821178}
    11831179
     
    11931189#endif
    11941190
     1191#ifndef WINDOWS
    11951192void
    11961193handle_signal_on_foreign_stack(TCR *tcr,
     
    12381235  switch_to_foreign_stack(foreign_rsp,handler,signum,info_copy,xp);
    12391236}
    1240 
    1241 
     1237#endif
     1238
     1239
     1240#ifndef WINDOWS
    12421241#ifndef USE_SIGALTSTACK
    12431242void
     
    12901289);
    12911290}
     1291#endif
    12921292#endif
    12931293
     
    13791379#endif
    13801380
     1381#ifndef WINDOWS
    13811382#ifndef USE_SIGALTSTACK
    13821383void
     
    14301431}
    14311432
     1433#endif
    14321434#endif
    14331435
     
    14991501}
    15001502
     1503extern LONG restore_win64_context(ExceptionInformation *, TCR *, int;);
     1504
    15011505LONG
    15021506windows_exception_handler(EXCEPTION_POINTERS *exception_pointers)
     
    15121516  wait_for_exception_lock_in_handler(tcr, context, &xframes);
    15131517 
    1514   if (handle_exception(signal_number, info, context, tcr, old_valence)) {
    1515     unlock_exception_lock_in_handler(tcr);
    1516     return EXCEPTION_CONTINUE_EXECUTION;
    1517   } else {
     1518  if (!handle_exception(signal_number, info, context, tcr, old_valence)) {
    15181519    char msg[512];
    15191520    Boolean foreign = (old_valence != TCR_STATE_LISP);
    15201521
    1521     snprintf(msg, sizeof(msg), "Unhandled exception %d at 0x%llx, context->regs at 0x%llx", signal_number, xpPC(context), (natural)xpGPRvector(context));
     1522    snprintf(msg, sizeof(msg), "Unhandled exception %d at 0x%Ix, context->regs at 0x%Ix", signal_number, xpPC(context), (natural)xpGPRvector(context));
    15221523   
    15231524    if (lisp_Debugger(context, info, signal_number,  foreign, msg)) {
    15241525      SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PROPAGATE_EXCEPTION);
    15251526    }
    1526     return EXCEPTION_CONTINUE_EXECUTION;
    1527   }
    1528   return EXCEPTION_CONTINUE_SEARCH;
    1529 }
     1527  }
     1528  unlock_exception_lock_in_handler(tcr);
     1529  return restore_win64_context(context, tcr, old_valence);
     1530}
     1531
     1532LONG windows_switch_to_foreign_stack(LispObj, void*, void*);
     1533
     1534LONG
     1535handle_windows_exception_on_foreign_stack(TCR *tcr,
     1536                                          CONTEXT *context,
     1537                                          void *handler,
     1538                                          EXCEPTION_POINTERS *original_ep)
     1539{
     1540  LispObj foreign_rsp =
     1541    (LispObj) find_foreign_rsp(xpGPR(context,Isp), tcr->cs_area, tcr);
     1542  CONTEXT *new_context;
     1543  siginfo_t *new_info;
     1544  EXCEPTION_POINTERS *new_ep;
     1545
     1546  new_context = ((CONTEXT *)(foreign_rsp&~2))-1;
     1547  *new_context = *context;
     1548  foreign_rsp = (LispObj)new_context;
     1549  new_info = ((siginfo_t *)(foreign_rsp&~2))-1;
     1550  *new_info = *original_ep->ExceptionRecord;
     1551  foreign_rsp = (LispObj)new_info;
     1552  new_ep = ((EXCEPTION_POINTERS *)(foreign_rsp&~2))-1;
     1553  foreign_rsp = (LispObj)new_ep;
     1554  new_ep->ContextRecord = new_context;
     1555  new_ep->ExceptionRecord = new_info;
     1556  return windows_switch_to_foreign_stack(foreign_rsp,handler,new_ep);
     1557}
     1558
     1559LONG
     1560windows_arbstack_exception_handler(EXCEPTION_POINTERS *exception_pointers)
     1561{
     1562  TCR *tcr = get_interrupt_tcr(false);
     1563  area *vs = tcr->vs_area;
     1564  BytePtr current_sp = (BytePtr) current_stack_pointer();
     1565
     1566  if ((current_sp >= vs->low) &&
     1567      (current_sp < vs->high)) {
     1568    return
     1569      handle_windows_exception_on_foreign_stack(tcr,
     1570                                                exception_pointers->ContextRecord,
     1571                                                windows_exception_handler,
     1572                                                exception_pointers);
     1573  }
     1574  return windows_exception_handler(exception_pointers);
     1575}
     1576
    15301577
    15311578void
    15321579install_pmcl_exception_handlers()
    15331580{
    1534   AddVectoredExceptionHandler(1,windows_exception_handler);
     1581  AddVectoredExceptionHandler(1,windows_arbstack_exception_handler);
    15351582}
    15361583#else
     
    15731620#endif
    15741621
     1622#ifndef WINDOWS
    15751623#ifndef USE_SIGALTSTACK
    15761624void
     
    16281676                                 );
    16291677}
    1630 
     1678#endif
    16311679#endif
    16321680
     
    16711719#endif
    16721720
     1721#ifndef WINDOWS
    16731722#ifndef USE_SIGALTSTACK
    16741723arbstack_quit_handler(int signum, siginfo_t *info, ExceptionInformation *context)
     
    17251774                                 );
    17261775}
     1776#endif
    17271777#endif
    17281778
     
    20422092{
    20432093  void *cur_allocptr = (void *)(tcr->save_allocptr);
    2044   LispObj lisprsp, lisptsp;
     2094  LispObj lisprsp;
    20452095  area *a;
    20462096
     
    20872137{
    20882138  TCR *tcr = get_tcr(false), *other_tcr;
    2089   ExceptionInformation* other_xp;
    20902139  int result;
    20912140  signed_natural inhibit;
Note: See TracChangeset for help on using the changeset viewer.