about summary refs log tree commit diff
path: root/sysdeps/x86_64/bits/atomic.h
diff options
context:
space:
mode:
authorTorvald Riegel <triegel@redhat.com>2014-10-29 10:34:36 +0100
committerTorvald Riegel <triegel@redhat.com>2015-06-23 19:20:52 +0200
commitc47ca9647f9b72692e62f94fe468cd5568f49129 (patch)
tree724bfcf502ac32b1117915e731dfad53083cf272 /sysdeps/x86_64/bits/atomic.h
parentb2faf4eadf5e9e9a71abcfe4da71fad91707ccac (diff)
downloadglibc-c47ca9647f9b72692e62f94fe468cd5568f49129.tar.gz
glibc-c47ca9647f9b72692e62f94fe468cd5568f49129.tar.xz
glibc-c47ca9647f9b72692e62f94fe468cd5568f49129.zip
Fix atomic_full_barrier on x86 and x86_64.
This fixes BZ #17403 by defining atomic_full_barrier,
atomic_read_barrier, and atomic_write_barrier on x86 and x86_64.  A full
barrier is implemented through an atomic idempotent modification to the
stack and not through using mfence because the latter can supposedly be
somewhat slower due to having to provide stronger guarantees wrt.
self-modifying code, for example.
Diffstat (limited to 'sysdeps/x86_64/bits/atomic.h')
-rw-r--r--sysdeps/x86_64/bits/atomic.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/sysdeps/x86_64/bits/atomic.h b/sysdeps/x86_64/bits/atomic.h
index 5d08146cd7..203d92c20d 100644
--- a/sysdeps/x86_64/bits/atomic.h
+++ b/sysdeps/x86_64/bits/atomic.h
@@ -472,3 +472,10 @@ typedef uintmax_t uatomic_max_t;
 #define atomic_or(mem, mask) __arch_or_body (LOCK_PREFIX, mem, mask)
 
 #define catomic_or(mem, mask) __arch_or_body (__arch_cprefix, mem, mask)
+
+/* We don't use mfence because it is supposedly slower due to having to
+   provide stronger guarantees (e.g., regarding self-modifying code).  */
+#define atomic_full_barrier() \
+    __asm __volatile (LOCK_PREFIX "orl $0, (%%rsp)" ::: "memory")
+#define atomic_read_barrier() __asm ("" ::: "memory")
+#define atomic_write_barrier() __asm ("" ::: "memory")