]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Revert a previous change.
authorVMware, Inc <>
Mon, 21 Nov 2011 23:23:47 +0000 (15:23 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 21 Nov 2011 23:23:47 +0000 (15:23 -0800)
Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/lock/ul.c
open-vm-tools/lib/lock/ulBarrier.c
open-vm-tools/lib/lock/ulExcl.c
open-vm-tools/lib/lock/ulInt.h
open-vm-tools/lib/lock/ulRW.c
open-vm-tools/lib/lock/ulRec.c
open-vm-tools/lib/lock/ulSema.c

index 1c43850ceca52a6e184833aba539994319ce4a0c..bdbe824fdbebb3bfd141f41eac2688d3d5597aa3 100644 (file)
@@ -23,8 +23,6 @@
 #include "ulInt.h"
 #include "ulIntShared.h"
 #include "hashTable.h"
-#include "random.h"
-#include "hostinfo.h"
 
 
 static Bool mxInPanic = FALSE;  // track when involved in a panic
@@ -87,67 +85,6 @@ MXUserInternalSingleton(Atomic_Ptr *storage)  // IN:
 }
 
 
-/*
- *-----------------------------------------------------------------------------
- *
- * MXUserSydrome --
- *
- *      Generate the syndrome bits for this MXUser library.
- *
- *      Each MXUser library has unique syndrome bits enabling the run time
- *      detection of locks created with one copy of the MXUser library and
- *      passed to another copy of the MXUser library.
- *
- *      The syndrome bits are important as they prevent incompatible versions
- *      of the MXUser library from trashing each other.
- *
- *      The bits are generated by using a source of bits that is external to
- *      a program and its libraries. This way no code or data based scheme
- *      can be spoofed or aliased.
- *
- * Results:
- *      As above
- *
- * Side effects:
- *      None
- *
- *-----------------------------------------------------------------------------
- */
-
-static uint32
-MXUserSyndrome(void)
-{
-   uint32 syndrome;
-   static Atomic_uint32 syndromeMem;  // implicitly zero -- mbellon
-
-   syndrome = Atomic_Read(&syndromeMem);
-
-   if (syndrome == 0) {
-       /*
-        * Use the cryto quality source of bytes. This comes from the
-        * host system. Should take somehow fail use the host's uptime
-        */
-
-       do {
-          if (!Random_Crypto(sizeof(syndrome), &syndrome)) {
-             syndrome = Hostinfo_SystemUpTime() & 0xFFFFFFFF;
-          }
-       } while (syndrome == 0);  // syndrome bits must be non-zero
-
-       /*
-        * Attempt to update the syndrome value with the computed value using
-        * a blind conditional write. One thread or another will have updated
-        * the value.
-        */
-
-       Atomic_ReadIfEqualWrite(&syndromeMem, 0, syndrome);
-       syndrome = Atomic_Read(&syndromeMem);
-   }
-
-   return syndrome;
-}
-
-
 #if defined(MXUSER_DEBUG)
 #define MXUSER_MAX_LOCKS_PER_THREAD (2 * MXUSER_MAX_REC_DEPTH)
 
@@ -158,10 +95,6 @@ typedef struct {
 
 static Atomic_Ptr hashTableMem;
 
-#if defined(_WIN32) && !defined(VMX86_VMX)
-static Atomic_Ptr hashLockMem;
-#endif
-
 
 /*
  *-----------------------------------------------------------------------------
@@ -191,18 +124,8 @@ MXUserGetPerThread(void *tid,      // IN: thread ID
    HashTable *hash;
    MXUserPerThread *perThread = NULL;
 
-#if defined(_WIN32) && !defined(VMX86_VMX)
-   MXRecLock *hashLock = MXUserInternalSingleton(&hashLockMem);
-
-   ASSERT(hashLock);
-
-   hash = HashTable_AllocOnce(&hashTableMem, 1024, HASH_INT_KEY, NULL);
-
-   MXRecLockAcquire(hashLock);
-#else
    hash = HashTable_AllocOnce(&hashTableMem, 1024,
                               HASH_INT_KEY | HASH_FLAG_ATOMIC, NULL);
-#endif
 
    if (!HashTable_Lookup(hash, tid, (void **) &perThread)) {
       /* No entry for this tid was found, allocate one? */
@@ -228,10 +151,6 @@ MXUserGetPerThread(void *tid,      // IN: thread ID
       }
    }
 
