Changeset 16068


Ignore:
Timestamp:
May 1, 2014, 5:17:13 PM (6 years ago)
Author:
rme
Message:

In suspend_tcr, die a horrible death (via abort) if pthread_kill
returns something unexpected.

Do the same in raise_pending_interrupt and in signal_handler.

Location:
trunk/source/lisp-kernel
Files:
2 edited

Legend:

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

    r16067 r16068  
    20812081{
    20822082  int suspend_count = atomic_incf(&(tcr->suspend_count));
    2083   pthread_t thread;
    2084   if (suspend_count == 1) {
    2085     thread = (pthread_t)(tcr->osid);
    2086     if ((thread != (pthread_t) 0) &&
    2087         (pthread_kill(thread, thread_suspend_signal) == 0)) {
    2088       SET_TCR_FLAG(tcr,TCR_FLAG_BIT_SUSPEND_ACK_PENDING);
    2089     } else {
    2090       /* A problem using pthread_kill.  On Darwin, this can happen
    2091          if the thread has had its signal mask surgically removed
    2092          by pthread_exit.  If the native (Mach) thread can be suspended,
    2093          do that and return true; otherwise, flag the tcr as belonging
    2094          to a dead thread by setting tcr->osid to 0.
    2095       */
     2083
     2084  if (suspend_count == 1 && tcr->osid != 0) {
     2085    pthread_t thread = (pthread_t)tcr->osid;
     2086    int ret;
     2087   
     2088    ret = pthread_kill(thread, thread_suspend_signal);
     2089    switch (ret) {
     2090    case 0:
     2091      SET_TCR_FLAG(tcr, TCR_FLAG_BIT_SUSPEND_ACK_PENDING);
     2092      return true;
     2093    case ESRCH:
     2094      /* The thread appears to be gone already.  Flag the tcr as
     2095         belonging to a dead thread by setting tcr->osid to 0. */
    20962096      tcr->osid = 0;
    20972097      return false;
    2098     }
    2099     return true;
     2098#ifdef DARWIN
     2099    case ENOTSUP:
     2100      /* We can get this (undocumented) result if we signal a
     2101         workqueue thread, which by default blocks signals.  Calling
     2102         the undocumented function __pthread_workqueue_setkill(1) from
     2103         the thread is supposed to make the thread accept signals.  We
     2104         try to call that when creating a TCR for foriegn threads, but
     2105         if we get here, it either means that didn't work, or we
     2106         missed a thread somehow. */
     2107      /* fall through */
     2108#endif
     2109    default:
     2110      fprintf(dbgout, "%s: pthread_kill returned %d, target thread = %p\n",
     2111              __FUNCTION__, ret, thread);
     2112      abort();
     2113    }
    21002114  }
    21012115  return false;
  • trunk/source/lisp-kernel/x86-exceptions.c

    r16066 r16068  
    14511451  if ((TCR_INTERRUPT_LEVEL(tcr) >= 0) &&
    14521452      (tcr->interrupt_pending)) {
    1453     pthread_kill((pthread_t)(tcr->osid), SIGNAL_FOR_PROCESS_INTERRUPT);
     1453    int ret;
     1454    pthread_t thread = (pthread_t)tcr->osid;
     1455
     1456    ret = pthread_kill(thread, SIGNAL_FOR_PROCESS_INTERRUPT);
     1457    if (ret != 0) {
     1458      fprintf(dbgout, "%s: pthread_kill returned %d, target thread = %p\n",
     1459              __FUNCTION__, ret, thread);
     1460      abort();
     1461    }
    14541462  }
    14551463}
     
    14791487  int old_valence = prepare_to_wait_for_exception_lock(tcr, context);
    14801488  if (tcr->flags & (1<<TCR_FLAG_BIT_PENDING_SUSPEND)) {
     1489    int ret;
     1490
    14811491    CLR_TCR_FLAG(tcr, TCR_FLAG_BIT_PENDING_SUSPEND);
    1482     pthread_kill(pthread_self(), thread_suspend_signal);
     1492    ret = pthread_kill(pthread_self(), thread_suspend_signal);
     1493    if (ret != 0) {
     1494      fprintf(dbgout, "%s: pthread_kill returned %d, target thread = %p\n",
     1495              __FUNCTION__, ret, pthread_self());
     1496      abort();
     1497    }
    14831498  }
    14841499  wait_for_exception_lock_in_handler(tcr,context, &xframe_link);
Note: See TracChangeset for help on using the changeset viewer.