708e55
commit c901c3e764d7c7079f006b4e21e877d5036eb4f5
708e55
Author: Florian Weimer <fweimer@redhat.com>
708e55
Date:   Thu Dec 9 09:49:32 2021 +0100
708e55
708e55
    nptl: Add public rseq symbols and <sys/rseq.h>
708e55
    
708e55
    The relationship between the thread pointer and the rseq area
708e55
    is made explicit.  The constant offset can be used by JIT compilers
708e55
    to optimize rseq access (e.g., for really fast sched_getcpu).
708e55
    
708e55
    Extensibility is provided through __rseq_size and __rseq_flags.
708e55
    (In the future, the kernel could request a different rseq size
708e55
    via the auxiliary vector.)
708e55
    
708e55
    Co-Authored-By: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
708e55
    Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
708e55
708e55
diff --git a/manual/threads.texi b/manual/threads.texi
708e55
index 06b6b277a1228af1..ab44a92ca0f5a6a5 100644
708e55
--- a/manual/threads.texi
708e55
+++ b/manual/threads.texi
708e55
@@ -629,6 +629,8 @@ the standard.
708e55
 * Waiting with Explicit Clocks::          Functions for waiting with an
708e55
                                           explicit clock specification.
708e55
 * Single-Threaded::                       Detecting single-threaded execution.
708e55
+* Restartable Sequences::                 Linux-specific restartable sequences
708e55
+                                          integration.
708e55
 @end menu
708e55
 
708e55
 @node Default Thread Attributes
708e55
@@ -958,6 +960,85 @@ application-created thread because future versions of @theglibc{} may
708e55
 create background threads after the first thread has been created, and
708e55
 the application has no way of knowning that these threads are present.
708e55
 
708e55
+@node Restartable Sequences
708e55
+@subsubsection Restartable Sequences
708e55
+
708e55
+This section describes restartable sequences integration for
708e55
+@theglibc{}.  This functionality is only available on Linux.
708e55
+
708e55
+@deftp {Data Type} {struct rseq}
708e55
+@standards{Linux, sys/rseq.h}
708e55
+The type of the restartable sequences area.  Future versions
708e55
+of Linux may add additional fields to the end of this structure.
708e55
+
708e55
+
708e55
+Users need to obtain the address of the restartable sequences area using
708e55
+the thread pointer and the @code{__rseq_offset} variable, described
708e55
+below.
708e55
+
708e55
+One use of the restartable sequences area is to read the current CPU
708e55
+number from its @code{cpu_id} field, as an inline version of
708e55
+@code{sched_getcpu}.  @Theglibc{} sets the @code{cpu_id} field to
708e55
+@code{RSEQ_CPU_ID_REGISTRATION_FAILED} if registration failed or was
708e55
+explicitly disabled.
708e55
+
708e55
+Furthermore, users can store the address of a @code{struct rseq_cs}
708e55
+object into the @code{rseq_cs} field of @code{struct rseq}, thus
708e55
+informing the kernel that the thread enters a restartable sequence
708e55
+critical section.  This pointer and the code areas it itself points to
708e55
+must not be left pointing to memory areas which are freed or re-used.
708e55
+Several approaches can guarantee this.  If the application or library
708e55
+can guarantee that the memory used to hold the @code{struct rseq_cs} and
708e55
+the code areas it refers to are never freed or re-used, no special
708e55
+action must be taken.  Else, before that memory is re-used of freed, the
708e55
+application is responsible for setting the @code{rseq_cs} field to
708e55
+@code{NULL} in each thread's restartable sequence area to guarantee that
708e55
+it does not leak dangling references.  Because the application does not
708e55
+typically have knowledge of libraries' use of restartable sequences, it
708e55
+is recommended that libraries using restartable sequences which may end
708e55
+up freeing or re-using their memory set the @code{rseq_cs} field to
708e55
+@code{NULL} before returning from library functions which use
708e55
+restartable sequences.
708e55
+
708e55
+The manual for the @code{rseq} system call can be found
708e55
+at @uref{https://git.kernel.org/pub/scm/libs/librseq/librseq.git/tree/doc/man/rseq.2}.
708e55
+@end deftp
708e55
+
708e55
+@deftypevar {int} __rseq_offset
708e55
+@standards{Linux, sys/rseq.h}
708e55
+This variable contains the offset between the thread pointer (as defined
708e55
+by @code{__builtin_thread_pointer} or the thread pointer register for
708e55
+the architecture) and the restartable sequences area.  This value is the
708e55
+same for all threads in the process.  If the restartable sequences area
708e55
+is located at a lower address than the location to which the thread
708e55
+pointer points, the value is negative.
708e55
+@end deftypevar
708e55
+
708e55
+@deftypevar {unsigned int} __rseq_size
708e55
+@standards{Linux, sys/rseq.h}
708e55
+This variable is either zero (if restartable sequence registration
708e55
+failed or has been disabled) or the size of the restartable sequence
708e55
+registration.  This can be different from the size of @code{struct rseq}
708e55
+if the kernel has extended the size of the registration.  If
708e55
+registration is successful, @code{__rseq_size} is at least 32 (the
708e55
+initial size of @code{struct rseq}).
708e55
+@end deftypevar
708e55
+
708e55
+@deftypevar {unsigned int} __rseq_flags
708e55
+@standards{Linux, sys/rseq.h}
708e55
+The flags used during restartable sequence registration with the kernel.
708e55
+Currently zero.
708e55
+@end deftypevar
708e55
+
708e55
+@deftypevr Macro int RSEQ_SIG
708e55
+@standards{Linux, sys/rseq.h}
708e55
+Each supported architecture provides a @code{RSEQ_SIG} macro in
708e55
+@file{sys/rseq.h} which contains a signature.  That signature is
708e55
+expected to be present in the code before each restartable sequences
708e55
+abort handler.  Failure to provide the expected signature may terminate
708e55
+the process with a segmentation fault.
708e55
+@end deftypevr
708e55
+
708e55
 @c FIXME these are undocumented:
708e55
 @c pthread_atfork
708e55
 @c pthread_attr_destroy
708e55
diff --git a/sysdeps/nptl/dl-tls_init_tp.c b/sysdeps/nptl/dl-tls_init_tp.c
708e55
index b39dfbff2c6678d5..4a73927f805abf94 100644
708e55
--- a/sysdeps/nptl/dl-tls_init_tp.c
708e55
+++ b/sysdeps/nptl/dl-tls_init_tp.c
708e55
@@ -22,6 +22,7 @@
708e55
 #include <pthreadP.h>
708e55
 #include <tls.h>
708e55
 #include <rseq-internal.h>
708e55
+#include <thread_pointer.h>
708e55
 
708e55
 #define TUNABLE_NAMESPACE pthread
708e55
 #include <dl-tunables.h>
708e55
@@ -43,6 +44,10 @@ rtld_mutex_dummy (pthread_mutex_t *lock)
708e55
 }