-#if defined(_WIN32) && !defined(VMX86_VMX)
-   MXRecLockRelease(hashLock);
-#endif
-
    return perThread;
 }
 
@@ -513,34 +432,6 @@ MXUserReleaseTracking(MXUserHeader *header)  // IN: lock, via its header
 
    perThread->lockArray[lastEntry] = NULL;  // tidy up memory
    perThread->locksHeld--;
-
-#if defined(_WIN32) && !defined(VMX86_VMX)
-   /*
-    * On Windows thread IDs aren't greedily recycled. If a process creates and
-    * destroys many threads this can cause a memory leak of perThread data
-    * (and its overhead). We avoid this by atomically (via a lock) creating
-    * (upon first lock acquired) and deleting (upon last lock release) a
-    * perThread.
-    *
-    * Yes, this is a performance cost but it only affects Windows debug
-    * builds and then not by very much - we tend to run for a long time
-    * with either no locks held or at least one lock held.
-    */
-
-   if (perThread->locksHeld == 0) {
-      HashTable *hash = Atomic_ReadPtr(&hashTableMem);
-      MXRecLock *hashLock = MXUserInternalSingleton(&hashLockMem);
-
-      ASSERT(hash);
-      ASSERT(hashLock);
-
-      MXRecLockAcquire(hashLock);
-      HashTable_Delete(hash, tid);
-      MXRecLockRelease(hashLock);
-
-      free(perThread);
-   }
-#endif
 }
 
 
@@ -591,17 +482,9 @@ void
 MXUserValidateSignature(MXUserHeader *header,  // IN:
                         uint32 salt)           // IN:
 {
-   uint32 syndrome = MXUserSyndrome();
-
-   ASSERT(header);
-
-   if ((header->signature[0] != syndrome) ||
-       (header->signature[1] != salt)) {
-      MXUserDumpAndPanic(header, "%s: expected (%X, %X) observed (%X, %X)\n",
-                         __FUNCTION__,
-                         syndrome, salt,
-                         header->signature[0],
-                         header->signature[1]);
+   if (header->signature != salt) {
+      MXUserDumpAndPanic(header, "%s: expected %X observed %X\n", __FUNCTION__,
+                         salt, header->signature);
    }
 }
 #endif
@@ -642,8 +525,11 @@ MXUserSetSignature(MXUserHeader *header,  // IN/OUT:
 {
    ASSERT(header);
 
-   header->signature[0] = MXUserSyndrome();
-   header->signature[1] = salt;
+#if defined(MXUSER_DEBUG)
+   header->signature = salt;  // TODO: use salt + time: make runtime unique
+#else
+   header->signature = salt;
+#endif
 }
 
 
@@ -666,10 +552,7 @@ MXUserSetSignature(MXUserHeader *header,  // IN/OUT:
 void
 MXUserClearSignature(MXUserHeader *header)  // IN/OUT:
 {
-   ASSERT(header);
-
-   header->signature[0] = 0;
-   header->signature[1] = 0;
+   header->signature = 0;
 }
 
 
index aaffda01ae758299e86644c3f7b5890ce7948b68..22d4cb2e45bd227cb56c2373885afb33621f4a75 100644 (file)
@@ -66,8 +66,7 @@ MXUserDumpBarrier(MXUserHeader *header)  // IN:
 
    Warning("%s: Barrier @ 0x%p\n", __FUNCTION__, barrier);
 
-   Warning("\tsignature (0x%X, 0x%X)\n", barrier->header.signature[0],
-           barrier->header.signature[1]);
+   Warning("\tsignature 0x%X\n", barrier->header.signature);
    Warning("\tname %s\n", barrier->header.name);
    Warning("\trank 0x%X\n", barrier->header.rank);
    Warning("\tserial number %u\n", barrier->header.serialNumber);
@@ -199,14 +198,13 @@ MXUser_DestroyBarrier(MXUserBarrier *barrier)  // IN:
                             __FUNCTION__);
       }
 
-      MXUserClearSignature(&barrier->header);  // just in case...
-
       MXUserRemoveFromList(&barrier->header);
 
       MXUser_DestroyCondVar(barrier->contexts[0].condVar);
       MXUser_DestroyCondVar(barrier->contexts[1].condVar);
       MXUser_DestroyExclLock(barrier->lock);
 
+      MXUserClearSignature(&barrier->header);  // just in case...
       free(barrier->header.name);
       barrier->header.name = NULL;
       free(barrier);
index 32406f5b61edb45e0eb1809a767f785b9fdd1179..143c9bfec97b4a32b558c444aea5f9630a3b6c6c 100644 (file)
@@ -138,19 +138,16 @@ MXUserDumpExclLock(MXUserHeader *header)  // IN:
 
    Warning("%s: Exclusive lock @ 0x%p\n", __FUNCTION__, lock);
 
-   Warning("\tsignature (0x%X, 0x%X)\n", lock->header.signature[0],
-           lock->header.signature[1]);
+   Warning("\tsignature 0x%X\n", lock->header.signature);
    Warning("\tname %s\n", lock->header.name);
    Warning("\trank 0x%X\n", lock->header.rank);
    Warning("\tserial number %u\n", lock->header.serialNumber);
 
-   Warning("\tdepth count %u\n", MXRecLockCount(&lock->recursiveLock));
+   Warning("\tcount %u\n", lock->recursiveLock.referenceCount);
 
-   Warning("\taddress of native owner data 0x%p\n",
+   Warning("\taddress of owner data 0x%p\n",
            &lock->recursiveLock.nativeThreadID);
 
-   Warning("\towner 0x%u\n", lock->recursiveLock.vmwThreadID);
-
    if (stats && (stats->holder != NULL)) {
       Warning("\tholder %p\n", stats->holder);
    }
@@ -355,8 +352,6 @@ MXUser_DestroyExclLock(MXUserExclLock *lock)  // IN:
                             __FUNCTION__);
       }
 
