Changeset 8812


Ignore:
Timestamp:
Mar 17, 2008, 7:23:09 AM (11 years ago)
Author:
gb
Message:

Start handling exceptions on Win64. (Not thread-safe yet.)

File:
1 edited

Legend:

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

    r8581 r8812  
    802802}
    803803
    804 #ifdef WINDOWS
    805 Boolean
    806 handle_exception(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr, int old_valence)
    807 {
    808 }
    809 #else
    810804Boolean
    811805handle_exception(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr, int old_valence)
     
    958952  }
    959953}
    960 #endif
     954
    961955
    962956/*
     
    14381432#endif
    14391433
    1440 #ifdef WINDOWS
    1441 void
    1442 install_signal_handler(int signo, void * handler)
    1443 {
    1444 }
    1445 #else
     1434#ifndef WINDOWS
    14461435void
    14471436install_signal_handler(int signo, void * handler)
     
    14711460
    14721461#ifdef WINDOWS
     1462BOOL
     1463ControlEventHandler(DWORD event)
     1464{
     1465  switch(event) {
     1466  case CTRL_C_EVENT:
     1467    lisp_global(INTFLAG) = (1 << fixnumshift);
     1468    return TRUE;
     1469    break;
     1470  default:
     1471    return FALSE;
     1472  }
     1473}
     1474
     1475int
     1476map_windows_exception_code_to_posix_signal(DWORD code)
     1477{
     1478  switch (code) {
     1479  case EXCEPTION_ACCESS_VIOLATION:
     1480    return SIGSEGV;
     1481  case EXCEPTION_FLT_DENORMAL_OPERAND:
     1482  case EXCEPTION_FLT_DIVIDE_BY_ZERO:
     1483  case EXCEPTION_FLT_INEXACT_RESULT:
     1484  case EXCEPTION_FLT_INVALID_OPERATION:
     1485  case EXCEPTION_FLT_OVERFLOW:
     1486  case EXCEPTION_FLT_STACK_CHECK:
     1487  case EXCEPTION_FLT_UNDERFLOW:
     1488  case EXCEPTION_INT_DIVIDE_BY_ZERO:
     1489  case EXCEPTION_INT_OVERFLOW:
     1490    return SIGFPE;
     1491  case EXCEPTION_PRIV_INSTRUCTION:
     1492  case EXCEPTION_ILLEGAL_INSTRUCTION:
     1493    return SIGILL;
     1494  case EXCEPTION_IN_PAGE_ERROR:
     1495    return SIGBUS;
     1496  default:
     1497    return -1;
     1498  }
     1499}
     1500
     1501LONG
     1502windows_exception_handler(EXCEPTION_POINTERS *exception_pointers)
     1503{
     1504  TCR *tcr = get_tcr(false);
     1505  DWORD code = exception_pointers->ExceptionRecord->ExceptionCode;
     1506  int old_valence = tcr->valence,
     1507    signal_number = map_windows_exception_code_to_posix_signal(code);
     1508  ExceptionInformation *context = exception_pointers->ContextRecord;
     1509    siginfo_t *info = exception_pointers->ExceptionRecord;
     1510    xframe_list xframes;
     1511
     1512  wait_for_exception_lock_in_handler(tcr, context, &xframes);
     1513 
     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    char msg[512];
     1519    Boolean foreign = (old_valence != TCR_STATE_LISP);
     1520
     1521    snprintf(msg, sizeof(msg), "Unhandled exception %d at 0x%llx, context->regs at 0x%llx", signal_number, xpPC(context), (natural)xpGPRvector(context));
     1522   
     1523    if (lisp_Debugger(context, info, signal_number,  foreign, msg)) {
     1524      SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PROPAGATE_EXCEPTION);
     1525    }
     1526    return EXCEPTION_CONTINUE_EXECUTION;
     1527  }
     1528  return EXCEPTION_CONTINUE_SEARCH;
     1529}
     1530
    14731531void
    14741532install_pmcl_exception_handlers()
    14751533{
     1534  AddVectoredExceptionHandler(1,windows_exception_handler);
    14761535}
    14771536#else
Note: See TracChangeset for help on using the changeset viewer.