978e96
Port sysdeps/unix/sysv/linux/i386/tst-bz21269.c to __atomic builtins
978e96
978e96
The upstream test uses <stdatomic.h>, which is not supported in the
978e96
Red Hat Enterprise Linux 7 system compiler.
978e96
978e96
The port uses __ATOMIC_SEQ_CST for consistency with the upstream test;
978e96
such as trong memory ordering is not actually required here.
978e96
978e96
Furthermore, it is necessary to change the SYS_ system call constants
978e96
to __NR_ constants.  Downstream builts the test with internal headers,
978e96
and those only have the __NR_ constants from the kernel.
978e96
978e96
The initializer of sa in xsethandler was replaced with a memset, to
978e96
avoid a warning about missing braces in an initializer (something that
978e96
later GCC versions do not warn about).
978e96
978e96
diff --git a/sysdeps/unix/sysv/linux/i386/tst-bz21269.c b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
978e96
index 6ee3fc62be0d3312..f58395cedc6972c4 100644
978e96
--- a/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
978e96
+++ b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
978e96
@@ -26,8 +26,6 @@
978e96
    - Replicate only the test required to trigger the issue for the
978e96
      BZ#21269.  */
978e96
 
978e96
-#include <stdatomic.h>
978e96
-
978e96
 #include <asm/ldt.h>
978e96
 #include <linux/futex.h>
978e96
 
978e96
@@ -36,6 +34,7 @@
978e96
 #include <errno.h>
978e96
 #include <sys/syscall.h>
978e96
 #include <sys/mman.h>
978e96
+#include <string.h>
978e96
 
978e96
 #include <support/xunistd.h>
978e96
 #include <support/check.h>
978e96
@@ -44,7 +43,7 @@
978e96
 static int
978e96
 xset_thread_area (struct user_desc *u_info)
978e96
 {
978e96
-  long ret = syscall (SYS_set_thread_area, u_info);
978e96
+  long ret = syscall (__NR_set_thread_area, u_info);
978e96
   TEST_VERIFY_EXIT (ret == 0);
978e96
   return ret;
978e96
 }
978e96
@@ -52,20 +51,21 @@ xset_thread_area (struct user_desc *u_info)
978e96
 static void
978e96
 xmodify_ldt (int func, const void *ptr, unsigned long bytecount)
978e96
 {
978e96
-  TEST_VERIFY_EXIT (syscall (SYS_modify_ldt, 1, ptr, bytecount) == 0);
978e96
+  TEST_VERIFY_EXIT (syscall (__NR_modify_ldt, 1, ptr, bytecount) == 0);
978e96
 }
978e96
 
978e96
 static int
978e96
 futex (int *uaddr, int futex_op, int val, void *timeout, int *uaddr2,
978e96
 	int val3)
978e96
 {
978e96
-  return syscall (SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
978e96
+  return syscall (__NR_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
978e96
 }
978e96
 
978e96
 static void
978e96
 xsethandler (int sig, void (*handler)(int, siginfo_t *, void *), int flags)
978e96
 {
978e96
-  struct sigaction sa = { 0 };
978e96
+  struct sigaction sa;
978e96
+  memset (&sa, 0, sizeof (sa));
978e96
   sa.sa_sigaction = handler;
978e96
   sa.sa_flags = SA_SIGINFO | flags;
978e96
   TEST_VERIFY_EXIT (sigemptyset (&sa.sa_mask) == 0);
978e96
@@ -128,7 +128,7 @@ setup_low_user_desc (void)
978e96
    1: thread armed.
978e96
    2: thread should clear LDT entry 0.
978e96
    3: thread should exit.  */
978e96
-static atomic_uint ftx;
978e96
+static unsigned int ftx;
978e96
 
978e96
 static void *
978e96
 threadproc (void *ctx)
978e96
@@ -136,9 +136,9 @@ threadproc (void *ctx)
978e96
   while (1)
978e96
     {
978e96
       futex ((int *) &ftx, FUTEX_WAIT, 1, NULL, NULL, 0);
978e96
-      while (atomic_load (&ftx) != 2)
978e96
+      while (__atomic_load_n (&ftx, __ATOMIC_SEQ_CST) != 2)
978e96
 	{
978e96
-	  if (atomic_load (&ftx) >= 3)
978e96
+	  if (__atomic_load_n (&ftx, __ATOMIC_SEQ_CST) >= 3)
978e96
 	    return NULL;
978e96
 	}
978e96
 
978e96
@@ -147,7 +147,7 @@ threadproc (void *ctx)
978e96
       xmodify_ldt (1, &desc, sizeof (desc));
978e96
 
978e96
       /* If ftx == 2, set it to zero,  If ftx == 100, quit.  */
978e96
-      if (atomic_fetch_add (&ftx, -2) != 2)
978e96
+      if (__atomic_fetch_add (&ftx, -2, __ATOMIC_SEQ_CST) != 2)
978e96
 	return NULL;
978e96
     }
978e96
 }
978e96
@@ -190,7 +190,7 @@ do_test (void)
978e96
 	continue;
978e96
 
978e96
       /* Make sure the thread is ready after the last test. */
978e96
-      while (atomic_load (&ftx) != 0)
978e96
+      while (__atomic_load_n (&ftx, __ATOMIC_SEQ_CST) != 0)
978e96
 	;
978e96
 
978e96
       struct user_desc desc = {
978e96
@@ -214,9 +214,9 @@ do_test (void)
978e96
       asm volatile ("mov %0, %%ss" : : "r" (0x7));
978e96
 
978e96
       /* Fire up thread modify_ldt call.  */
978e96
-      atomic_store (&ftx, 2);
978e96
+      __atomic_store_n (&ftx, 2, __ATOMIC_SEQ_CST);
978e96
 
978e96
-      while (atomic_load (&ftx) != 0)
978e96
+      while (__atomic_load_n (&ftx, __ATOMIC_SEQ_CST) != 0)
978e96
 	;
978e96
 
978e96
       /* On success, modify_ldt will segfault us synchronously and we will
978e96
@@ -224,7 +224,7 @@ do_test (void)
978e96
       support_record_failure ();
978e96
     }
978e96
 
978e96
-  atomic_store (&ftx, 100);
978e96
+  __atomic_store_n (&ftx, 100, __ATOMIC_SEQ_CST);
978e96
   futex ((int*) &ftx, FUTEX_WAKE, 0, NULL, NULL, 0);
978e96
 
978e96
   xpthread_join (thread);