-      MXUserClearSignature(&lock->header);  // just in case...
-
       MXRecLockDestroy(&lock->recursiveLock);
 
       MXUserRemoveFromList(&lock->header);
@@ -372,6 +367,7 @@ MXUser_DestroyExclLock(MXUserExclLock *lock)  // IN:
          free(stats);
       }
 
+      MXUserClearSignature(&lock->header);  // just in case...
       free(lock->header.name);
       lock->header.name = NULL;
       free(lock);
index c1e481f8bb503d9abda9a68beaa26800bf68c465..1294f790cd78ba1a88d39b0530fbf10f5261c847 100644 (file)
@@ -57,9 +57,8 @@ typedef struct {
    pthread_mutex_t  nativeLock;       // Native lock object
 #endif
 
-   int              depthCount;       // Acquisition count
+   int              referenceCount;   // Acquisition count
    MXUserThreadID   nativeThreadID;   // Native thread ID
-   VThreadID        vmwThreadID;      // VMW thread ID
 } MXRecLock;
 
 
@@ -124,7 +123,6 @@ static INLINE void
 MXRecLockSetNoOwner(MXRecLock *lock)  // IN:
 {
    lock->nativeThreadID = MXUSER_INVALID_OWNER;
-   lock->vmwThreadID = VTHREAD_INVALID_ID;
 }
 
 
@@ -132,7 +130,6 @@ static INLINE void
 MXRecLockSetOwner(MXRecLock *lock)  // IN/OUT:
 {
    lock->nativeThreadID = GetCurrentThreadId();
-   lock->vmwThreadID = VThread_CurID();
 }
 
 
@@ -186,7 +183,6 @@ MXRecLockSetNoOwner(MXRecLock *lock)  // IN/OUT:
 {
    /* a hack but it works portably */
    memset((void *) &lock->nativeThreadID, 0xFF, sizeof(lock->nativeThreadID));
-   lock->vmwThreadID = VTHREAD_INVALID_ID;
 }
 
 
@@ -194,7 +190,6 @@ static INLINE void
 MXRecLockSetOwner(MXRecLock *lock)  // IN:
 {
    lock->nativeThreadID = pthread_self();
-   lock->vmwThreadID = VThread_CurID();
 }
 
 
