Changeset 15468


Ignore:
Timestamp:
Sep 24, 2012, 5:39:29 AM (7 years ago)
Author:
gb
Message:

fall back to hashing scheme on Leopard, because mach_port context functions aren't defined there

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/x86-exceptions.c

    r15467 r15468  
    101101like_mach_port_set_context Pmach_port_set_context = NULL;
    102102
     103Boolean use_mach_port_context_functions = false;
     104
    103105void
    104106darwin_early_exception_init()
    105107{
    106108  Pmach_port_get_context = dlsym(RTLD_DEFAULT, "mach_port_get_context");
    107   if (Pmach_port_get_context == NULL) {
    108     Fatal("","Can't find mach_port_get_context");
    109   }
    110109  Pmach_port_set_context = dlsym(RTLD_DEFAULT, "mach_port_set_context");
    111   if (Pmach_port_set_context == NULL) {
    112     Fatal("","Can't find mach_port_set_context");
     110  if ((Pmach_port_set_context != NULL) &&
     111      (Pmach_port_get_context != NULL)) {
     112    use_mach_port_context_functions = true;
    113113  }
    114114}
     
    32903290#define DARWIN_EXCEPTION_HANDLER signal_handler
    32913291
     3292#define EXCEPTION_PORT_BUCKETS 109
     3293
     3294TCR *
     3295exception_port_map[EXCEPTION_PORT_BUCKETS];
     3296
     3297pthread_mutex_t
     3298exception_port_map_lock = PTHREAD_MUTEX_INITIALIZER;
     3299
    32923300TCR *
    32933301find_tcr_from_exception_port(mach_port_t port)
    32943302{
    3295   mach_vm_address_t addr = 0;
    3296   kern_return_t kret;
    3297 
    3298   kret = Pmach_port_get_context(mach_task_self(),port,&addr);
    3299   MACH_CHECK_ERROR("finding TCR from exception port",kret);
    3300   return (TCR *)((natural)addr);
     3303  if (use_mach_port_context_functions) {
     3304    mach_vm_address_t addr = 0;
     3305    kern_return_t kret;
     3306
     3307    kret = Pmach_port_get_context(mach_task_self(),port,&addr);
     3308    MACH_CHECK_ERROR("finding TCR from exception port",kret);
     3309    return (TCR *)((natural)addr);
     3310  } else {
     3311    TCR *tcr = NULL;
     3312    pthread_mutex_lock(&exception_port_map_lock);
     3313
     3314    tcr = exception_port_map[(unsigned)port % EXCEPTION_PORT_BUCKETS];
     3315
     3316    while (tcr) {
     3317      if (TCR_TO_EXCEPTION_PORT(tcr) == port) {
     3318        break;
     3319      }
     3320      tcr = (TCR *)tcr->pending_io_info;
     3321    }
     3322    pthread_mutex_unlock(&exception_port_map_lock);
     3323    return tcr;
     3324  }
    33013325}
    33023326
     
    33043328associate_tcr_with_exception_port(mach_port_t port, TCR *tcr)
    33053329{
    3306   kern_return_t kret;
    3307 
    3308   kret = Pmach_port_set_context(mach_task_self(),port,(mach_vm_address_t)((natural)tcr));
    3309   MACH_CHECK_ERROR("associating TCR with exception port",kret);
     3330  if (use_mach_port_context_functions) {
     3331    kern_return_t kret;
     3332   
     3333    kret = Pmach_port_set_context(mach_task_self(),port,(mach_vm_address_t)((natural)tcr));
     3334    MACH_CHECK_ERROR("associating TCR with exception port",kret);
     3335  } else {
     3336    int b = (unsigned)port % EXCEPTION_PORT_BUCKETS;
     3337    pthread_mutex_lock(&exception_port_map_lock);
     3338   
     3339    tcr->pending_io_info = (void *)(exception_port_map[b]);
     3340    exception_port_map[b] = tcr;
     3341    pthread_mutex_unlock(&exception_port_map_lock);
     3342  }
    33103343}
    33113344
     
    33133346disassociate_tcr_from_exception_port(mach_port_t port)
    33143347{
     3348  if (use_mach_port_context_functions) {
     3349    TCR **prev = &(exception_port_map[(unsigned)port % EXCEPTION_PORT_BUCKETS]),
     3350      *tcr;
     3351    pthread_mutex_lock(&exception_port_map_lock);
     3352
     3353    while((tcr = *prev) != NULL) {
     3354      if (TCR_TO_EXCEPTION_PORT(tcr) == port) {
     3355        *prev = (TCR *)tcr->pending_io_info;
     3356        break;
     3357      }
     3358      prev = (TCR **)&(tcr->pending_io_info);
     3359    }
     3360    pthread_mutex_unlock(&exception_port_map_lock);
     3361  }
    33153362}
    33163363 
Note: See TracChangeset for help on using the changeset viewer.