Ticket #363: fork_threaddata.diff

File fork_threaddata.diff, 2.8 KB (added by dmik, 3 years ago)
  • src/lib/process/thread_internals.c

     
    531531
    532532    if (!gfForkCleanupDone)
    533533    {
    534         LIBCLOG_MSG("Unlocking the thread DB.\n");
    535534        if (enmCtx == __LIBC_FORK_CTX_PARENT)
     535        {
     536            LIBCLOG_MSG("Unlocking the thread DB.\n");
    536537            _fmutex_release(&gmtxThrdDB);
    537         else
    538             _fmutex_release_fork(&gmtxThrdDB);
     538        }
    539539        gfForkCleanupDone = 1;
    540540    }
    541541    LIBCLOG_RETURN_VOID();
     
    576576
    577577_FORK_PARENT1(0xffffff02, threadForkParent1)
    578578
     579
     580/**
     581 * Child fork callback for ressetting gPreAllocThrd (normally used for
     582 * thread 1) and other global thread data variables to their initial state.
     583 *
     584 * @note This callback must be registered with a priority higher than
     585 * fhForkChild1 and any other callback that might call LIBC thread functions.
     586 *
     587 * @returns 0 on success.
     588 * @returns -errno on failure.
     589 * @param   pForkHandle     Pointer to fork handle.
     590 * @param   enmOperation    Fork operation.
     591 */
     592static int threadForkChild1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     593{
     594    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     595
     596    if (enmOperation != __LIBC_FORK_OP_FORK_CHILD)
     597        LIBCLOG_RETURN_INT(0);
     598
     599    /*
     600     * Release the mutex locked in parent. Note that we do it here rather than
     601     * in threadForkCompletion as that one called too late and this mutex
     602     * can be used earlier (e.g. when accessing LIBC thread data).
     603     */
     604    _fmutex_release_fork(&gmtxThrdDB);
     605
     606    /*
     607     * Reset other global thread variables.
     608     */
     609    gpThrdDB = NULL;
     610    gcThrdDBEntries = 0;
     611    gpThrdDBZombies = NULL;
     612    gcThrdDBZombies = 0;
     613    gpTermHead = NULL;
     614    gpTermTail = NULL;
     615    gsmtxTerm = '\0';
     616
     617    /*
     618     * Cause the main thread to be re-iniitialized as new.
     619     */
     620    gfPreAllocThrd = 0;
     621    *__libc_gpTLS = NULL;
     622    __libc_threadCurrentSlow();
     623
     624    LIBCLOG_RETURN_INT(0);
     625}
     626
     627
     628_FORK_CHILD1(0xffffff02, threadForkChild1)
  • src/lib/sys/b_panic.c

     
    162162 */
    163163void __libc_Back_panicV(unsigned fFlags, void *pvCtx, const char *pszFormat, va_list args)
    164164{
    165     LIBCLOG_ENTER("fFlags=%#x pvCtx=%p pszFormat=%p:{%s}\n", fFlags, pvCtx, (void *)pszFormat, args);
     165    LIBCLOG_ENTER("fFlags=%#x pvCtx=%p pszFormat=%p:{%s}\n", fFlags, pvCtx, (void *)pszFormat, (void *)pszFormat);
    166166
    167167    /*
    168168     * First, terminate the exception handler chain to avoid recursive trouble.