708e55
 #endif
708e55
 
708e55
+const unsigned int __rseq_flags;
708e55
+const unsigned int __rseq_size attribute_relro;
708e55
+const int __rseq_offset attribute_relro;
708e55
+
708e55
 void
708e55
 __tls_pre_init_tp (void)
708e55
 {
708e55
@@ -100,7 +105,23 @@ __tls_init_tp (void)
708e55
 #if HAVE_TUNABLES
708e55
     do_rseq = TUNABLE_GET (rseq, int, NULL);
708e55
 #endif
708e55
-    rseq_register_current_thread (pd, do_rseq);
708e55
+    if (rseq_register_current_thread (pd, do_rseq))
708e55
+      {
708e55
+        /* We need a writable view of the variables.  They are in
708e55
+           .data.relro and are not yet write-protected.  */
708e55
+        extern unsigned int size __asm__ ("__rseq_size");
708e55
+        size = sizeof (pd->rseq_area);
708e55
+      }
708e55
+
708e55
+#ifdef RSEQ_SIG
708e55
+    /* This should be a compile-time constant, but the current
708e55
+       infrastructure makes it difficult to determine its value.  Not
708e55
+       all targets support __thread_pointer, so set __rseq_offset only
708e55
+       if thre rseq registration may have happened because RSEQ_SIG is
708e55
+       defined.  */
708e55
+    extern int offset __asm__ ("__rseq_offset");
708e55
+    offset = (char *) &pd->rseq_area - (char *) __thread_pointer ();
708e55
+#endif
708e55
   }
708e55
 
