VirtualBox

Changeset 54358 in vbox


Ignore:
Timestamp:
Feb 22, 2015 11:29:25 PM (10 years ago)
Author:
vboxsync
Message:

IPRT/R0Drv: Fix (windows & solaris) / kludge (the rest) for thread termination racing IPRT termination race in ring-0.

Location:
trunk/src/VBox/Runtime
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/thread.cpp

    r52457 r54358  
    7474*******************************************************************************/
    7575/** The AVL thread containing the threads. */
    76 static PAVLPVNODECORE   g_ThreadTree;
     76static PAVLPVNODECORE       g_ThreadTree;
     77/** The number of threads in the tree (for ring-0 termination kludge). */
     78static uint32_t volatile    g_cThreadInTree;
    7779#ifdef IN_RING3
    7880/** The RW lock protecting the tree. */
     
    455457                fRc = RTAvlPVInsert(&g_ThreadTree, &pThread->Core);
    456458                ASMAtomicOrU32(&pThread->fIntFlags, RTTHREADINT_FLAG_IN_TREE);
     459                if (fRc)
     460                    ASMAtomicIncU32(&g_cThreadInTree);
    457461
    458462                AssertReleaseMsg(fRc, ("Lock problem? %p (%RTnthrd) %s\n", pThread, NativeThread, pThread->szName));
     
    479483                                    pThread, pThread->Core.Key, pThread->szName));
    480484#endif
    481     NOREF(pThread2);
     485    if (pThread2)
     486        ASMAtomicDecU32(&g_cThreadInTree);
    482487}
    483488
     
    11761181                     */
    11771182                    if (ASMAtomicBitTestAndClear(&pThread->fFlags, RTTHREADFLAGS_WAITABLE_BIT))
     1183                    {
    11781184                        rtThreadRelease(pThread);
     1185#ifdef IN_RING0
     1186                        /*
     1187                         * IPRT termination kludge. Call native code to make sure
     1188                         * the last thread is really out of IPRT to prevent it from
     1189                         * crashing after we destroyed the spinlock in rtThreadTerm.
     1190                         */
     1191                        if (   ASMAtomicReadU32(&g_cThreadInTree) == 1
     1192                            && ASMAtomicReadU32(&pThread->cRefs) > 1)
     1193                            rtThreadNativeWaitKludge(pThread);
     1194#endif
     1195                    }
    11791196                }
    11801197            }
  • trunk/src/VBox/Runtime/include/internal/thread.h

    r52457 r54358  
    176176DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread);
    177177
     178#ifdef IN_RING0
     179/**
     180 * Called from rtThreadWait when the last thread has completed in order to make
     181 * sure it's all the way out of IPRT before RTR0Term is called.
     182 *
     183 * @param   pThread     The thread structure.
     184 */
     185DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread);
     186#endif
     187
     188
    178189/**
    179190 * Sets the priority of the thread according to the thread type
  • trunk/src/VBox/Runtime/r0drv/darwin/thread2-r0drv-darwin.cpp

    r48935 r54358  
    137137
    138138
     139DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
     140{
     141    /** @todo fix RTThreadWait/RTR0Term race on darwin. */
     142    RTThreadSleep(1);
     143}
     144
     145
    139146DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
    140147{
  • trunk/src/VBox/Runtime/r0drv/freebsd/thread2-r0drv-freebsd.c

    r36555 r54358  
    9999
    100100
     101DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
     102{
     103    /** @todo fix RTThreadWait/RTR0Term race on freebsd. */
     104    RTThreadSleep(1);
     105}
     106
     107
    101108DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
    102109{
  • trunk/src/VBox/Runtime/r0drv/haiku/thread2-r0drv-haiku.c

    r43403 r54358  
    4141
    4242
    43 int rtThreadNativeInit(void)
     43DECLHIDDEN(int) rtThreadNativeInit(void)
    4444{
    4545    /* No TLS in Ring-0. :-/ */
     
    5454
    5555
    56 int rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
     56DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
    5757{
    5858    int32 iPriority;
     
    8282
    8383
    84 int rtThreadNativeAdopt(PRTTHREADINT pThread)
     84DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
    8585{
    8686    return VERR_NOT_IMPLEMENTED;
     
    8888
    8989
    90 void rtThreadNativeDestroy(PRTTHREADINT pThread)
     90DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
     91{
     92    /** @todo fix RTThreadWait/RTR0Term race on freebsd. */
     93    RTThreadSleep(1);
     94}
     95
     96
     97DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
    9198{
    9299    NOREF(pThread);
     
    115122
    116123
    117 int rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
     124DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
    118125{
    119126    thread_id NativeThread;
  • trunk/src/VBox/Runtime/r0drv/linux/thread2-r0drv-linux.c

    r48935 r54358  
    103103
    104104
     105DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
     106{
     107    /** @todo fix RTThreadWait/RTR0Term race on linux. */
     108    RTThreadSleep(1); NOREF(pThread);
     109}
     110
     111
    105112DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
    106113{
  • trunk/src/VBox/Runtime/r0drv/nt/thread2-r0drv-nt.cpp

    r48935 r54358  
    8888
    8989
     90DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
     91{
     92    PVOID pvThreadObj = pThread->Core.Key;
     93    NTSTATUS rcNt = KeWaitForSingleObject(pvThreadObj, Executive, KernelMode, FALSE, NULL);
     94    AssertMsg(rcNt == STATUS_SUCCESS, ("rcNt=%#x\n", rcNt));
     95}
     96
     97
    9098DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
    9199{
  • trunk/src/VBox/Runtime/r0drv/os2/thread2-r0drv-os2.cpp

    r48935 r54358  
    6565}
    6666
     67DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
     68{
     69    NOREF(pThread);
     70}
     71
    6772
    6873DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
  • trunk/src/VBox/Runtime/r0drv/solaris/thread2-r0drv-solaris.c

    r52983 r54358  
    8686
    8787
     88DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
     89{
     90    kthread_t *pThread = (kthread_t *)pThread->Core.Key;
     91    thread_join(pThread);
     92}
     93
     94
    8895DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
    8996{
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette