Changeset 10401 for release


Ignore:
Timestamp:
Aug 8, 2008, 11:42:01 AM (11 years ago)
Author:
gb
Message:

In 1.2 (this is not exactly the same code as in the trunk):

Remove some old/experimental conditionalization, making some of this
easier to read.

In resume_tcr(), don't try to raise a resume semaphore that may
not exist.

Location:
release/1.2/source/lisp-kernel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • release/1.2/source/lisp-kernel/lisp-exceptions.h

    r8547 r10401  
    140140exception_fn_name( ExceptionInformation *, int, char *, size_t );
    141141
    142 /* Need to define this here */
    143 #ifdef DARWIN
    144 #define USE_MACH_EXCEPTION_LOCK 0
    145 #endif
    146142
    147143
  • release/1.2/source/lisp-kernel/ppc-exceptions.c

    r9067 r10401  
    22792279
    22802280
    2281 #if USE_MACH_EXCEPTION_LOCK
    2282 pthread_mutex_t _mach_exception_lock, *mach_exception_lock;
    2283 #endif
    22842281
    22852282#define LISP_EXCEPTIONS_HANDLED_MASK \
     
    27052702  kern_return_t kret;
    27062703
    2707 #ifdef DEBUG_MACH_EXCEPTIONS
    2708   fprintf(stderr, "obtaining Mach exception lock in exception thread\n");
    2709 #endif
    2710 
    2711   if (
    2712 #if USE_MACH_EXCEPTION_LOCK
    2713     pthread_mutex_trylock(mach_exception_lock) == 0
    2714 #else
    2715     1
    2716 #endif
    2717     ) {
    2718     if (tcr->flags & (1<<TCR_FLAG_BIT_PENDING_EXCEPTION)) {
    2719       CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
    2720     }
    2721     if ((exception == EXC_BAD_INSTRUCTION) &&
    2722         (code_vector[0] == EXC_PPC_UNIPL_INST) &&
    2723         (((code1 = code_vector[1]) == (int)pseudo_sigreturn) ||
    2724          (code1 == (int)enable_fp_exceptions) ||
    2725          (code1 == (int)disable_fp_exceptions))) {
    2726       if (code1 == (int)pseudo_sigreturn) {
    2727         kret = do_pseudo_sigreturn(thread, tcr);
     2704
     2705  if (tcr->flags & (1<<TCR_FLAG_BIT_PENDING_EXCEPTION)) {
     2706    CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
     2707  }
     2708  if ((exception == EXC_BAD_INSTRUCTION) &&
     2709      (code_vector[0] == EXC_PPC_UNIPL_INST) &&
     2710      (((code1 = code_vector[1]) == (int)pseudo_sigreturn) ||
     2711       (code1 == (int)enable_fp_exceptions) ||
     2712       (code1 == (int)disable_fp_exceptions))) {
     2713    if (code1 == (int)pseudo_sigreturn) {
     2714      kret = do_pseudo_sigreturn(thread, tcr);
    27282715#if 0
    27292716      fprintf(stderr, "Exception return in 0x%x\n",tcr);
    27302717#endif
    27312718       
    2732       } else if (code1 == (int)enable_fp_exceptions) {
    2733         kret = thread_set_fp_exceptions_enabled(thread, true);
    2734       } else kret =  thread_set_fp_exceptions_enabled(thread, false);
    2735     } else if (tcr->flags & (1<<TCR_FLAG_BIT_PROPAGATE_EXCEPTION)) {
    2736       CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PROPAGATE_EXCEPTION);
    2737       kret = 17;
    2738     } else {
    2739       switch (exception) {
    2740       case EXC_BAD_ACCESS:
    2741         signum = SIGSEGV;
    2742         break;
     2719    } else if (code1 == (int)enable_fp_exceptions) {
     2720      kret = thread_set_fp_exceptions_enabled(thread, true);
     2721    } else kret =  thread_set_fp_exceptions_enabled(thread, false);
     2722  } else if (tcr->flags & (1<<TCR_FLAG_BIT_PROPAGATE_EXCEPTION)) {
     2723    CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PROPAGATE_EXCEPTION);
     2724    kret = 17;
     2725  } else {
     2726    switch (exception) {
     2727    case EXC_BAD_ACCESS:
     2728      signum = SIGSEGV;
     2729      break;
    27432730       
    2744       case EXC_BAD_INSTRUCTION:
    2745         signum = SIGILL;
    2746         break;
     2731    case EXC_BAD_INSTRUCTION:
     2732      signum = SIGILL;
     2733      break;
    27472734     
    2748       case EXC_SOFTWARE:
    2749         if (code == EXC_PPC_TRAP) {
    2750           signum = SIGTRAP;
    2751         }
    2752         break;
     2735    case EXC_SOFTWARE:
     2736      if (code == EXC_PPC_TRAP) {
     2737        signum = SIGTRAP;
     2738      }
     2739      break;
    27532740     
    2754       case EXC_ARITHMETIC:
    2755         signum = SIGFPE;
    2756         break;
    2757 
    2758       default:
    2759         break;
    2760       }
    2761       if (signum) {
    2762         kret = setup_signal_frame(thread,
    2763                                   (void *)pseudo_signal_handler,
    2764                                   signum,
    2765                                   code,
    2766                                   tcr);
     2741    case EXC_ARITHMETIC:
     2742      signum = SIGFPE;
     2743      break;
     2744
     2745    default:
     2746      break;
     2747    }
     2748    if (signum) {
     2749      kret = setup_signal_frame(thread,
     2750                                (void *)pseudo_signal_handler,
     2751                                signum,
     2752                                code,
     2753                                tcr);
    27672754#if 0
    27682755      fprintf(stderr, "Setup pseudosignal handling in 0x%x\n",tcr);
    27692756#endif
    27702757
    2771       } else {
    2772         kret = 17;
    2773       }
    2774     }
    2775 #if USE_MACH_EXCEPTION_LOCK
    2776 #ifdef DEBUG_MACH_EXCEPTIONS
    2777     fprintf(stderr, "releasing Mach exception lock in exception thread\n");
    2778 #endif
    2779     pthread_mutex_unlock(mach_exception_lock);
    2780 #endif
    2781   } else {
    2782     SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
    2783 #if 0
    2784     fprintf(stderr, "deferring pending exception in 0x%x\n", tcr);
    2785 #endif
    2786     kret = 0;
    2787     if (tcr == gc_tcr) {
    2788       int i;
    2789       write(1, "exception in GC thread. Sleeping for 60 seconds\n",sizeof("exception in GC thread.  Sleeping for 60 seconds\n"));
    2790       for (i = 0; i < 60; i++) {
    2791         sleep(1);
    2792       }
    2793       _exit(EX_SOFTWARE);
     2758    } else {
     2759      kret = 17;
    27942760    }
    27952761  }
     
    28702836  kern_return_t kret; 
    28712837  if (__exception_port_set == MACH_PORT_NULL) {
    2872 #if USE_MACH_EXCEPTION_LOCK
    2873     mach_exception_lock = &_mach_exception_lock;
    2874     pthread_mutex_init(mach_exception_lock, NULL);
    2875 #endif
    28762838    kret = mach_port_allocate(mach_task_self(),
    28772839                              MACH_PORT_RIGHT_PORT_SET,
     
    31483110
    31493111  LOCK(lisp_global(TCR_AREA_LOCK), current);
    3150 #if USE_MACH_EXCEPTION_LOCK
    3151   pthread_mutex_lock(mach_exception_lock);
    3152 #endif
    3153 
    31543112  if (suspend_mach_thread(mach_thread)) {
    31553113    if (thread_info(mach_thread,
     
    31783136   
    31793137  }
    3180 #if USE_MACH_EXCEPTION_LOCK
    3181   pthread_mutex_unlock(mach_exception_lock);
    3182 #endif
    31833138  UNLOCK(lisp_global(TCR_AREA_LOCK), current);
    31843139  return 0;
  • release/1.2/source/lisp-kernel/ppc-exceptions.h

    r9067 r10401  
    388388#include <mach/machine/thread_status.h>
    389389
    390 #if USE_MACH_EXCEPTION_LOCK
    391 pthread_mutex_t *mach_exception_lock;
    392 #endif
    393390#endif
    394391
  • release/1.2/source/lisp-kernel/thread_manager.c

    r10178 r10401  
    1818#include "Threads.h"
    1919
    20 /*
    21    If we suspend via signals - and if the "suspend" signal is maked
    22    in the handler for that signal - then it's not possible to suspend
    23    a thread that's still waiting to be resumed (which is what
    24    WAIT_FOR_RESUME_ACK is all about.)
    25 */
    26 #define WAIT_FOR_RESUME_ACK 0
    27 #define RESUME_VIA_RESUME_SEMAPHORE 1
    28 #define SUSPEND_RESUME_VERBOSE 0
    2920
    3021typedef struct {
     
    156147
    157148static void inline
    158 lock_futex(natural *p)
     149lock_futex(signed_natural *p)
    159150{
    160151 
     
    173164
    174165static void inline
    175 unlock_futex(natural *p)
     166unlock_futex(signed_natural *p)
    176167{
    177168  if (atomic_decf(p) != FUTEX_AVAIL) {
     
    427418}
    428419 
    429   void
     420void
    430421suspend_resume_handler(int signo, siginfo_t *info, ExceptionInformation *context)
    431422{
     
    438429    SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_SUSPEND);
    439430  } else {
    440     if (signo == thread_suspend_signal) {
    441 #if 0
    442       sigset_t wait_for;
    443 #endif
    444 
    445       tcr->suspend_context = context;
    446 #if 0
    447       sigfillset(&wait_for);
    448 #endif
    449       SEM_RAISE(tcr->suspend);
    450 #if 0
    451       sigdelset(&wait_for, thread_resume_signal);
    452 #endif
    453 #if 1
    454 #if RESUME_VIA_RESUME_SEMAPHORE
    455       SEM_WAIT_FOREVER(tcr->resume);
    456 #if SUSPEND_RESUME_VERBOSE
    457       fprintf(stderr, "got  resume in 0x%x\n",tcr);
    458 #endif
    459       tcr->suspend_context = NULL;
    460 #else
    461       sigsuspend(&wait_for);
    462 #endif
    463 #else
    464     do {
    465       sigsuspend(&wait_for);
    466     } while (tcr->suspend_context);
    467 #endif 
    468     } else {
    469       tcr->suspend_context = NULL;
    470 #if SUSEPEND_RESUME_VERBOSE
    471       fprintf(stderr,"got  resume in in 0x%x\n",tcr);
    472 #endif
    473     }
    474 #if WAIT_FOR_RESUME_ACK
     431    tcr->suspend_context = context;
    475432    SEM_RAISE(tcr->suspend);
    476 #endif
     433    SEM_WAIT_FOREVER(tcr->resume);
     434    tcr->suspend_context = NULL;
    477435  }
    478436#ifdef DARWIN_GS_HACK
     
    530488  *size = temp_size;
    531489#endif
    532 
     490#ifdef SOLARIS
     491  stack_t st;
     492 
     493  thr_stksegment(&st);
     494  *size = st.ss_size;
     495  *base = st.ss_sp;
     496 
     497#endif
    533498}
    534499#endif
     
    718683  /* darwin_set_x8664_fs_reg(tcr); */
    719684#endif
    720 }
    721 
    722 #endif
    723 
    724 
     685#ifdef SOLARIS
     686  /* Chris Curtis found this and suggested the use of syscall here */
     687  syscall(SYS_lwp_private,_LWP_SETPRIVATE, _LWP_GSBASE, tcr);
     688#endif
     689}
     690
     691#endif
     692
     693#ifdef X8632
     694#ifdef DARWIN
     695#include <architecture/i386/table.h>
     696#include <architecture/i386/sel.h>
     697#include <i386/user_ldt.h>
     698
     699void setup_tcr_extra_segment(TCR *tcr)
     700{
     701    uintptr_t addr = (uintptr_t)tcr;
     702    unsigned int size = sizeof(*tcr);
     703    ldt_entry_t desc;
     704    sel_t sel;
     705    int i;
     706
     707    desc.data.limit00 = (size - 1) & 0xffff;
     708    desc.data.limit16 = ((size - 1) >> 16) & 0xf;
     709    desc.data.base00 = addr & 0xffff;
     710    desc.data.base16 = (addr >> 16) & 0xff;
     711    desc.data.base24 = (addr >> 24) & 0xff;
     712    desc.data.type = DESC_DATA_WRITE;
     713    desc.data.dpl = USER_PRIV;
     714    desc.data.present = 1;
     715    desc.data.stksz = DESC_CODE_32B;
     716    desc.data.granular = DESC_GRAN_BYTE;
     717   
     718    i = i386_set_ldt(LDT_AUTO_ALLOC, &desc, 1);
     719
     720    if (i < 0) {
     721        perror("i386_set_ldt");
     722    } else {
     723        sel.index = i;
     724        sel.rpl = USER_PRIV;
     725        sel.ti = SEL_LDT;
     726        tcr->ldt_selector = sel;
     727    }
     728}
     729
     730void free_tcr_extra_segment(TCR *tcr)
     731{
     732  /* load %fs with null segement selector */
     733  __asm__ volatile ("mov %0,%%fs" : : "r"(0));
     734  if (i386_set_ldt(tcr->ldt_selector.index, NULL, 1) < 0)
     735    perror("i386_set_ldt");
     736  tcr->ldt_selector = NULL_SEL;
     737}
     738#endif
     739#endif
    725740
    726741/*
     
    747762#ifdef HAVE_TLS
    748763  TCR *tcr = &current_tcr;
    749 #else
     764#else /* no TLS */
    750765  TCR *tcr = allocate_tcr();
    751 #endif
    752 
    753 #ifdef X8664
     766#ifdef X8632
     767  setup_tcr_extra_segment(tcr);
     768#endif
     769#endif
     770
     771#ifdef X86
    754772  setup_tcr_extra_segment(tcr);
    755773  tcr->linear = tcr;
     774#ifdef X8632
     775  tcr->node_regs_mask = X8632_DEFAULT_NODE_REGS_MASK;
     776#endif
    756777#endif
    757778
     
    853874    dequeue_tcr(tcr);
    854875#endif
     876#ifdef DARWIN
     877#ifdef X8632
     878    free_tcr_extra_segment(tcr);
     879#endif
     880#endif
    855881    UNLOCK(lisp_global(TCR_AREA_LOCK),tcr);
    856882    if (termination_semaphore) {
     
    12541280#define NSAVEREGS 4
    12551281#endif
     1282#ifdef X8632
     1283#define NSAVEREGS 0
     1284#endif
    12561285    for (i = 0; i < NSAVEREGS; i++) {
    12571286      *(--current->save_vsp) = 0;
     
    12831312  pthread_t thread;
    12841313  if (suspend_count == 1) {
    1285 #if SUSPEND_RESUME_VERBOSE
    1286     fprintf(stderr,"Suspending 0x%x\n", tcr);
    1287 #endif
    1288 #ifdef DARWIN_nope
    1289     if (mach_suspend_tcr(tcr)) {
    1290       SET_TCR_FLAG(tcr,TCR_FLAG_BIT_ALT_SUSPEND);
    1291       return true;
    1292     }
    1293 #endif
    12941314    thread = (pthread_t)(tcr->osid);
    12951315    if ((thread != (pthread_t) 0) &&
     
    13181338    SEM_WAIT_FOREVER(tcr->suspend);
    13191339    tcr->flags &= ~(1<<TCR_FLAG_BIT_SUSPEND_ACK_PENDING);
    1320 #if SUSPEND_RESUME_VERBOSE
    1321     fprintf(stderr,"Suspend ack from 0x%x\n", tcr);
    1322 #endif
    1323 
    13241340  }
    13251341  return true;
     
    13361352 
    13371353  LOCK(lisp_global(TCR_AREA_LOCK),current);
    1338 #ifdef DARWIN
    1339 #if USE_MACH_EXCEPTION_LOCK
    1340   if (use_mach_exception_handling) {
    1341     pthread_mutex_lock(mach_exception_lock);
    1342   }
    1343 #endif
    1344 #endif
    13451354  suspended = suspend_tcr(tcr);
    13461355  if (suspended) {
    13471356    while (!tcr_suspend_ack(tcr));
    13481357  }
    1349 #ifdef DARWIN
    1350 #if USE_MACH_EXCEPTION_LOCK
    1351   if (use_mach_exception_handling) {
    1352     pthread_mutex_unlock(mach_exception_lock);
    1353   }
    1354 #endif
    1355 #endif
    13561358  UNLOCK(lisp_global(TCR_AREA_LOCK),current);
    13571359  return suspended;
     
    13641366  int suspend_count = atomic_decf(&(tcr->suspend_count));
    13651367  if (suspend_count == 0) {
    1366 #ifdef DARWIN
    1367     if (tcr->flags & (1<<TCR_FLAG_BIT_ALT_SUSPEND)) {
    1368 #if SUSPEND_RESUME_VERBOSE
    1369     fprintf(stderr,"Mach resume to 0x%x\n", tcr);
    1370 #endif
    1371       mach_resume_tcr(tcr);
     1368    void *s = (tcr->resume);
     1369    if (s != NULL) {
     1370      SEM_RAISE(s);
    13721371      return true;
    13731372    }
    1374 #endif
    1375 #if RESUME_VIA_RESUME_SEMAPHORE
    1376     SEM_RAISE(tcr->resume);
    1377 #else
    1378     if ((err = (pthread_kill((pthread_t)(tcr->osid), thread_resume_signal))) != 0) {
    1379       Bug(NULL, "pthread_kill returned %d on thread #x%x", err, tcr->osid);
    1380     }
    1381 #endif
    1382 #if SUSPEND_RESUME_VERBOSE
    1383     fprintf(stderr, "Sent resume to 0x%x\n", tcr);
    1384 #endif
    1385     return true;
    13861373  }
    13871374  return false;
    13881375}
    13891376
    1390 void
    1391 wait_for_resumption(TCR *tcr)
    1392 {
    1393   if (tcr->suspend_count == 0) {
    1394 #ifdef DARWIN
    1395     if (tcr->flags & (1<<TCR_FLAG_BIT_ALT_SUSPEND)) {
    1396       tcr->flags &= ~(1<<TCR_FLAG_BIT_ALT_SUSPEND);
    1397       return;
    1398   }
    1399 #endif
    1400 #if WAIT_FOR_RESUME_ACK
    1401 #if SUSPEND_RESUME_VERBOSE
    1402     fprintf(stderr, "waiting for resume in 0x%x\n",tcr);
    1403 #endif
    1404     SEM_WAIT_FOREVER(tcr->suspend);
    1405 #endif
    1406   }
    1407 }
    14081377   
    14091378
     
    14171386  LOCK(lisp_global(TCR_AREA_LOCK),current);
    14181387  resumed = resume_tcr(tcr);
    1419   wait_for_resumption(tcr);
    14201388  UNLOCK(lisp_global(TCR_AREA_LOCK), current);
    14211389  return resumed;
     
    14831451
    14841452  LOCK(lisp_global(TCR_AREA_LOCK), current);
    1485 #ifdef DARWIN
    1486 #if USE_MACH_EXCEPTION_LOCK
    1487   if (for_gc && use_mach_exception_handling) {
    1488 #if SUSPEND_RESUME_VERBOSE
    1489     fprintf(stderr, "obtaining Mach exception lock in GC thread 0x%x\n", current);
    1490 #endif
    1491     pthread_mutex_lock(mach_exception_lock);
    1492   }
    1493 #endif
    1494 #endif
    14951453  for (other = current->next; other != current; other = other->next) {
    14961454    if ((other->osid != 0)) {
     
    15331491lisp_suspend_other_threads()
    15341492{
    1535   TCR *current = get_tcr(true);
    1536   LOCK(lisp_global(TCR_AREA_LOCK),current);
    15371493  suspend_other_threads(false);
    15381494}
     
    15471503    }
    15481504  }
    1549   for (other = current->next; other != current; other = other->next) {
    1550     if ((other->osid != 0)) {
    1551       wait_for_resumption(other);
    1552     }
    1553   }
    15541505  free_freed_tcrs();
    1555 #ifdef DARWIN
    1556 #if USE_MACH_EXCEPTION_LOCK
    1557   if (for_gc && use_mach_exception_handling) {
    1558 #if SUSPEND_RESUME_VERBOSE
    1559     fprintf(stderr, "releasing Mach exception lock in GC thread 0x%x\n", current);
    1560 #endif
    1561     pthread_mutex_unlock(mach_exception_lock);
    1562   }
    1563 #endif
    1564 #endif
    1565 
    15661506  UNLOCK(lisp_global(TCR_AREA_LOCK), current);
    15671507}
     
    15701510lisp_resume_other_threads()
    15711511{
    1572   TCR *current = get_tcr(true);
    15731512  resume_other_threads(false);
    1574   UNLOCK(lisp_global(TCR_AREA_LOCK),current);
    15751513}
    15761514
  • release/1.2/source/lisp-kernel/x86-exceptions.c

    r9055 r10401  
    21372137#define TCR_TO_EXCEPTION_PORT(tcr) ((mach_port_t)((natural)(tcr)))
    21382138
    2139 #if USE_MACH_EXCEPTION_LOCK
    2140 pthread_mutex_t _mach_exception_lock, *mach_exception_lock;
    2141 #endif
    21422139extern void pseudo_sigreturn(void);
    21432140
     
    25412538
    25422539
    2543   if (
    2544 #if USE_MACH_EXCEPTION_LOCK
    2545       pthread_mutex_trylock(mach_exception_lock) == 0
    2546 #else
    2547       1
    2548 #endif
    2549       ) {
    25502540#ifdef X8664
    2551     do {
    2552       thread_state_count = x86_THREAD_STATE64_COUNT;
    2553       call_kret = thread_get_state(thread,
    2554                                    x86_THREAD_STATE64,
    2555                                    (thread_state_t)&ts,
    2556                                    &thread_state_count);
    2557     } while (call_kret == KERN_ABORTED);
     2541  do {
     2542    thread_state_count = x86_THREAD_STATE64_COUNT;
     2543    call_kret = thread_get_state(thread,
     2544                                 x86_THREAD_STATE64,
     2545                                 (thread_state_t)&ts,
     2546                                 &thread_state_count);
     2547  } while (call_kret == KERN_ABORTED);
    25582548  MACH_CHECK_ERROR("getting thread state",call_kret);
    25592549#else
    2560     thread_state_count = x86_THREAD_STATE_COUNT;
    2561     thread_get_state(thread,
    2562                      x86_THREAD_STATE,
    2563                      (thread_state_t)&ts,
    2564                      &thread_state_count);
    2565 #endif
    2566     if (tcr->flags & (1<<TCR_FLAG_BIT_PENDING_EXCEPTION)) {
    2567       CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
    2568     }
    2569     if ((code == EXC_I386_GPFLT) &&
    2570         ((natural)(ts_pc(ts)) == (natural)pseudo_sigreturn)) {
    2571       kret = do_pseudo_sigreturn(thread, tcr);
    2572 #if 0
    2573       fprintf(stderr, "Exception return in 0x%x\n",tcr);
    2574 #endif
    2575     } else if (tcr->flags & (1<<TCR_FLAG_BIT_PROPAGATE_EXCEPTION)) {
    2576       CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PROPAGATE_EXCEPTION);
     2550  thread_state_count = x86_THREAD_STATE_COUNT;
     2551  thread_get_state(thread,
     2552                   x86_THREAD_STATE,
     2553                   (thread_state_t)&ts,
     2554                   &thread_state_count);
     2555#endif
     2556  if (tcr->flags & (1<<TCR_FLAG_BIT_PENDING_EXCEPTION)) {
     2557    CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
     2558  }
     2559  if ((code == EXC_I386_GPFLT) &&
     2560      ((natural)(ts_pc(ts)) == (natural)pseudo_sigreturn)) {
     2561    kret = do_pseudo_sigreturn(thread, tcr);
     2562  } else if (tcr->flags & (1<<TCR_FLAG_BIT_PROPAGATE_EXCEPTION)) {
     2563    CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PROPAGATE_EXCEPTION);
     2564    kret = 17;
     2565  } else {
     2566    switch (exception) {
     2567    case EXC_BAD_ACCESS:
     2568      if (code == EXC_I386_GPFLT) {
     2569        signum = SIGSEGV;
     2570      } else {
     2571        signum = SIGBUS;
     2572      }
     2573      break;
     2574       
     2575    case EXC_BAD_INSTRUCTION:
     2576      if (code == EXC_I386_GPFLT) {
     2577        signum = SIGSEGV;
     2578      } else {
     2579        signum = SIGILL;
     2580      }
     2581      break;
     2582         
     2583    case EXC_SOFTWARE:
     2584      signum = SIGILL;
     2585      break;
     2586       
     2587    case EXC_ARITHMETIC:
     2588      signum = SIGFPE;
     2589      break;
     2590       
     2591    default:
     2592      break;
     2593    }
     2594    if (signum) {
     2595      kret = setup_signal_frame(thread,
     2596                                (void *)DARWIN_EXCEPTION_HANDLER,
     2597                                signum,
     2598                                code,
     2599                                tcr,
     2600                                &ts);
     2601       
     2602    } else {
    25772603      kret = 17;
    2578     } else {
    2579       switch (exception) {
    2580       case EXC_BAD_ACCESS:
    2581         if (code == EXC_I386_GPFLT) {
    2582           signum = SIGSEGV;
    2583         } else {
    2584           signum = SIGBUS;
    2585         }
    2586         break;
    2587        
    2588       case EXC_BAD_INSTRUCTION:
    2589         if (code == EXC_I386_GPFLT) {
    2590           signum = SIGSEGV;
    2591         } else {
    2592           signum = SIGILL;
    2593         }
    2594         break;
    2595          
    2596       case EXC_SOFTWARE:
    2597         signum = SIGILL;
    2598         break;
    2599        
    2600       case EXC_ARITHMETIC:
    2601         signum = SIGFPE;
    2602         break;
    2603        
    2604       default:
    2605         break;
    2606       }
    2607       if (signum) {
    2608         kret = setup_signal_frame(thread,
    2609                                   (void *)DARWIN_EXCEPTION_HANDLER,
    2610                                   signum,
    2611                                   code,
    2612                                   tcr,
    2613                                   &ts);
    2614 #if 0
    2615         fprintf(stderr, "Setup pseudosignal handling in 0x%x\n",tcr);
    2616 #endif
    2617        
    2618       } else {
    2619         kret = 17;
    2620       }
    2621     }
    2622 #if USE_MACH_EXCEPTION_LOCK
    2623 #ifdef DEBUG_MACH_EXCEPTIONS
    2624     fprintf(stderr, "releasing Mach exception lock in exception thread\n");
    2625 #endif
    2626     pthread_mutex_unlock(mach_exception_lock);
    2627 #endif
    2628   } else {
    2629     SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
    2630      
    2631 #if 0
    2632     fprintf(stderr, "deferring pending exception in 0x%x\n", tcr);
    2633 #endif
    2634     kret = KERN_SUCCESS;
    2635     if (tcr == gc_tcr) {
    2636       int i;
    2637       write(1, "exception in GC thread. Sleeping for 60 seconds\n",sizeof("exception in GC thread.  Sleeping for 60 seconds\n"));
    2638       for (i = 0; i < 60; i++) {
    2639         sleep(1);
    2640       }
    2641       _exit(EX_SOFTWARE);
    2642     }
    2643   }
     2604    }
     2605  }
     2606 
    26442607  return kret;
    26452608}
Note: See TracChangeset for help on using the changeset viewer.