708e55
   /* Set initial thread's stack block from 0 up to __libc_stack_end.
708e55
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
708e55
index 0657f4003e7116c6..856a9d58cef6a879 100644
708e55
--- a/sysdeps/unix/sysv/linux/Makefile
708e55
+++ b/sysdeps/unix/sysv/linux/Makefile
708e55
@@ -110,7 +110,8 @@ sysdep_headers += sys/mount.h sys/acct.h \
708e55
 		  bits/types/struct_semid64_ds_helper.h \
708e55
 		  bits/types/struct_shmid64_ds.h \
708e55
 		  bits/types/struct_shmid64_ds_helper.h \
708e55
-		  bits/pthread_stack_min.h bits/pthread_stack_min-dynamic.h
708e55
+		  bits/pthread_stack_min.h bits/pthread_stack_min-dynamic.h \
708e55
+		  sys/rseq.h bits/rseq.h
708e55
 
708e55
 tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
708e55
 	 tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \
708e55
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
708e55
index 26452f3f17b5421d..3f8809a1581f27d0 100644
708e55
--- a/sysdeps/unix/sysv/linux/Versions
708e55
+++ b/sysdeps/unix/sysv/linux/Versions
708e55
@@ -316,6 +316,11 @@ librt {
708e55
 }
708e55
 
708e55
 ld {
708e55
+  GLIBC_2.35 {
708e55
+    __rseq_flags;
708e55
+    __rseq_offset;
708e55
+    __rseq_size;
708e55
+  }
708e55
   GLIBC_PRIVATE {
708e55
     __nptl_change_stack_perm;
708e55
   }
708e55
diff --git a/sysdeps/unix/sysv/linux/aarch64/ld.abilist b/sysdeps/unix/sysv/linux/aarch64/ld.abilist
708e55
index b7196a80e2df8efc..bf4d4f9b6f2ddf97 100644
708e55
--- a/sysdeps/unix/sysv/linux/aarch64/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/aarch64/ld.abilist
708e55
@@ -4,3 +4,6 @@ GLIBC_2.17 __tls_get_addr F
708e55
 GLIBC_2.17 _dl_mcount F
708e55
 GLIBC_2.17 _r_debug D 0x28
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/alpha/ld.abilist b/sysdeps/unix/sysv/linux/alpha/ld.abilist
708e55
index 13f7fc74af62941d..a23325a566419b41 100644
708e55
--- a/sysdeps/unix/sysv/linux/alpha/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/alpha/ld.abilist
708e55
@@ -3,4 +3,7 @@ GLIBC_2.1 __libc_stack_end D 0x8
708e55
 GLIBC_2.1 _dl_mcount F
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x8
708e55
diff --git a/sysdeps/unix/sysv/linux/arc/ld.abilist b/sysdeps/unix/sysv/linux/arc/ld.abilist
708e55
index 7284383a6bea8e64..55f0c2ab9c6f7d91 100644
708e55
--- a/sysdeps/unix/sysv/linux/arc/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/arc/ld.abilist
708e55
@@ -4,3 +4,6 @@ GLIBC_2.32 __tls_get_addr F
708e55
 GLIBC_2.32 _dl_mcount F
708e55
 GLIBC_2.32 _r_debug D 0x14
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/arm/be/ld.abilist b/sysdeps/unix/sysv/linux/arm/be/ld.abilist
708e55
index 7987bbae1112aa3d..f1da2c636ddb359d 100644
708e55
--- a/sysdeps/unix/sysv/linux/arm/be/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/arm/be/ld.abilist
708e55
@@ -1,4 +1,7 @@
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __libc_stack_end D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x4
708e55
 GLIBC_2.4 __tls_get_addr F
708e55
diff --git a/sysdeps/unix/sysv/linux/arm/le/ld.abilist b/sysdeps/unix/sysv/linux/arm/le/ld.abilist
708e55
index 7987bbae1112aa3d..f1da2c636ddb359d 100644
708e55
--- a/sysdeps/unix/sysv/linux/arm/le/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/arm/le/ld.abilist
708e55
@@ -1,4 +1,7 @@
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __libc_stack_end D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x4
708e55
 GLIBC_2.4 __tls_get_addr F
708e55
diff --git a/sysdeps/unix/sysv/linux/csky/ld.abilist b/sysdeps/unix/sysv/linux/csky/ld.abilist
708e55
index 4939b20631dc6c54..7f482276ed8df1d5 100644
708e55
--- a/sysdeps/unix/sysv/linux/csky/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/csky/ld.abilist
708e55
@@ -4,3 +4,6 @@ GLIBC_2.29 __tls_get_addr F
708e55
 GLIBC_2.29 _dl_mcount F
708e55
 GLIBC_2.29 _r_debug D 0x14
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/hppa/ld.abilist b/sysdeps/unix/sysv/linux/hppa/ld.abilist
708e55
index 7cc9ebd792c2aadc..7f5527fb301b913c 100644
708e55
--- a/sysdeps/unix/sysv/linux/hppa/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/hppa/ld.abilist
708e55
@@ -3,4 +3,7 @@ GLIBC_2.2 _dl_mcount F
708e55
 GLIBC_2.2 _r_debug D 0x14
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/i386/ld.abilist b/sysdeps/unix/sysv/linux/i386/ld.abilist
708e55
index e8d187b14d722a64..9c4a45d8dc525e52 100644
708e55
--- a/sysdeps/unix/sysv/linux/i386/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/i386/ld.abilist
708e55
@@ -4,3 +4,6 @@ GLIBC_2.1 _dl_mcount F
708e55
 GLIBC_2.3 ___tls_get_addr F
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/ia64/ld.abilist b/sysdeps/unix/sysv/linux/ia64/ld.abilist
708e55
index be5122650ae2b327..8ccb5be911e0e9a2 100644
708e55
--- a/sysdeps/unix/sysv/linux/ia64/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/ia64/ld.abilist
708e55
@@ -3,3 +3,6 @@ GLIBC_2.2 _dl_mcount F
708e55
 GLIBC_2.2 _r_debug D 0x28
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist
708e55
index 7987bbae1112aa3d..f1da2c636ddb359d 100644
708e55
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist
708e55
@@ -1,4 +1,7 @@
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __libc_stack_end D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x4
708e55
 GLIBC_2.4 __tls_get_addr F
708e55
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist
708e55
index 4f2854edf7746958..dadbf852d0522e77 100644
708e55
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist
708e55
@@ -3,4 +3,7 @@ GLIBC_2.1 __libc_stack_end D 0x4
708e55
 GLIBC_2.1 _dl_mcount F
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/microblaze/ld.abilist b/sysdeps/unix/sysv/linux/microblaze/ld.abilist
708e55
index 9f0fdeca38890a34..89a0b7e4fd5a95fa 100644
708e55
--- a/sysdeps/unix/sysv/linux/microblaze/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/microblaze/ld.abilist
708e55
@@ -4,3 +4,6 @@ GLIBC_2.18 __tls_get_addr F
708e55
 GLIBC_2.18 _dl_mcount F
708e55
 GLIBC_2.18 _r_debug D 0x14
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist b/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist
708e55
index f750067d5c34bf42..e304d1bb464b28f4 100644
708e55
--- a/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist
708e55
@@ -3,4 +3,7 @@ GLIBC_2.2 __libc_stack_end D 0x4
708e55
 GLIBC_2.2 _dl_mcount F
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist
708e55
index f750067d5c34bf42..e304d1bb464b28f4 100644
708e55
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist
708e55
@@ -3,4 +3,7 @@ GLIBC_2.2 __libc_stack_end D 0x4
708e55
 GLIBC_2.2 _dl_mcount F
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist
708e55
index 2fba6a9b6ec92e47..37a47ebc0a0d16c8 100644
708e55
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist
708e55
@@ -3,4 +3,7 @@ GLIBC_2.2 __libc_stack_end D 0x8
708e55
 GLIBC_2.2 _dl_mcount F
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x8
708e55
diff --git a/sysdeps/unix/sysv/linux/nios2/ld.abilist b/sysdeps/unix/sysv/linux/nios2/ld.abilist
708e55
index 57dfad5a53b739e8..811ae9da2fa85399 100644
708e55
--- a/sysdeps/unix/sysv/linux/nios2/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/nios2/ld.abilist
708e55
@@ -4,3 +4,6 @@ GLIBC_2.21 __tls_get_addr F
708e55
 GLIBC_2.21 _dl_mcount F
708e55
 GLIBC_2.21 _r_debug D 0x14
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
708e55
index e89660739262c6ab..5a68aeb9eed33844 100644
708e55
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
708e55
@@ -5,3 +5,6 @@ GLIBC_2.22 __tls_get_addr_opt F
708e55
 GLIBC_2.23 __parse_hwcap_and_convert_at_platform F
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
708e55
index ce0bc639597c4bd9..da24dc7fb52ad2d4 100644
708e55
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
708e55
@@ -5,3 +5,6 @@ GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.3 _dl_mcount F
708e55
 GLIBC_2.3 _r_debug D 0x28
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
708e55
index 65b22674d2462e96..b9ae89ae8d90ed9e 100644
708e55
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
708e55
@@ -5,3 +5,6 @@ GLIBC_2.17 _r_debug D 0x28
708e55
 GLIBC_2.22 __tls_get_addr_opt F
708e55
 GLIBC_2.23 __parse_hwcap_and_convert_at_platform F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/ld.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/ld.abilist
708e55
index 5ad4c81d12d7a612..068368878eb2406e 100644
708e55
--- a/sysdeps/unix/sysv/linux/riscv/rv32/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/riscv/rv32/ld.abilist
708e55
@@ -4,3 +4,6 @@ GLIBC_2.33 __tls_get_addr F
708e55
 GLIBC_2.33 _dl_mcount F
708e55
 GLIBC_2.33 _r_debug D 0x14
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist
708e55
index 479efdea9bb654bb..48431c91a9fd16b0 100644
708e55
--- a/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist
708e55
@@ -4,3 +4,6 @@ GLIBC_2.27 __tls_get_addr F
708e55
 GLIBC_2.27 _dl_mcount F
708e55
 GLIBC_2.27 _r_debug D 0x28
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h
708e55
index 6a3441f2cc49e7c4..9e8f99fd51a063b1 100644
708e55
--- a/sysdeps/unix/sysv/linux/rseq-internal.h
708e55
+++ b/sysdeps/unix/sysv/linux/rseq-internal.h
708e55
@@ -41,7 +41,7 @@ rseq_register_current_thread (struct pthread *self, bool do_rseq)
708e55
   return false;
708e55
 }
708e55
 #else /* RSEQ_SIG */
