]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/lock: put the syndrome bits back
authorVMware, Inc <>
Mon, 21 Nov 2011 23:02:49 +0000 (15:02 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 21 Nov 2011 23:02:49 +0000 (15:02 -0800)
Took them out because the old way of doing things broke the
tools build. This way works just as well, is simpler and easier
to understand.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/lock/ul.c

index 0ef4e813ddbc3ea2f50e636be5d96e01b7233cd7..59d68a48800bbec9f8c9ab467c4a75efecc8482f 100644 (file)
@@ -23,7 +23,6 @@
 #include "ulInt.h"
 #include "ulIntShared.h"
 #include "hashTable.h"
-#include "random.h"
 #include "hostinfo.h"
 
 
@@ -123,26 +122,32 @@ MXUserSyndrome(void)
    syndrome = Atomic_Read(&syndromeMem);
 
    if (syndrome == 0) {
+       void *token;
+
        /*
-        * Use the cryto quality source of bytes. This comes from the
-        * host system. Should take somehow fail use the host's uptime
+        * It is extremely rare for malloc/calloc to be diverted into multiple
+        * heaps or to fail in our environment - one heap per program; addresses
+        * must be unique. Attempt a small allocation and use its address for
+        * the syndrome bits.
+        *
+        * This is an intentional "leak" albeit only once per program (or
+        * copy of MXUser).
         */
 
-       do {
-          if (!Random_Crypto(sizeof(syndrome), &syndrome)) {
-//             syndrome = Hostinfo_SystemUpTime() & 0xFFFFFFFF;
-             syndrome = 1;  // work around tools build
-          }
-       } while (syndrome == 0);  // syndrome bits must be non-zero
+       token = malloc(4);
 
-       /*
-        * Attempt to update the syndrome value with the computed value using
-        * a blind conditional write. One thread or another will have updated
-        * the value.
-        */
+       syndrome = ((uintptr_t) token) & 0xFFFFFFFF;
+
+       if (UNLIKELY(syndrome == 0)) {
+          syndrome++;  // live with the exceedingly rare outcome
+       }
+
+       if (Atomic_ReadIfEqualWrite(&syndromeMem, 0, syndrome)) {
+          free(token);
+       }
 
-       Atomic_ReadIfEqualWrite(&syndromeMem, 0, syndrome);
        syndrome = Atomic_Read(&syndromeMem);
+       ASSERT(syndrome);
    }
 
    return syndrome;