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