8234509: Race in macOS os::processor_id()
authoreosterlund
Mon, 25 Nov 2019 09:10:41 +0000
changeset 59242 6ba3d8d41135
parent 59241 23ecaf949f8f
child 59243 fb1d9bf1be2b
8234509: Race in macOS os::processor_id() Reviewed-by: dholmes, pliden, rehn
src/hotspot/os/bsd/os_bsd.cpp
--- a/src/hotspot/os/bsd/os_bsd.cpp	Mon Nov 25 08:11:24 2019 +0100
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Mon Nov 25 09:10:41 2019 +0000
@@ -3264,12 +3264,14 @@
   int processor_id = Atomic::load(&mapping[apic_id]);
 
   while (processor_id < 0) {
-    if (Atomic::cmpxchg(-2, &mapping[apic_id], -1)) {
+    if (Atomic::cmpxchg(-2, &mapping[apic_id], -1) == -1) {
       Atomic::store(Atomic::add(1, &next_processor_id) - 1, &mapping[apic_id]);
     }
     processor_id = Atomic::load(&mapping[apic_id]);
   }
 
+  assert(processor_id >= 0 && processor_id < os::processor_count(), "invalid processor id");
+
   return (uint)processor_id;
 }
 #endif