From c901c3e764d7c7079f006b4e21e877d5036eb4f5 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 9 Dec 2021 09:49:32 +0100 Subject: nptl: Add public rseq symbols and The relationship between the thread pointer and the rseq area is made explicit. The constant offset can be used by JIT compilers to optimize rseq access (e.g., for really fast sched_getcpu). Extensibility is provided through __rseq_size and __rseq_flags. (In the future, the kernel could request a different rseq size via the auxiliary vector.) Co-Authored-By: Mathieu Desnoyers Reviewed-by: Szabolcs Nagy --- sysdeps/nptl/dl-tls_init_tp.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'sysdeps/nptl/dl-tls_init_tp.c') diff --git a/sysdeps/nptl/dl-tls_init_tp.c b/sysdeps/nptl/dl-tls_init_tp.c index b39dfbff2c..4a73927f80 100644 --- a/sysdeps/nptl/dl-tls_init_tp.c +++ b/sysdeps/nptl/dl-tls_init_tp.c @@ -22,6 +22,7 @@ #include #include #include +#include #define TUNABLE_NAMESPACE pthread #include @@ -43,6 +44,10 @@ rtld_mutex_dummy (pthread_mutex_t *lock) } #endif +const unsigned int __rseq_flags; +const unsigned int __rseq_size attribute_relro; +const int __rseq_offset attribute_relro; + void __tls_pre_init_tp (void) { @@ -100,7 +105,23 @@ __tls_init_tp (void) #if HAVE_TUNABLES do_rseq = TUNABLE_GET (rseq, int, NULL); #endif - rseq_register_current_thread (pd, do_rseq); + if (rseq_register_current_thread (pd, do_rseq)) + { + /* We need a writable view of the variables. They are in + .data.relro and are not yet write-protected. */ + extern unsigned int size __asm__ ("__rseq_size"); + size = sizeof (pd->rseq_area); + } + +#ifdef RSEQ_SIG + /* This should be a compile-time constant, but the current + infrastructure makes it difficult to determine its value. Not + all targets support __thread_pointer, so set __rseq_offset only + if thre rseq registration may have happened because RSEQ_SIG is + defined. */ + extern int offset __asm__ ("__rseq_offset"); + offset = (char *) &pd->rseq_area - (char *) __thread_pointer (); +#endif } /* Set initial thread's stack block from 0 up to __libc_stack_end. -- cgit v1.2.3