From: Oliver Kurth Date: Wed, 16 Jan 2019 22:53:03 +0000 (-0800) Subject: Changes to common header files not directly appilcable to open-vm-tools. X-Git-Tag: stable-11.0.0~266 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e74e440279d402c5d81a1b6f75e0760d91c4eb88;p=thirdparty%2Fopen-vm-tools.git Changes to common header files not directly appilcable to open-vm-tools. --- diff --git a/open-vm-tools/lib/include/vm_atomic.h b/open-vm-tools/lib/include/vm_atomic.h index 8bcb77404..be25e8c6d 100644 --- a/open-vm-tools/lib/include/vm_atomic.h +++ b/open-vm-tools/lib/include/vm_atomic.h @@ -2303,7 +2303,10 @@ Atomic_ReadAdd64(Atomic_uint64 *var, // IN/OUT * * Atomic_ReadSub64 -- * - * Atomically subtracts a 64-bit integer to another + * Atomically subtracts a 64-bit integer from another. + * + * Note: It is expected that val <= var. If untrue, the result + * cannot be represented in an unsigned type. * * Results: * Returns the old value just prior to the subtraction @@ -2321,7 +2324,7 @@ Atomic_ReadSub64(Atomic_uint64 *var, // IN/OUT #if defined VM_ARM_64 return _VMATOM_X(ROP, 64, TRUE, &var->value, sub, val); #else - return Atomic_ReadAdd64(var, -(int64)val); + return Atomic_ReadAdd64(var, (uint64)-(int64)val); #endif } @@ -3618,7 +3621,7 @@ Atomic_ReadInc16(Atomic_uint16 *var) // IN/OUT static INLINE uint16 Atomic_ReadDec16(Atomic_uint16 *var) // IN/OUT { - return Atomic_ReadAdd16(var, -1); + return Atomic_ReadAdd16(var, (uint16)-1); } #endif diff --git a/open-vm-tools/lib/include/vm_basic_asm.h b/open-vm-tools/lib/include/vm_basic_asm.h index 51d26d3cf..d15048dcf 100644 --- a/open-vm-tools/lib/include/vm_basic_asm.h +++ b/open-vm-tools/lib/include/vm_basic_asm.h @@ -235,8 +235,9 @@ mssb64_0(const uint64 value) #endif static INLINE int -lssb32_0(uint32 value) +lssb32_0(uint32 v) { + int value = (int)v; #ifdef USE_ARCH_X86_CUSTOM if (!__builtin_constant_p(value)) { if (UNLIKELY(value == 0)) { @@ -276,8 +277,10 @@ mssb32_0(uint32 value) } static INLINE int -lssb64_0(const uint64 value) +lssb64_0(const uint64 v) { + int64 value = (int64)v; + #ifdef USE_ARCH_X86_CUSTOM if (!__builtin_constant_p(value)) { if (UNLIKELY(value == 0)) { @@ -1184,7 +1187,9 @@ RoundUpPow2C32(uint32 value) if (value <= 1 || value > (1U << 31)) { return 1; // Match the assembly's undefined value for large inputs. } else { - return (2 << mssb32_0(value - 1)); + int mssb32 = mssb32_0(value - 1); + /* invariant: mssb32 >= 0 */ + return (2U << (uint32)mssb32); } }