708e55
-static inline void
708e55
+static inline bool
708e55
 rseq_register_current_thread (struct pthread *self, bool do_rseq)
708e55
 {
708e55
   THREAD_SETMEM (self, rseq_area.cpu_id, RSEQ_CPU_ID_REGISTRATION_FAILED);
708e55
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
708e55
index d5ecb636bb792bdf..c15288394a232a8c 100644
708e55
--- a/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
708e55
@@ -3,3 +3,6 @@ GLIBC_2.1 __libc_stack_end D 0x4
708e55
 GLIBC_2.1 _dl_mcount F
708e55
 GLIBC_2.3 __tls_get_offset F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
708e55
index 62a5e1d99a2e6f42..117d1430a4c6272e 100644
708e55
--- a/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
708e55
@@ -3,3 +3,6 @@ GLIBC_2.2 _dl_mcount F
708e55
 GLIBC_2.2 _r_debug D 0x28
708e55
 GLIBC_2.3 __tls_get_offset F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/sh/be/ld.abilist b/sysdeps/unix/sysv/linux/sh/be/ld.abilist
708e55
index 7cc9ebd792c2aadc..7f5527fb301b913c 100644
708e55
--- a/sysdeps/unix/sysv/linux/sh/be/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/sh/be/ld.abilist
708e55
@@ -3,4 +3,7 @@ GLIBC_2.2 _dl_mcount F
708e55
 GLIBC_2.2 _r_debug D 0x14
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/sh/le/ld.abilist b/sysdeps/unix/sysv/linux/sh/le/ld.abilist
708e55
index 7cc9ebd792c2aadc..7f5527fb301b913c 100644
708e55
--- a/sysdeps/unix/sysv/linux/sh/le/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/sh/le/ld.abilist
708e55
@@ -3,4 +3,7 @@ GLIBC_2.2 _dl_mcount F
708e55
 GLIBC_2.2 _r_debug D 0x14
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
 GLIBC_2.4 __stack_chk_guard D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
708e55
index 2e6054349871e7d5..3aac73f3df646cb6 100644
708e55
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
708e55
@@ -3,3 +3,6 @@ GLIBC_2.1 __libc_stack_end D 0x4
708e55
 GLIBC_2.1 _dl_mcount F
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
708e55
index be5122650ae2b327..8ccb5be911e0e9a2 100644
708e55
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
708e55
@@ -3,3 +3,6 @@ GLIBC_2.2 _dl_mcount F
708e55
 GLIBC_2.2 _r_debug D 0x28
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/sys/rseq.h b/sysdeps/unix/sysv/linux/sys/rseq.h
708e55
index c8edff50d40e29b6..1215b5d086b8852b 100644
708e55
--- a/sysdeps/unix/sysv/linux/sys/rseq.h
708e55
+++ b/sysdeps/unix/sysv/linux/sys/rseq.h
708e55
@@ -171,4 +171,14 @@ struct rseq
708e55
 
708e55
 #endif /* __GLIBC_HAVE_KERNEL_RSEQ */
708e55
 
708e55
+/* Offset from the thread pointer to the rseq area.  */
708e55
+extern const int __rseq_offset;
708e55
+
708e55
+/* Size of the registered rseq area.  0 if the registration was
708e55
+   unsuccessful.  */
708e55
+extern const unsigned int __rseq_size;
708e55
+
708e55
+/* Flags used during rseq registration.  */
708e55
+extern const unsigned int __rseq_flags;
708e55
+
708e55
 #endif /* sys/rseq.h */
708e55
diff --git a/sysdeps/unix/sysv/linux/tst-rseq-disable.c b/sysdeps/unix/sysv/linux/tst-rseq-disable.c
708e55
index 000e351872fc2f76..6d73f77e9621da42 100644
708e55
--- a/sysdeps/unix/sysv/linux/tst-rseq-disable.c
708e55
+++ b/sysdeps/unix/sysv/linux/tst-rseq-disable.c
708e55
@@ -21,6 +21,7 @@
708e55
 #include <support/namespace.h>
708e55
 #include <support/xthread.h>
708e55
 #include <sysdep.h>
708e55
+#include <thread_pointer.h>
708e55
 #include <unistd.h>
708e55
 
708e55
 #ifdef RSEQ_SIG
708e55
@@ -30,6 +31,11 @@ static void
708e55
 check_rseq_disabled (void)
708e55
 {
708e55
   struct pthread *pd = THREAD_SELF;
708e55
+
708e55
+  TEST_COMPARE (__rseq_flags, 0);
708e55
+  TEST_VERIFY ((char *) __thread_pointer () + __rseq_offset
708e55
+               == (char *) &pd->rseq_area);
708e55
+  TEST_COMPARE (__rseq_size, 0);
708e55
   TEST_COMPARE ((int) pd->rseq_area.cpu_id, RSEQ_CPU_ID_REGISTRATION_FAILED);
708e55
 
708e55
   int ret = syscall (__NR_rseq, &pd->rseq_area, sizeof (pd->rseq_area),
708e55
diff --git a/sysdeps/unix/sysv/linux/tst-rseq.c b/sysdeps/unix/sysv/linux/tst-rseq.c
708e55
index 926376b6a5446ece..572c11166f8b6533 100644
708e55
--- a/sysdeps/unix/sysv/linux/tst-rseq.c
708e55
+++ b/sysdeps/unix/sysv/linux/tst-rseq.c
708e55
@@ -29,12 +29,20 @@
708e55
 # include <stdlib.h>
708e55
 # include <string.h>
708e55
 # include <syscall.h>
708e55
+# include <thread_pointer.h>
708e55
+# include <tls.h>
708e55
 # include "tst-rseq.h"
708e55
 
708e55
 static void
708e55
 do_rseq_main_test (void)
708e55
 {
708e55
+  struct pthread *pd = THREAD_SELF;
708e55
+
708e55
   TEST_VERIFY_EXIT (rseq_thread_registered ());
708e55
+  TEST_COMPARE (__rseq_flags, 0);
708e55
+  TEST_VERIFY ((char *) __thread_pointer () + __rseq_offset
708e55
+               == (char *) &pd->rseq_area);
708e55
+  TEST_COMPARE (__rseq_size, sizeof (pd->rseq_area));
708e55
 }
708e55
 
708e55
 static void
708e55
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist b/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
708e55
index afddaec57c11f837..ae622bdf9710bdbd 100644
708e55
--- a/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
708e55
@@ -3,3 +3,6 @@ GLIBC_2.2.5 _dl_mcount F
708e55
 GLIBC_2.2.5 _r_debug D 0x28
708e55
 GLIBC_2.3 __tls_get_addr F
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4
708e55
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
708e55
index defc488d137c61c3..e17496d124b0c7b7 100644
708e55
--- a/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
708e55
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
708e55
@@ -3,3 +3,6 @@ GLIBC_2.16 __tls_get_addr F
708e55
 GLIBC_2.16 _dl_mcount F
708e55
 GLIBC_2.16 _r_debug D 0x14
708e55
 GLIBC_2.34 __rtld_version_placeholder F
708e55
+GLIBC_2.35 __rseq_flags D 0x4
708e55
+GLIBC_2.35 __rseq_offset D 0x4
708e55
+GLIBC_2.35 __rseq_size D 0x4