Changeset 6415 for branches/x8664-call


Ignore:
Timestamp:
May 4, 2007, 5:38:06 AM (13 years ago)
Author:
gb
Message:

Conditionalize for USE_MACH_EXCEPTION_LOCK.
Pass the old_valence through to handle_fault; don't call out to lisp
if we faulted in foreign code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/x8664-call/ccl/lisp-kernel/x86-exceptions.c

    r6367 r6415  
    570570
    571571Boolean
    572 handle_fault(TCR *tcr, ExceptionInformation *xp, siginfo_t *info)
     572handle_fault(TCR *tcr, ExceptionInformation *xp, siginfo_t *info, int old_valence)
    573573{
    574574#ifdef FREEBSD
     
    591591    }
    592592  }
    593   {
     593  if (old_valence == TCR_STATE_LISP) {
    594594    LispObj cmain = nrs_CMAIN.vcell,
    595595      xcf;
     
    727727
    728728Boolean
    729 handle_exception(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr)
     729handle_exception(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr, int old_valence)
    730730{
    731731  pc program_counter = (pc)xpPC(context);
     
    778778
    779779    } else {
    780       return handle_fault(tcr, context, info);
     780      return handle_fault(tcr, context, info, old_valence);
    781781    }
    782782    break;
     
    832832#if SIGBUS != SIGNUM_FOR_INTN_TRAP
    833833  case SIGBUS:
    834     return handle_fault(tcr, context, info);
     834    return handle_fault(tcr, context, info, old_valence);
    835835#endif
    836836   
    837837#if SIGSEGV != SIGNUM_FOR_INTN_TRAP
    838838  case SIGSEGV:
    839     return handle_fault(tcr, context, info);
     839    return handle_fault(tcr, context, info, old_valence);
    840840#endif   
    841841   
     
    932932
    933933
    934   if (! handle_exception(signum, info, context, tcr)) {
     934  if (! handle_exception(signum, info, context, tcr, old_valence)) {
    935935    char msg[512];
    936936
     
    10491049
    10501050#ifdef DARWIN
    1051 /*
    1052    There seems to be a problem with thread-level exception handling;
    1053    Mach seems (under some cirumstances) to conclude that there's
    1054    no thread-level handler and exceptions get passed up to a
    1055    handler that raises Un*x signals.  Ignore those signals so that
    1056    the exception will repropagate and eventually get caught by
    1057    catch_exception_raise() at the thread level.
    1058 
    1059    Mach sucks, but no one understands how.
    1060 */
    1061 void
    1062 bogus_signal_handler()
    1063 {
    1064   /* This does nothing, but does it with signals masked */
     1051void
     1052bogus_signal_handler(int signum, siginfo_t *info, ExceptionInformation *xp)
     1053{
     1054  if (signum == SIGSYS) {
     1055    return;                     /* Leopard lossage */
     1056  }
    10651057}
    10661058#endif
     
    11681160        old_valence = prepare_to_wait_for_exception_lock(tcr, context);
    11691161        wait_for_exception_lock_in_handler(tcr, context, &xframe_link);
    1170         handle_exception(signum, info, context, tcr);
     1162        handle_exception(signum, info, context, tcr, old_valence);
    11711163        if (alloc_displacement) {
    11721164          tcr->save_allocptr -= alloc_displacement;
     
    19151907#define TCR_TO_EXCEPTION_PORT(tcr) ((mach_port_t)((natural)(tcr)))
    19161908
     1909#if USE_MACH_EXCEPTION_LOCK
    19171910pthread_mutex_t _mach_exception_lock, *mach_exception_lock;
     1911#endif
    19181912extern void pseudo_sigreturn(void);
    19191913
     
    22912285#endif
    22922286
     2287
    22932288kern_return_t
    22942289catch_exception_raise(mach_port_t exception_port,
     
    23102305
    23112306
     2307
    23122308#ifdef DEBUG_MACH_EXCEPTIONS
    23132309  fprintf(stderr, "obtaining Mach exception lock in exception thread\n");
     
    23152311
    23162312
    2317   if (pthread_mutex_trylock(mach_exception_lock) == 0) {
     2313  if (
     2314#if USE_MACH_EXCEPTION_LOCK
     2315      pthread_mutex_trylock(mach_exception_lock) == 0
     2316#else
     2317      1
     2318#endif
     2319      ) {
    23182320#ifdef X8664
    2319     thread_state_count = x86_THREAD_STATE64_COUNT;
    2320     call_kret = thread_get_state(thread,
    2321                                  x86_THREAD_STATE64,
    2322                                  (thread_state_t)&ts,
    2323                      &thread_state_count);
     2321    do {
     2322      thread_state_count = x86_THREAD_STATE64_COUNT;
     2323      call_kret = thread_get_state(thread,
     2324                                   x86_THREAD_STATE64,
     2325                                   (thread_state_t)&ts,
     2326                                   &thread_state_count);
     2327    } while (call_kret == KERN_ABORTED);
    23242328  MACH_CHECK_ERROR("getting thread state",call_kret);
    23252329#else
     
    23592363        }
    23602364        break;
    2361      
     2365         
    23622366      case EXC_SOFTWARE:
    2363           signum = SIGILL;
     2367        signum = SIGILL;
    23642368        break;
    2365      
     2369       
    23662370      case EXC_ARITHMETIC:
    23672371        signum = SIGFPE;
    23682372        break;
    2369 
     2373       
    23702374      default:
    23712375        break;
     
    23792383                                  &ts);
    23802384#if 0
    2381       fprintf(stderr, "Setup pseudosignal handling in 0x%x\n",tcr);
    2382 #endif
    2383 
     2385        fprintf(stderr, "Setup pseudosignal handling in 0x%x\n",tcr);
     2386#endif
     2387       
    23842388      } else {
    23852389        kret = 17;
    23862390      }
    23872391    }
     2392#if USE_MACH_EXCEPTION_LOCK
    23882393#ifdef DEBUG_MACH_EXCEPTIONS
    23892394    fprintf(stderr, "releasing Mach exception lock in exception thread\n");
    23902395#endif
    23912396    pthread_mutex_unlock(mach_exception_lock);
     2397#endif
    23922398  } else {
    23932399    SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
     
    23962402    fprintf(stderr, "deferring pending exception in 0x%x\n", tcr);
    23972403#endif
    2398     kret = 0;
     2404    kret = KERN_SUCCESS;
    23992405    if (tcr == gc_tcr) {
    24002406      int i;
     
    24522458  kern_return_t kret; 
    24532459  if (__exception_port_set == MACH_PORT_NULL) {
     2460#if USE_MACH_EXCEPTION_LOCK
    24542461    mach_exception_lock = &_mach_exception_lock;
    24552462    pthread_mutex_init(mach_exception_lock, NULL);
     2463#endif
    24562464
    24572465    kret = mach_port_allocate(mach_task_self(),
Note: See TracChangeset for help on using the changeset viewer.