@@ -228,7 +223,7 @@ MXRecLockInit(MXRecLock *lock)  // IN/OUT:
    if (success) {
       MXRecLockSetNoOwner(lock);
 
-      lock->depthCount = 0;
+      lock->referenceCount = 0;
    }
 
    return success;
@@ -249,7 +244,7 @@ MXRecLockDestroy(MXRecLock *lock)  // IN/OUT:
 static INLINE uint32
 MXRecLockCount(const MXRecLock *lock)  // IN:
 {
-   return lock->depthCount;
+   return lock->referenceCount;
 }
 
 
@@ -261,7 +256,7 @@ MXRecLockIncCount(MXRecLock *lock,  // IN/OUT:
       MXRecLockSetOwner(lock);
    }
 
-   lock->depthCount += count;
+   lock->referenceCount += count;
 }
 
 
@@ -295,7 +290,7 @@ MXRecLockAcquire(MXRecLock *lock)  // IN/OUT:
                err);
       }
 
-      ASSERT(lock->depthCount == 0);
+      ASSERT(lock->referenceCount == 0);
    }
 
    MXRecLockIncCount(lock, 1);
@@ -340,8 +335,8 @@ static INLINE void
 MXRecLockDecCount(MXRecLock *lock,  // IN/OUT:
                   uint32 count)     // IN:
 {
-   ASSERT(count <= lock->depthCount);
-   lock->depthCount -= count;
+   ASSERT(count <= lock->referenceCount);
+   lock->referenceCount -= count;
 
    if (MXRecLockCount(lock) == 0) {
       MXRecLockSetNoOwner(lock);
@@ -393,22 +388,7 @@ MXRecLockRelease(MXRecLock *lock)  // IN/OUT:
 static INLINE void *
 MXUserGetThreadID(void)
 {
-#if defined(_WIN32)
-   /*
-    * On Windows there is a problem with using VThread_CurID() - it doesn't
-    * maintain unique thread ID values (PR 780775). Native thread ID values
-    * and special handling are used to resolve issues.
-    */
-
-   return (void *) (uintptr_t) GetCurrentThreadId();  // DWORD
-#else
-   /*
-    * Outside of Windows there are no known issues with using VThread_CurID
-    * so that is what is used.
-    */
-
    return (void *) (uintptr_t) VThread_CurID();  // unsigned
-#endif
 }
 
 
@@ -417,13 +397,13 @@ MXUserGetThreadID(void)
  */
 
 typedef struct MXUserHeader {
-   uint32       signature[2];
+   uint32       signature;
    char        *name;
+   MX_Rank      rank;
+   uint32       serialNumber;
    void       (*dumpFunc)(struct MXUserHeader *);
    void       (*statsFunc)(struct MXUserHeader *);
    ListItem     item;
-   uint32       serialNumber;
-   MX_Rank      rank;
 } MXUserHeader;
 
 
index 810ff57effb5d6a8826206c5a2f6645b5f323081..4790f966f9486d24c0ed4b323449322682be1eee 100644 (file)
@@ -364,8 +364,7 @@ MXUserDumpRWLock(MXUserHeader *header)  // IN:
 
    Warning("%s: Read-write lock @ 0x%p\n", __FUNCTION__, lock);
 
-   Warning("\tsignature (0x%X, 0x%X)\n", lock->header.signature[0],
-           lock->header.signature[1]);
+   Warning("\tsignature 0x%X\n", lock->header.signature);
    Warning("\tname %s\n", lock->header.name);
    Warning("\trank 0x%X\n", lock->header.rank);
    Warning("\tserial number %u\n", lock->header.serialNumber);
@@ -373,7 +372,7 @@ MXUserDumpRWLock(MXUserHeader *header)  // IN:
    if (LIKELY(lock->useNative)) {
       Warning("\tnativeLock 0x%p\n", &lock->nativeLock);
    } else {
-      Warning("\tdepth count %u\n", MXRecLockCount(&lock->recursiveLock));
+      Warning("\tcount %u\n", lock->recursiveLock.referenceCount);
    }
 
    Warning("\tholderCount %d\n", Atomic_Read(&lock->holderCount));
@@ -605,8 +604,6 @@ MXUser_DestroyRWLock(MXUserRWLock *lock)  // IN:
                             __FUNCTION__);
       }
 
