Changeset 6513


Ignore:
Timestamp:
May 9, 2007, 8:41:33 AM (15 years ago)
Author:
gb
Message:

new_heap_segment: if we can't extend with (possibly very large)
lisp_heap_gc_threshold, try smaller values.

Pass "old_valence" to exception handlers; don't call out to lisp
on memory faults from foreign code.

File:
1 edited

Legend:

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

    r6388 r6513  
    577577  if (newlimit > (natural) (a->high)) {
    578578    if (extend) {
    579       if (! resize_dynamic_heap(a->active, (newlimit-oldlimit)+lisp_heap_gc_threshold)) {
    580         return false;
    581       }
     579      natural extend_by = lisp_heap_gc_threshold;
     580      do {
     581        if (resize_dynamic_heap(a->active, (newlimit-oldlimit)+extend_by)) {
     582          break;
     583        }
     584        extend_by = align_to_power_of_2(extend_by>>1, log2_allocation_quantum);
     585        if (extend_by < 4<<20) {
     586          return false;
     587        }
     588      } while (1);
    582589    } else {
    583590      return false;
     
    868875
    869876OSStatus
    870 handle_protection_violation(ExceptionInformation *xp, siginfo_t *info, TCR *tcr)
     877handle_protection_violation(ExceptionInformation *xp, siginfo_t *info, TCR *tcr, int old_valence)
    871878{
    872879  BytePtr addr;
     
    884891  if (addr && (addr == tcr->safe_ref_address)) {
    885892    adjust_exception_pc(xp,4);
     893
    886894    xpGPR(xp,imm0) = 0;
    887895    return 0;
     
    902910    }
    903911  }
    904   callback_for_trap(nrs_CMAIN.vcell, xp, (pc)xpPC(xp), SIGBUS, (natural)addr, is_write_fault(xp,info));
     912  if (old_valence == TCR_STATE_LISP) {
     913    callback_for_trap(nrs_CMAIN.vcell, xp, (pc)xpPC(xp), SIGBUS, (natural)addr, is_write_fault(xp,info));
     914  }
    905915  return -1;
    906916}
     
    12071217                       ExceptionInformation *xp,
    12081218                       TCR *tcr,
    1209                        siginfo_t *info)
     1219                       siginfo_t *info,
     1220                       int old_valence)
    12101221{
    12111222  unsigned oldMQ;
     
    12251236  } else if ((xnum == SIGSEGV) ||
    12261237             (xnum == SIGBUS)) {
    1227     status = handle_protection_violation(xp, info, tcr);
     1238    status = handle_protection_violation(xp, info, tcr, old_valence);
    12281239  } else if (xnum == SIGFPE) {
    12291240    status = handle_sigfpe(xp, tcr);
     
    17291740
    17301741void
    1731 signal_handler(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr)
     1742signal_handler(int signum, siginfo_t *info, ExceptionInformation  *context, TCR *tcr, int old_valence)
    17321743{
    17331744  xframe_list xframe_link;
    1734   int old_valence;
    17351745
    17361746#ifdef DARWIN
     
    17541764 
    17551765  wait_for_exception_lock_in_handler(tcr, context, &xframe_link);
    1756   if ((noErr != PMCL_exception_handler(signum, context, tcr, info))) {
     1766  if ((noErr != PMCL_exception_handler(signum, context, tcr, info, old_valence))) {
    17571767    char msg[512];
    17581768    snprintf(msg, sizeof(msg), "Unhandled exception %d at 0x%lx, context->regs at #x%lx", signum, xpPC(context), (natural)xpGPRvector(context));
     
    20502060          fprintf(stderr, "[0x%x acquired exception lock for interrupt]\n",tcr);
    20512061#endif
    2052           PMCL_exception_handler(signum, context, tcr, info);
     2062          PMCL_exception_handler(signum, context, tcr, info, old_valence);
    20532063          if (disp) {
    20542064            xpGPR(context,allocptr) -= disp;
     
    22292239#ifdef DARWIN
    22302240
     2241
    22312242#define TCR_FROM_EXCEPTION_PORT(p) ((TCR *)((natural)p))
    22322243#define TCR_TO_EXCEPTION_PORT(tcr) ((mach_port_t)((natural)(tcr)))
    22332244
     2245
     2246#if USE_MACH_EXCEPTION_LOCK
    22342247pthread_mutex_t _mach_exception_lock, *mach_exception_lock;
    2235 
     2248#endif
    22362249
    22372250#define LISP_EXCEPTIONS_HANDLED_MASK \
     
    25002513  mach_msg_type_number_t thread_state_count;
    25012514  ExceptionInformation *pseudosigcontext;
    2502   int i, j;
     2515  int i, j, old_valence = tcr->valence;
    25032516  kern_return_t result;
    25042517  natural stackp;
     
    25262539  ts.__r4 = (natural)pseudosigcontext;
    25272540  ts.__r5 = (natural)tcr;
     2541  ts.__r6 = (natural)old_valence;
    25282542  ts.__lr = (natural)pseudo_sigreturn;
    25292543
     
    25492563
    25502564void
    2551 pseudo_signal_handler(int signum, ExceptionInformation *context, TCR *tcr)
    2552 {
    2553   signal_handler(signum, NULL, context, tcr);
     2565pseudo_signal_handler(int signum, ExceptionInformation *context, TCR *tcr, int old_valence)
     2566{
     2567  signal_handler(signum, NULL, context, tcr, old_valence);
    25542568}
    25552569
     
    26602674#endif
    26612675
    2662   if (pthread_mutex_trylock(mach_exception_lock) == 0) {
     2676  if (
     2677#if USE_MACH_EXCEPTION_LOCK
     2678    pthread_mutex_trylock(mach_exception_lock) == 0
     2679#else
     2680    1
     2681#endif
     2682    ) {
    26632683    if (tcr->flags & (1<<TCR_FLAG_BIT_PENDING_EXCEPTION)) {
    26642684      CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
     
    27182738      }
    27192739    }
     2740#if USE_MACH_EXCEPTION_LOCK
    27202741#ifdef DEBUG_MACH_EXCEPTIONS
    27212742    fprintf(stderr, "releasing Mach exception lock in exception thread\n");
    27222743#endif
    27232744    pthread_mutex_unlock(mach_exception_lock);
     2745#endif
    27242746  } else {
    27252747    SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
     
    28132835  kern_return_t kret; 
    28142836  if (__exception_port_set == MACH_PORT_NULL) {
     2837#if USE_MACH_EXCEPTION_LOCK
    28152838    mach_exception_lock = &_mach_exception_lock;
    28162839    pthread_mutex_init(mach_exception_lock, NULL);
    2817 
     2840#endif
    28182841    kret = mach_port_allocate(mach_task_self(),
    28192842                              MACH_PORT_RIGHT_PORT_SET,
     
    30903113
    30913114  LOCK(lisp_global(TCR_AREA_LOCK), current);
     3115#if USE_MACH_EXCEPTION_LOCK
    30923116  pthread_mutex_lock(mach_exception_lock);
     3117#endif
    30933118
    30943119  if (suspend_mach_thread(mach_thread)) {
     
    31183143   
    31193144  }
     3145#if USE_MACH_EXCEPTION_LOCK
    31203146  pthread_mutex_unlock(mach_exception_lock);
     3147#endif
    31213148  UNLOCK(lisp_global(TCR_AREA_LOCK), current);
    31223149  return 0;
Note: See TracChangeset for help on using the changeset viewer.