Bug 1480732 - make ipc/'s atomicops.h work on aarch64 windows; r=jld
authorNathan Froyd <froydnj@mozilla.com>
Mon, 27 Aug 2018 09:31:28 -0400
changeset 488629 dfa6c9b695146cfa7e29c58f1762389419db7738
parent 488628 389b7c456a910ba9f035c451a0cfca1b6378c49d
child 488630 409efae1c7f25ea10da7c55a7d1e0fbba1b43c6f
push id9734
push usershindli@mozilla.com
push dateThu, 30 Aug 2018 12:18:07 +0000
treeherdermozilla-beta@71c71ab3afae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjld
bugs1480732
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1480732 - make ipc/'s atomicops.h work on aarch64 windows; r=jld I'm not entirely sure how this works on x86-64 Windows, which also uses a #define for MemoryBarrier...I think something about intrinsics.
ipc/chromium/src/base/atomicops.h
ipc/chromium/src/base/atomicops_internals_x86_msvc.h
--- a/ipc/chromium/src/base/atomicops.h
+++ b/ipc/chromium/src/base/atomicops.h
@@ -93,16 +93,30 @@ Atomic32 Barrier_AtomicIncrement(volatil
 // access.
 Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
                                 Atomic32 old_value,
                                 Atomic32 new_value);
 Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
                                 Atomic32 old_value,
                                 Atomic32 new_value);
 
+// On AArch64 Windows, MemoryBarrier is defined as:
+//
+// #define MemoryBarrier()             __dmb(_ARM_BARRIER_SY)
+//
+// which wreaks havoc with the declaration below.  Capture the definition
+// before undefining the macro.
+#if defined(_M_ARM64) && defined(MemoryBarrier)
+static inline void
+MemoryBarrierARM64()
+{
+  MemoryBarrier();
+}
+#undef MemoryBarrier
+#endif
 void MemoryBarrier();
 void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value);
 void Acquire_Store(volatile Atomic32* ptr, Atomic32 value);
 void Release_Store(volatile Atomic32* ptr, Atomic32 value);
 
 Atomic32 NoBarrier_Load(volatile const Atomic32* ptr);
 Atomic32 Acquire_Load(volatile const Atomic32* ptr);
 Atomic32 Release_Load(volatile const Atomic32* ptr);
@@ -131,16 +145,19 @@ Atomic64 Release_Load(volatile const Ato
 #endif  // CPU_ARCH_64_BITS
 
 }  // namespace base::subtle
 }  // namespace base
 
 // Include our platform specific implementation.
 #if defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY)
 #include "base/atomicops_internals_x86_msvc.h"
+#elif defined(OS_WIN) && defined(ARCH_CPU_AARCH64_FAMILY)
+// Works just fine, separate case in case we need to change things.
+#include "base/atomicops_internals_x86_msvc.h"
 #elif defined(OS_MACOSX) && defined(ARCH_CPU_X86_FAMILY)
 #include "base/atomicops_internals_x86_macosx.h"
 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_X86_FAMILY)
 #include "base/atomicops_internals_x86_gcc.h"
 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_ARMEL)
 #include "base/atomicops_internals_arm_gcc.h"
 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_ARM64)
 #include "base/atomicops_internals_arm64_gcc.h"
--- a/ipc/chromium/src/base/atomicops_internals_x86_msvc.h
+++ b/ipc/chromium/src/base/atomicops_internals_x86_msvc.h
@@ -40,18 +40,23 @@ inline Atomic32 Barrier_AtomicIncrement(
 }
 
 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
                                           Atomic32 increment) {
   return Barrier_AtomicIncrement(ptr, increment);
 }
 
 inline void MemoryBarrier() {
-  // We use MemoryBarrier from WinNT.h
+  // We use MemoryBarrier from WinNT.h, except for AArch64.
+  // See the comment in atomicops.h.
+#if defined(_M_ARM64)
+  MemoryBarrierARM64();
+#else
   ::MemoryBarrier();
+#endif
 }
 
 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
                                        Atomic32 old_value,
                                        Atomic32 new_value) {
   return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
 }