-      MXUserClearSignature(&lock->header);  // just in case...
-
       if (LIKELY(lock->useNative)) {
          int err = MXUserNativeRWDestroy(&lock->nativeLock);
 
@@ -632,6 +629,7 @@ MXUser_DestroyRWLock(MXUserRWLock *lock)  // IN:
       }
 
       HashTable_FreeUnsafe(lock->holderTable);
+      MXUserClearSignature(&lock->header);  // just in case...
       free(lock->header.name);
       lock->header.name = NULL;
       free(lock);
index d4c87a4e1ac2efa211c51c2e151c8b376b70be20..4c0396927f781d1f6ec71a2ce2628ffdda212584 100644 (file)
@@ -151,24 +151,20 @@ MXUserDumpRecLock(MXUserHeader *header)  // IN:
 
    Warning("%s: Recursive lock @ 0x%p\n", __FUNCTION__, lock);
 
-   Warning("\tsignature (0x%X, 0x%X)\n", lock->header.signature[0],
-           lock->header.signature[1]);
+   Warning("\tsignature 0x%X\n", lock->header.signature);
    Warning("\tname %s\n", lock->header.name);
    Warning("\trank 0x%X\n", lock->header.rank);
    Warning("\tserial number %u\n", lock->header.serialNumber);
-
    Warning("\treference count %u\n", Atomic_Read(&lock->refCount));
 
    if (lock->vmmLock == NULL) {
       MXUserStats *stats = (MXUserStats *) Atomic_ReadPtr(&lock->statsMem);
 
-      Warning("\tdepth count %u\n", MXRecLockCount(&lock->recursiveLock));
+      Warning("\tcount %u\n", lock->recursiveLock.referenceCount);
 
-      Warning("\taddress of native owner data 0x%p\n",
+      Warning("\taddress of owner data 0x%p\n",
               &lock->recursiveLock.nativeThreadID);
 
-      Warning("\towner 0x%u\n", lock->recursiveLock.vmwThreadID);
-
       if (stats && (stats->holder != NULL)) {
          Warning("\tholder %p\n", stats->holder);
       }
@@ -441,8 +437,6 @@ MXUserCondDestroyRecLock(MXUserRecLock *lock)  // IN:
    MXUserValidateSignature(&lock->header, MXUSER_REC_SIGNATURE);
 
    if (Atomic_FetchAndDec(&lock->refCount) == 1) {
-      MXUserClearSignature(&lock->header);  // just in case...
-
       if (lock->vmmLock == NULL) {
          MXUserStats *stats;
 
@@ -468,6 +462,7 @@ MXUserCondDestroyRecLock(MXUserRecLock *lock)  // IN:
          }
       }
 
+      MXUserClearSignature(&lock->header);  // just in case...
       free(lock->header.name);
       lock->header.name = NULL;
       free(lock);
index 6d6c03f4cdb4d12210ce782898220e5dacede650..eb48f714c0e0aca37c211520fb18edd35c4b9ee7 100644 (file)
@@ -467,9 +467,7 @@ MXUserDumpSemaphore(MXUserHeader *header)  // IN:
 
    Warning("%s: semaphore @ 0x%p\n", __FUNCTION__, sema);
 
-   Warning("\tsignature (0x%X, 0x%X)\n", sema->header.signature[0],
-           sema->header.signature[1]);
-
+   Warning("\tsignature 0x%X\n", sema->header.signature);
    Warning("\tname %s\n", sema->header.name);
    Warning("\trank 0x%X\n", sema->header.rank);
    Warning("\tserial number %u\n", sema->header.serialNumber);
@@ -578,8 +576,6 @@ MXUser_DestroySemaphore(MXUserSemaphore *sema)  // IN:
                             __FUNCTION__);
       }
 
-      MXUserClearSignature(&sema->header);  // just in case...
-
       err = MXUserDestroy(&sema->nativeSemaphore);
 
       if (UNLIKELY(err != 0)) {
@@ -598,6 +594,7 @@ MXUser_DestroySemaphore(MXUserSemaphore *sema)  // IN:
          free(stats);
       }
 
+      MXUserClearSignature(&sema->header);  // just in case...
       free(sema->header.name);
       sema->header.name = NULL;
       free(sema);