aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix
diff options
context:
space:
mode:
authorMichael Jeanson <mjeanson@efficios.com>2024-08-01 11:10:49 -0400
committerMichael Jeanson <mjeanson@efficios.com>2025-01-10 20:19:40 +0000
commit304221775cd321886d0ca86ac167f7af6913a1ec (patch)
treed89245c4c98e581bcb8b1410e6ece175c4443d5f /sysdeps/unix
parent0e411c5d3098982d67cd2d7a233eaa6c977a1869 (diff)
downloadglibc-304221775cd321886d0ca86ac167f7af6913a1ec.zip
glibc-304221775cd321886d0ca86ac167f7af6913a1ec.tar.gz
glibc-304221775cd321886d0ca86ac167f7af6913a1ec.tar.bz2
Add Linux 'extra TLS'
Add the Linux implementation of 'extra TLS' which will allocate space for the rseq area at the end of the TLS blocks in allocation order. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Reviewed-by: Florian Weimer <fweimer@redhat.com>
Diffstat (limited to 'sysdeps/unix')
-rw-r--r--sysdeps/unix/sysv/linux/dl-extra_tls.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/dl-extra_tls.h b/sysdeps/unix/sysv/linux/dl-extra_tls.h
new file mode 100644
index 0000000..d48a5e9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/dl-extra_tls.h
@@ -0,0 +1,71 @@
+/* extra tls block utils for the dynamic linker. Linux version.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _DL_EXTRA_TLS_H
+#define _DL_EXTRA_TLS_H 1
+
+#include <stddef.h>
+#include <sys/rseq.h>
+#include <rseq-internal.h>
+#include <elf/dl-tunables.h>
+
+/* Returns the size of the extra TLS block, it must always be a multiple of the
+ alignment. */
+static inline size_t
+_dl_extra_tls_get_size (void)
+{
+ bool do_rseq = TUNABLE_GET_FULL (glibc, pthread, rseq, int, NULL);
+ if (do_rseq)
+ {
+ /* Make sure the rseq area size is at least the minimum ABI size and a
+ multiple of the requested aligment. */
+ return roundup (MAX (_rseq_size, RSEQ_AREA_SIZE_INITIAL), _rseq_align);
+ }
+
+ /* Even when disabled by tunable, an rseq area will be allocated to allow
+ application code to test the registration status with 'rseq->cpu_id >= 0'.
+ Default to the rseq ABI minimum size, this will ensure we don't use more
+ TLS than necessary. */
+ return RSEQ_AREA_SIZE_INITIAL;
+}
+
+/* Returns the alignment requirements of the extra TLS block. */
+static inline size_t
+_dl_extra_tls_get_align (void)
+{
+ bool do_rseq = TUNABLE_GET_FULL (glibc, pthread, rseq, int, NULL);
+ if (do_rseq)
+ {
+ return _rseq_align;
+ }
+
+ /* Even when disabled by tunable, an rseq area will be allocated to allow
+ application code to test the registration status with 'rseq->cpu_id >= 0'.
+ Default to the rseq ABI minimum alignment, this will ensure we don't use
+ more TLS than necessary. */
+ return RSEQ_MIN_ALIGN;
+}
+
+/* Record the offset of the extra TLS block from the thread pointer. */
+static inline void
+_dl_extra_tls_set_offset (ptrdiff_t tls_offset)
+{
+ _rseq_offset = tls_offset;
+}
+
+#endif