glibc: Perform rseq(2) registration at C startup and thread creation (v7)
RFC PATCH 1/4 glibc: Perform rseq(2) registration at C startup and thread creation (v7)
Register rseq(2) TLS for each thread (including main), and unregister for each thread (excluding main). "rseq" stands for Restartable Sequences.
See the rseq(2) man page proposed here:
https://lkml.org/lkml/2018/9/19/647
This patch is based on glibc-2.29. The rseq(2) system call was merged into Linux 4.18.
---
Changes since v1:
- Move __rseq_refcount to an extra field at the end of __rseq_abi to eliminate one symbol.
All libraries/programs which try to register rseq (glibc, early-adopter applications, early-adopter libraries) should use the rseq refcount. It becomes part of the ABI within a user-space process, but it's not part of the ABI shared with the kernel per se.
- Restructure how this code is organized so glibc keeps building on non-Linux targets.
- Use non-weak symbol for __rseq_abi.
- Move rseq registration/unregistration implementation into its own nptl/rseq.c compile unit.
- Move __rseq_abi symbol under GLIBC_2.29.
Changes since v2:
- Move __rseq_refcount to its own symbol, which is less ugly than trying to play tricks with the rseq uapi.
- Move __rseq_abi from nptl to csu (C start up), so it can be used across glibc, including memory allocator and sched_getcpu(). The __rseq_refcount symbol is kept in nptl, because there is no reason to use it elsewhere in glibc.
Changes since v3:
- Set __rseq_refcount TLS to 1 on register/set to 0 on unregister because glibc is the first/last user.
- Unconditionally register/unregister rseq at thread start/exit, because glibc is the first/last user.
- Add missing abilist items.
- Rebase on glibc master commit a502c5294.
- Add NEWS entry.
Changes since v4:
- Do not use "weak" symbols for __rseq_abi and __rseq_refcount. Based on "System V Application Binary Interface", weak only affects the link editor, not the dynamic linker.
- Install a new sys/rseq.h system header on Linux, which contains the RSEQ_SIG definition, __rseq_abi declaration and __rseq_refcount declaration. Move those definition/declarations from rseq-internal.h to the installed sys/rseq.h header.
- Considering that rseq is only available on Linux, move csu/rseq.c to sysdeps/unix/sysv/linux/rseq-sym.c.
- Move __rseq_refcount from nptl/rseq.c to sysdeps/unix/sysv/linux/rseq-sym.c, so it is only defined on Linux.
- Move both ABI definitions for __rseq_abi and __rseq_refcount to sysdeps/unix/sysv/linux/Versions, so they only appear on Linux.
- Document __rseq_abi and __rseq_refcount volatile.
- Document the RSEQ_SIG signature define.
- Move registration functions from rseq.c to rseq-internal.h static inline functions. Introduce empty stubs in misc/rseq-internal.h, which can be overridden by architecture code in sysdeps/unix/sysv/linux/rseq-internal.h.
- Rename __rseq_register_current_thread and __rseq_unregister_current_thread to rseq_register_current_thread and rseq_unregister_current_thread, now that those are only visible as internal static inline functions.
- Invoke rseq_register_current_thread() from libc-start.c LIBC_START_MAIN rather than nptl init, so applications not linked against libpthread.so have rseq registered for their main() thread. Note that it is invoked separately for SHARED and !SHARED builds.
Changes since v5:
- Replace __rseq_refcount by __rseq_lib_abi, which contains two
uint32_t: register_state and refcount. The "register_state" field allows inhibiting rseq registration from signal handlers nested on top of glibc registration and occuring after rseq unregistration by glibc.
- Introduce enum rseq_register_state, which contains the states allowed for the struct rseq_lib_abi register_state field.
Changes since v6:
- Introduce bits/rseq.h to define RSEQ_SIG for each architecture. The generic bits/rseq.h does not define RSEQ_SIG, meaning that each architecture implementing rseq needs to implement bits/rseq.h.
- Rename enum item RSEQ_REGISTER_NESTED to RSEQ_REGISTER_ONGOING.
- Port to glibc-2.29.
--- NEWS | 11 +++ csu/libc-start.c | 12 ++- misc/Makefile | 3 +- misc/rseq-internal.h | 34 +++++++ nptl/pthread_create.c | 9 ++ sysdeps/unix/sysv/linux/Makefile | 4 +- sysdeps/unix/sysv/linux/Versions | 4 + sysdeps/unix/sysv/linux/aarch64/bits/rseq.h | 24 +++++ sysdeps/unix/sysv/linux/aarch64/libc.abilist | 2 + sysdeps/unix/sysv/linux/alpha/libc.abilist | 2 + sysdeps/unix/sysv/linux/arm/bits/rseq.h | 24 +++++ sysdeps/unix/sysv/linux/arm/libc.abilist | 2 + sysdeps/unix/sysv/linux/bits/rseq.h | 24 +++++ sysdeps/unix/sysv/linux/hppa/libc.abilist | 2 + sysdeps/unix/sysv/linux/i386/libc.abilist | 2 + sysdeps/unix/sysv/linux/ia64/libc.abilist | 2 + .../sysv/linux/m68k/coldfire/libc.abilist | 2 + .../unix/sysv/linux/m68k/m680x0/libc.abilist | 2 + .../unix/sysv/linux/microblaze/libc.abilist | 2 + sysdeps/unix/sysv/linux/mips/bits/rseq.h | 24 +++++ .../sysv/linux/mips/mips32/fpu/libc.abilist | 2 + .../sysv/linux/mips/mips32/nofpu/libc.abilist | 2 + .../sysv/linux/mips/mips64/n32/libc.abilist | 2 + .../sysv/linux/mips/mips64/n64/libc.abilist | 2 + sysdeps/unix/sysv/linux/nios2/libc.abilist | 2 + sysdeps/unix/sysv/linux/powerpc/bits/rseq.h | 24 +++++ .../linux/powerpc/powerpc32/fpu/libc.abilist | 2 + .../powerpc/powerpc32/nofpu/libc.abilist | 2 + .../linux/powerpc/powerpc64/be/libc.abilist | 2 + .../linux/powerpc/powerpc64/le/libc.abilist | 2 + .../unix/sysv/linux/riscv/rv64/libc.abilist | 2 + sysdeps/unix/sysv/linux/rseq-internal.h | 91 +++++++++++++++++++ sysdeps/unix/sysv/linux/rseq-sym.c | 54 +++++++++++ sysdeps/unix/sysv/linux/s390/bits/rseq.h | 24 +++++ .../unix/sysv/linux/s390/s390-32/libc.abilist | 2 + .../unix/sysv/linux/s390/s390-64/libc.abilist | 2 + sysdeps/unix/sysv/linux/sh/libc.abilist | 2 + .../sysv/linux/sparc/sparc32/libc.abilist | 2 + .../sysv/linux/sparc/sparc64/libc.abilist | 2 + sysdeps/unix/sysv/linux/sys/rseq.h | 65 +++++++++++++ sysdeps/unix/sysv/linux/x86/bits/rseq.h | 24 +++++ .../unix/sysv/linux/x86_64/64/libc.abilist | 2 + .../unix/sysv/linux/x86_64/x32/libc.abilist | 2 + 43 files changed, 501 insertions(+), 6 deletions(-) create mode 100644 misc/rseq-internal.h create mode 100644 sysdeps/unix/sysv/linux/aarch64/bits/rseq.h create mode 100644 sysdeps/unix/sysv/linux/arm/bits/rseq.h create mode 100644 sysdeps/unix/sysv/linux/bits/rseq.h create mode 100644 sysdeps/unix/sysv/linux/mips/bits/rseq.h create mode 100644 sysdeps/unix/sysv/linux/powerpc/bits/rseq.h create mode 100644 sysdeps/unix/sysv/linux/rseq-internal.h create mode 100644 sysdeps/unix/sysv/linux/rseq-sym.c create mode 100644 sysdeps/unix/sysv/linux/s390/bits/rseq.h create mode 100644 sysdeps/unix/sysv/linux/sys/rseq.h create mode 100644 sysdeps/unix/sysv/linux/x86/bits/rseq.h
NEWS +11 -0
@@ -5,6 +5,17 @@ See the end for copying conditions. Please send GNU C library bug reports via <https://sourceware.org/bugzilla/> using `glibc' in the "product" field. +Version 2.30 + +Major new features: + +* Support for automatically registering threads with the Linux rseq(2) + system call has been added. This system call is implemented starting + from Linux 4.18. In order to be activated, it requires that glibc is built + against kernel headers that include this system call, and that glibc + detects availability of that system call at runtime. + + Version 2.29 Major new features:
csu/libc-start.c +9 -3
@@ -22,6 +22,7 @@#include <ldsodefs.h> #include <exit-thread.h> #include <libc-internal.h> +#include <rseq-internal.h> #include <elf/dl-tunables.h>
@@ -140,7 +141,10 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up; -#ifndef SHARED +#ifdef SHARED +/* Register rseq ABI to the kernel. */ + (void )rseq_register_current_thread (); +#else _dl_relocate_static_pie ();char **ev = &argv[argc +1 ];
@@ -218,6 +222,9 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), }# endif +/* Register rseq ABI to the kernel. */ + (void )rseq_register_current_thread (); +/* Initialize libpthread if linked in. */ if (__pthread_initialize_minimal !=NULL )__pthread_initialize_minimal ();
@@ -230,8 +237,7 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),# else __pointer_chk_guard_local = pointer_chk_guard;# endif - -#endif /* !SHARED */ +#endif /* Register the destructor of the dynamic linker if there is any. */ if (__glibc_likely (rtld_fini !=NULL ))
misc/Makefile +2 -1
@@ -36,7 +36,8 @@ headers := sys/uio.h bits/uio-ext.h bits/uio_lim.h \ syslog.h sys/syslog.h \ bits/syslog.h bits/syslog-ldbl.h bits/syslog-path.h bits/error.h \ bits/select2.h bits/hwcap.h sys/auxv.h \ - sys/sysmacros.h bits/sysmacros.h bits/types/struct_iovec.h + sys/sysmacros.h bits/sysmacros.h bits/types/struct_iovec.h \ + rseq-internal.h routines := brk sbrk sstk ioctl \ readv writev preadv preadv64 pwritev pwritev64 \
misc/rseq-internal.h new file +34 -0
@@ -0,0 +1,34 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2018. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef RSEQ_INTERNAL_H +#define RSEQ_INTERNAL_H + +static inline int +rseq_register_current_thread (void ) +{ +return -1 ; +} + +static inline int +rseq_unregister_current_thread (void ) +{ +return -1 ; +} + +#endif /* rseq-internal.h */
nptl/pthread_create.c +9 -0
@@ -33,6 +33,7 @@#include <default-sched.h> #include <futex-internal.h> #include <tls-setup.h> +#include <rseq-internal.h> #include "libioP.h" #include <shlib-compat.h>
@@ -378,6 +379,7 @@ __free_tcb (struct pthread *pd) START_THREAD_DEFN {struct pthread *pd =START_THREAD_SELF ; +bool has_rseq = false;#if HP_TIMING_AVAIL /* Remember the time when the thread was started. */
@@ -396,6 +398,9 @@ START_THREAD_DEFNif (__glibc_unlikely (atomic_exchange_acq (&pd->setxid_futex,0 ) ==-2 ))futex_wake (&pd->setxid_futex,1 ,FUTEX_PRIVATE ); +/* Register rseq TLS to the kernel. */ + has_rseq = !rseq_register_current_thread (); +#ifdef __NR_set_robust_list# ifndef __ASSUME_SET_ROBUST_LISTif (__set_robust_list_avail >=0 )
@@ -573,6 +578,10 @@ START_THREAD_DEFN }#endif +/* Unregister rseq TLS from kernel. */ +if (has_rseq &&rseq_unregister_current_thread ()) +abort (); +advise_stack_range (pd->stackblock, pd->stackblock_size, (uintptr_t ) pd, pd->guardsize);
sysdeps/unix/sysv/linux/Makefile +2 -2
@@ -1,5 +1,5 @@ ifeq ($(subdir),csu) -sysdep_routines += errno-loc +sysdep_routines += errno-loc rseq-sym endif ifeq ($(subdir),assert)
@@ -48,7 +48,7 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \ bits/termios-c_iflag.h bits/termios-c_oflag.h \ bits/termios-baud.h bits/termios-c_cflag.h \ bits/termios-c_lflag.h bits/termios-tcflow.h \ - bits/termios-misc.h + bits/termios-misc.h sys/rseq.h bits/rseq.h tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \
sysdeps/unix/sysv/linux/Versions +4 -0
@@ -174,6 +174,10 @@ libc { GLIBC_2.29 { getcpu; } + GLIBC_2.30 { + __rseq_abi; + __rseq_lib_abi; + } GLIBC_PRIVATE { # functions used in other libraries __syscall_rt_sigqueueinfo;
sysdeps/unix/sysv/linux/aarch64/bits/rseq.h new file +24 -0
@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0xd428bc00/* BRK #0x45E0. */
sysdeps/unix/sysv/linux/aarch64/libc.abilist +2 -0
@@ -2141,3 +2141,5 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8
sysdeps/unix/sysv/linux/alpha/libc.abilist +2 -0
@@ -2036,6 +2036,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/arm/bits/rseq.h new file +24 -0
@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053
sysdeps/unix/sysv/linux/arm/libc.abilist +2 -0
@@ -126,6 +126,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.4 _Exit F GLIBC_2.4 _IO_2_1_stderr_ D 0xa0 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0
sysdeps/unix/sysv/linux/bits/rseq.h new file +24 -0
@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Each architecture supporting rseq should define RSEQ_SIG as a 32-bit +signature inserted before each rseq abort label in the code section. */
sysdeps/unix/sysv/linux/hppa/libc.abilist +2 -0
@@ -1883,6 +1883,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/i386/libc.abilist +2 -0
@@ -2048,6 +2048,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/ia64/libc.abilist +2 -0
@@ -1917,6 +1917,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist +2 -0
@@ -127,6 +127,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.4 _Exit F GLIBC_2.4 _IO_2_1_stderr_ D 0x98 GLIBC_2.4 _IO_2_1_stdin_ D 0x98
sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist +2 -0
@@ -1992,6 +1992,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/microblaze/libc.abilist +2 -0
@@ -2133,3 +2133,5 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8
sysdeps/unix/sysv/linux/mips/bits/rseq.h new file +24 -0
@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053
sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist +2 -0
@@ -1970,6 +1970,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist +2 -0
@@ -1968,6 +1968,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist +2 -0
@@ -1976,6 +1976,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist +2 -0
@@ -1971,6 +1971,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/nios2/libc.abilist +2 -0
@@ -2174,3 +2174,5 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8
sysdeps/unix/sysv/linux/powerpc/bits/rseq.h new file +24 -0
@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053
sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist +2 -0
@@ -1996,6 +1996,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist +2 -0
@@ -2000,6 +2000,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist +2 -0
@@ -126,6 +126,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 _Exit F GLIBC_2.3 _IO_2_1_stderr_ D 0xe0 GLIBC_2.3 _IO_2_1_stdin_ D 0xe0
sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist +2 -0
@@ -2231,3 +2231,5 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8
sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist +2 -0
@@ -2103,3 +2103,5 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8
sysdeps/unix/sysv/linux/rseq-internal.h new file +91 -0
91 lines not on this page · raw message
sysdeps/unix/sysv/linux/rseq-sym.c new file +54 -0
54 lines not on this page · raw message
sysdeps/unix/sysv/linux/s390/bits/rseq.h new file +24 -0
@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053
sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist +2 -0
@@ -2005,6 +2005,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist +2 -0
@@ -1911,6 +1911,8 @@ GLIBC_2.29 __fentry__ F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/sh/libc.abilist +2 -0
@@ -1887,6 +1887,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist +2 -0
@@ -1999,6 +1999,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist +2 -0
@@ -1940,6 +1940,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/sys/rseq.h new file +65 -0
65 lines not on this page · raw message
sysdeps/unix/sysv/linux/x86/bits/rseq.h new file +24 -0
@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053
sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +2 -0
@@ -1898,6 +1898,8 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 GLIBC_2.3 __ctype_b_loc F GLIBC_2.3 __ctype_tolower_loc F GLIBC_2.3 __ctype_toupper_loc F
sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +2 -0
@@ -2149,3 +2149,5 @@ GLIBC_2.28 thrd_yield F GLIBC_2.29 getcpu F GLIBC_2.29 posix_spawn_file_actions_addchdir_np F GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F +GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8
Signature · 1 line
2.17.1
RFC PATCH 2/4 glibc: sched_getcpu(): use rseq cpu_id TLS on Linux
When available, use the cpu_id field from __rseq_abi on Linux to implement sched_getcpu(). Fall-back on the vgetcpu vDSO if unavailable.
Benchmarks:
x86-64: Intel E5-2630 [email protected], 16-core, hyperthreading
glibc sched_getcpu(): 13.7 ns (baseline) glibc sched_getcpu() using rseq: 2.5 ns (speedup: 5.5x)
inline load cpuid from __rseq_abi TLS: 0.8 ns (speedup: 17.1x)
--- sysdeps/unix/sysv/linux/sched_getcpu.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
sysdeps/unix/sysv/linux/sched_getcpu.c +23 -2
@@ -24,8 +24,8 @@#endif #include <sysdep-vdso.h> -int -sched_getcpu (void ) +static int +vsyscall_sched_getcpu (void ) {#ifdef __NR_getcpuunsigned int cpu;
@@ -37,3 +37,24 @@ sched_getcpu (void)return -1 ;#endif } + +#ifdef __NR_rseq +#include <linux/rseq.h> + +extern __attribute__ ((tls_model ("initial-exec" ))) +__threadvolatile struct rseq __rseq_abi; + +int +sched_getcpu (void ) +{ +int cpu_id = __rseq_abi.cpu_id; + +return cpu_id >=0 ? cpu_id :vsyscall_sched_getcpu (); +} +#else +int +sched_getcpu (void ) +{ +return vsyscall_sched_getcpu (); +} +#endif
Signature · 1 line
2.17.1
Quoted 9 lines · ----- On Feb 4, 2019, at 4:28 PM, Mathieu Desnoyers…
Register rseq(2) TLS for each thread (including main), and unregister for each thread (excluding main). "rseq" stands for Restartable Sequences.
See the rseq(2) man page proposed here:
https://lkml.org/lkml/2018/9/19/647This patch is based on glibc-2.29. The rseq(2) system call was merged into Linux 4.18.
I recently stumbled on the thread about introduction of the getcpu(2) wrapper in glibc, which returns both the current cpu_id and the current node_id:
https://public-inbox.org/libc-alpha/[email protected]/
It would be great if we could speed it up using Restartable Sequences.
At the moment, struct rseq only holds the cpu_id. I foresee that we'll want to add support for a "node_id" to rseq at some point in a near future. It's worthwhile to go through the exercise of looking at how this change can be introduced considering all ABIs involved.
We cannot change the size of struct rseq, because the kernel validates that the rseq_len received as sys_rseq parameter == sizeof(*rseq). Considering that various libraries/applications need to agree on the exact size/content of this structure as a userspace ABI anyway, it's a good thing that it's fixed and can never change.
One viable solution would be to introduce a new rseq flag to the kernel UAPI, e.g.
RSEQ_FLAG_NODE_ID
which could be used to register a u32 __rseq_abi_node_id TLS. It would be exposed as a new public glibc symbol. Its unregistration would be done using (RSEQ_FLAG_NODE_ID | RSEQ_FLAG_UNREGISTER).
The type of the "rseq" argument expected by sys_rseq would become __u32 __user * when the RSEQ_FLAG_NODE_ID is specified.
This would allow glibc to use rseq to implement getcpu() whenever it runs on a kernel that supports rseq RSEQ_FLAG_NODE_ID.
Thoughts ?
Thanks,
Mathieu
Quoted 1,149 lines
Signed-off-by Mathieu Desnoyers <[email protected]>CC Carlos O'Donell <[email protected]>CC Florian Weimer <[email protected]>CC Joseph Myers <[email protected]>CC Szabolcs Nagy <[email protected]>CC Thomas Gleixner <[email protected]>CC Ben Maurer <[email protected]>CC Peter Zijlstra <[email protected]>CC "Paul E. McKenney" <[email protected]>CC Boqun Feng <[email protected]>CC Will Deacon <[email protected]>CC Dave Watson <[email protected]>CC Paul Turner <[email protected]>CC Rich Felker <[email protected]>---
Changes since v1:
- Move__rseq_refcountto an extra field at the end of__rseq_abito eliminate one symbol.All libraries/programs which try to register rseq (glibc, early-adopter applications, early-adopter libraries) should use the rseq refcount. It becomes part of the ABI within a user-space process, but it's not part of the ABI shared with the kernel per se.
- Restructure how this code is organized so glibc keeps building on non-Linux targets.
- Use non-weak symbol for
__rseq_abi.- Move rseq registration/unregistration implementation into its own
nptl/rseq.ccompile unit.- Move
__rseq_abisymbol under GLIBC_2.29.Changes since v2:
- Move__rseq_refcountto its own symbol, which is less ugly than trying to play tricks with the rseq uapi.
- Move__rseq_abifrom nptl to csu (C start up), so it can be used across glibc, including memory allocator andsched_getcpu(). The__rseq_refcountsymbol is kept in nptl, because there is no reason to use it elsewhere in glibc.Changes since v3:
- Set__rseq_refcountTLS to 1 on register/set to 0 on unregister because glibc is the first/last user.
- Unconditionally register/unregister rseq at thread start/exit, because glibc is the first/last user.
- Add missing abilist items.
- Rebase on glibc master commita502c5294.
- Add NEWS entry.Changes since v4:
- Do not use "weak" symbols for__rseq_abiand__rseq_refcount. Based on "System V Application Binary Interface", weak only affects the link editor, not the dynamic linker.
- Install a newsys/rseq.hsystem header on Linux, which contains theRSEQ_SIGdefinition,__rseq_abideclaration and__rseq_refcountdeclaration. Move those definition/declarations fromrseq-internal.hto the installedsys/rseq.hheader.
- Considering that rseq is only available on Linux, movecsu/rseq.ctosysdeps/unix/sysv/linux/rseq-sym.c.
- Move__rseq_refcountfromnptl/rseq.ctosysdeps/unix/sysv/linux/rseq-sym.c, so it is only defined on Linux.
- Move both ABI definitions for__rseq_abiand__rseq_refcountto sysdeps/unix/sysv/linux/Versions, so they only appear on Linux.
- Document__rseq_abiand__rseq_refcountvolatile.
- Document theRSEQ_SIGsignature define.
- Move registration functions fromrseq.ctorseq-internal.hstatic inline functions. Introduce empty stubs inmisc/rseq-internal.h, which can be overridden by architecture code insysdeps/unix/sysv/linux/rseq-internal.h.
- Rename__rseq_register_current_threadand__rseq_unregister_current_threadtorseq_register_current_threadandrseq_unregister_current_thread, now that those are only visible as internal static inline functions.
- Invokerseq_register_current_thread()fromlibc-start.cLIBC_START_MAINrather than nptl init, so applications not linked against libpthread.so have rseq registered for theirmain()thread. Note that it is invoked separately for SHARED and !SHARED builds.Changes since v5:
- Replace__rseq_refcountby__rseq_lib_abi, which contains two
uint32_t:register_stateand refcount. The "register_state" field allows inhibiting rseq registration from signal handlers nested on top of glibc registration and occuring after rseq unregistration by glibc.
- Introduce enumrseq_register_state, which contains the states allowed for the structrseq_lib_abiregister_statefield.Changes since v6:
- Introducebits/rseq.hto defineRSEQ_SIGfor each architecture. The genericbits/rseq.hdoes not defineRSEQ_SIG, meaning that each architecture implementing rseq needs to implementbits/rseq.h.
- Rename enum itemRSEQ_REGISTER_NESTEDtoRSEQ_REGISTER_ONGOING.
- Port to glibc-2.29.
---NEWS | 11 +++ csu/libc-start.c | 12 ++- misc/Makefile | 3 +- misc/rseq-internal.h | 34 +++++++ nptl/pthread_create.c | 9 ++ sysdeps/unix/sysv/linux/Makefile | 4 +- sysdeps/unix/sysv/linux/Versions | 4 + sysdeps/unix/sysv/linux/aarch64/bits/rseq.h | 24 +++++ sysdeps/unix/sysv/linux/aarch64/libc.abilist | 2 + sysdeps/unix/sysv/linux/alpha/libc.abilist | 2 + sysdeps/unix/sysv/linux/arm/bits/rseq.h | 24 +++++ sysdeps/unix/sysv/linux/arm/libc.abilist | 2 + sysdeps/unix/sysv/linux/bits/rseq.h | 24 +++++ sysdeps/unix/sysv/linux/hppa/libc.abilist | 2 + sysdeps/unix/sysv/linux/i386/libc.abilist | 2 + sysdeps/unix/sysv/linux/ia64/libc.abilist | 2 + .../sysv/linux/m68k/coldfire/libc.abilist | 2 + .../unix/sysv/linux/m68k/m680x0/libc.abilist | 2 + .../unix/sysv/linux/microblaze/libc.abilist | 2 + sysdeps/unix/sysv/linux/mips/bits/rseq.h | 24 +++++ .../sysv/linux/mips/mips32/fpu/libc.abilist | 2 + .../sysv/linux/mips/mips32/nofpu/libc.abilist | 2 + .../sysv/linux/mips/mips64/n32/libc.abilist | 2 + .../sysv/linux/mips/mips64/n64/libc.abilist | 2 + sysdeps/unix/sysv/linux/nios2/libc.abilist | 2 + sysdeps/unix/sysv/linux/powerpc/bits/rseq.h | 24 +++++ .../linux/powerpc/powerpc32/fpu/libc.abilist | 2 + .../powerpc/powerpc32/nofpu/libc.abilist | 2 + .../linux/powerpc/powerpc64/be/libc.abilist | 2 + .../linux/powerpc/powerpc64/le/libc.abilist | 2 + .../unix/sysv/linux/riscv/rv64/libc.abilist | 2 + sysdeps/unix/sysv/linux/rseq-internal.h | 91 +++++++++++++++++++ sysdeps/unix/sysv/linux/rseq-sym.c | 54 +++++++++++ sysdeps/unix/sysv/linux/s390/bits/rseq.h | 24 +++++ .../unix/sysv/linux/s390/s390-32/libc.abilist | 2 + .../unix/sysv/linux/s390/s390-64/libc.abilist | 2 + sysdeps/unix/sysv/linux/sh/libc.abilist | 2 + .../sysv/linux/sparc/sparc32/libc.abilist | 2 + .../sysv/linux/sparc/sparc64/libc.abilist | 2 + sysdeps/unix/sysv/linux/sys/rseq.h | 65 +++++++++++++ sysdeps/unix/sysv/linux/x86/bits/rseq.h | 24 +++++ .../unix/sysv/linux/x86_64/64/libc.abilist | 2 + .../unix/sysv/linux/x86_64/x32/libc.abilist | 2 + 43 files changed, 501 insertions(+), 6 deletions(-)create mode 100644
misc/rseq-internal.h
create mode 100644sysdeps/unix/sysv/linux/aarch64/bits/rseq.hcreate mode 100644sysdeps/unix/sysv/linux/arm/bits/rseq.hcreate mode 100644sysdeps/unix/sysv/linux/bits/rseq.hcreate mode 100644sysdeps/unix/sysv/linux/mips/bits/rseq.hcreate mode 100644sysdeps/unix/sysv/linux/powerpc/bits/rseq.hcreate mode 100644sysdeps/unix/sysv/linux/rseq-internal.hcreate mode 100644sysdeps/unix/sysv/linux/rseq-sym.ccreate mode 100644sysdeps/unix/sysv/linux/s390/bits/rseq.hcreate mode 100644sysdeps/unix/sysv/linux/sys/rseq.hcreate mode 100644sysdeps/unix/sysv/linux/x86/bits/rseq.hNEWS +0
-0@@ -5,6 +5,17 @@ See the end for copying conditions.Please send GNU C library bug reports via <https://sourceware.org/bugzilla/>
using `glibc' in the "product" field.NEWS +11
-0+Version 2.30 + +Major new features: + +* Support for automatically registering threads with the Linux rseq(2) + system call has been added. This system call is implemented starting + from Linux 4.18. In order to be activated, it requires that glibc is built + against kernel headers that include this system call, and that glibc + detects availability of that system call at runtime. + +Version 2.29
Major new features:
csu/libc-start.c +5
-1@@ -22,6 +22,7 @@#include <ldsodefs.h> #include <exit-thread.h> #include <libc-internal.h> +#include <rseq-internal.h> #include <elf/dl-tunables.h> @@ -140,7 +141,10 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up; -#ifndef SHARED +#ifdef SHARED +/* Register rseq ABI to the kernel. */ + (void )rseq_register_current_thread (); +#else _dl_relocate_static_pie ();char **ev = &argv[argc + 1];csu/libc-start.c +3
-0@@ -218,6 +222,9 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), } # endif +/* Register rseq ABI to the kernel. */ + (void )rseq_register_current_thread (); +/* Initialize libpthread if linked in. */ if (__pthread_initialize_minimal !=NULL )__pthread_initialize_minimal ();csu/libc-start.c +1
-2@@ -230,8 +237,7 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), # else __pointer_chk_guard_local = pointer_chk_guard;# endif - -#endif /* !SHARED */ +#endif /* Register the destructor of the dynamic linker if there is any. */ if (
__glibc_likely(rtld_fini!= NULL))misc/Makefile +2
-1@@ -36,7 +36,8 @@ headers := sys/uio.h bits/uio-ext.h bits/uio_lim.h \ syslog.h sys/syslog.h \ bits/syslog.h bits/syslog-ldbl.h bits/syslog-path.h bits/error.h \ bits/select2.h bits/hwcap.h sys/auxv.h \ - sys/sysmacros.h bits/sysmacros.h bits/types/struct_iovec.h + sys/sysmacros.h bits/sysmacros.h bits/types/struct_iovec.h \ + rseq-internal.h routines := brk sbrk sstk ioctl \ readv writev preadv preadv64 pwritev pwritev64 \misc/rseq-internal.h new file +34
-0@@ -0,0 +1,34 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2018. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef RSEQ_INTERNAL_H +#define RSEQ_INTERNAL_H + +static inline int +rseq_register_current_thread (void ) +{ +return -1 ; +} + +static inline int +rseq_unregister_current_thread (void ) +{ +return -1 ; +} + +#endif /* rseq-internal.h */ nptl/pthread_create.c +1
-0@@ -33,6 +33,7 @@#include <default-sched.h> #include <futex-internal.h> #include <tls-setup.h> +#include <rseq-internal.h> #include "libioP.h" #include <shlib-compat.h> @@ -378,6 +379,7 @@ __free_tcb (struct pthread *pd)
START_THREAD_DEFN
{
struct pthread *pd =START_THREAD_SELF;
+ boolhas_rseq= false;#if
HP_TIMING_AVAIL
/* Remember the time when the thread was started. */nptl/pthread_create.c +7
-0@@ -396,6 +398,9 @@ START_THREAD_DEFNif (__glibc_unlikely (atomic_exchange_acq (&pd->setxid_futex,0 ) ==-2 ))futex_wake (&pd->setxid_futex,1 ,FUTEX_PRIVATE ); +/* Register rseq TLS to the kernel. */ + has_rseq = !rseq_register_current_thread (); +#ifdef __NR_set_robust_list# ifndef __ASSUME_SET_ROBUST_LISTif (__set_robust_list_avail >=0 )@@ -573,6 +578,10 @@ START_THREAD_DEFN }#endif +/* Unregister rseq TLS from kernel. */ +if (has_rseq &&rseq_unregister_current_thread ()) +abort (); +advise_stack_range (pd->stackblock, pd->stackblock_size, (uintptr_t ) pd, pd->guardsize);sysdeps/unix/sysv/linux/Makefile +1
-1@@ -1,5 +1,5 @@ ifeq ($(subdir),csu) -sysdep_routines += errno-loc +sysdep_routines += errno-loc rseq-symendif
ifeq ($(subdir),assert)
sysdeps/unix/sysv/linux/Makefile +1
-1@@ -48,7 +48,7 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \ bits/termios-c_iflag.h bits/termios-c_oflag.h \ bits/termios-baud.h bits/termios-c_cflag.h \ bits/termios-c_lflag.h bits/termios-tcflow.h \ - bits/termios-misc.h + bits/termios-misc.h sys/rseq.h bits/rseq.h tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \sysdeps/unix/sysv/linux/Versions +4
-0@@ -174,6 +174,10 @@ libc { GLIBC_2.29 { getcpu; } + GLIBC_2.30 { + __rseq_abi; + __rseq_lib_abi; + } GLIBC_PRIVATE { # functions used in other libraries __syscall_rt_sigqueueinfo;sysdeps/unix/sysv/linux/aarch64/bits/rseq.h new file +24
-0@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0xd428bc00/* BRK #0x45E0. */ sysdeps/unix/sysv/linux/aarch64/libc.abilist +0
-0@@ -2141,3 +2141,5 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/aarch64/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8sysdeps/unix/sysv/linux/alpha/libc.abilist +0
-0@@ -2036,6 +2036,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/alpha/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/arm/bits/rseq.h new file +24
-0@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053sysdeps/unix/sysv/linux/arm/libc.abilist +0
-0@@ -126,6 +126,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/arm/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.4
_ExitF
GLIBC_2.4 _IO_2_1_stderr_ D0xa0
GLIBC_2.4 _IO_2_1_stdin_ D0xa0sysdeps/unix/sysv/linux/bits/rseq.h new file +24
-0@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Each architecture supporting rseq should define RSEQ_SIG as a 32-bit +signature inserted before each rseq abort label in the code section. */ sysdeps/unix/sysv/linux/hppa/libc.abilist +0
-0@@ -1883,6 +1883,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/hppa/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/i386/libc.abilist +0
-0@@ -2048,6 +2048,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/i386/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/ia64/libc.abilist +0
-0@@ -1917,6 +1917,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/ia64/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist +0
-0@@ -127,6 +127,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.4
_ExitF
GLIBC_2.4 _IO_2_1_stderr_ D0x98
GLIBC_2.4 _IO_2_1_stdin_ D0x98sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist +0
-0@@ -1992,6 +1992,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/microblaze/libc.abilist +0
-0@@ -2133,3 +2133,5 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/microblaze/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8sysdeps/unix/sysv/linux/mips/bits/rseq.h new file +24
-0@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist +0
-0@@ -1970,6 +1970,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist +0
-0@@ -1968,6 +1968,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist +0
-0@@ -1976,6 +1976,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist +0
-0@@ -1971,6 +1971,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/nios2/libc.abilist +0
-0@@ -2174,3 +2174,5 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/nios2/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8sysdeps/unix/sysv/linux/powerpc/bits/rseq.h new file +24
-0@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist +0
-0@@ -1996,6 +1996,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist +0
-0@@ -2000,6 +2000,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist +0
-0@@ -126,6 +126,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
_ExitF
GLIBC_2.3 _IO_2_1_stderr_ D0xe0
GLIBC_2.3 _IO_2_1_stdin_ D0xe0sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist +0
-0@@ -2231,3 +2231,5 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist +0
-0@@ -2103,3 +2103,5 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/riscv/rv64/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8sysdeps/unix/sysv/linux/rseq-internal.h new file +91
-0@@ -0,0 +1,91 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2018. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef RSEQ_INTERNAL_H +#define RSEQ_INTERNAL_H + +#include <sysdep.h> + +#ifdef __NR_rseq + +#include <errno.h> +#include <sys/rseq.h> + +static inline int +rseq_register_current_thread (void ) +{ +int rc, ret =0 ; +INTERNAL_SYSCALL_DECL (err); + +if (__rseq_abi.cpu_id ==RSEQ_CPU_ID_REGISTRATION_FAILED ) +return -1 ; +/* Temporarily prevent nested signal handlers from registering rseq. */ + __rseq_lib_abi.register_state =RSEQ_REGISTER_ONGOING ; +if (__rseq_lib_abi.refcount ==UINT_MAX ) + { + ret =-1 ; + goto end; + } +if (__rseq_lib_abi.refcount++) + goto end; + rc =INTERNAL_SYSCALL_CALL (rseq, err, &__rseq_abi,sizeof (struct rseq ), +0 ,RSEQ_SIG ); +if (!rc) + goto end; +if (INTERNAL_SYSCALL_ERRNO (rc, err) !=EBUSY ) + __rseq_abi.cpu_id =RSEQ_CPU_ID_REGISTRATION_FAILED ; + ret =-1 ; +end: + __rseq_lib_abi.register_state =RSEQ_REGISTER_ALLOWED ; +return ret; +} + +static inline int +rseq_unregister_current_thread (void ) +{ +int rc, ret =0 ; +INTERNAL_SYSCALL_DECL (err); + +/* Setting __rseq_register_state = RSEQ_REGISTER_EXITING for the rest of the +thread lifetime. Ensures signal handlers nesting just before thread exit +don't try to register rseq. */ + __rseq_lib_abi.register_state =RSEQ_REGISTER_EXITING ; + __rseq_lib_abi.refcount =0 ; + rc =INTERNAL_SYSCALL_CALL (rseq, err, &__rseq_abi,sizeof (struct rseq ), +RSEQ_FLAG_UNREGISTER ,RSEQ_SIG ); +if (!rc) + goto end; + ret =-1 ; +end: +return ret; +} +#else +static inline int +rseq_register_current_thread (void ) +{ +return -1 ; +} + +static inline int +rseq_unregister_current_thread (void ) +{ +return -1 ; +} +#endif + +#endif /* rseq-internal.h */ sysdeps/unix/sysv/linux/rseq-sym.c new file +54
-0@@ -0,0 +1,54 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2018. + +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 +<http://www.gnu.org/licenses/>. */ + +#include <sys/syscall.h> +#include <stdint.h> + +#ifdef __NR_rseq +#include <sys/rseq.h> +#else + +enum rseq_cpu_id_state { +RSEQ_CPU_ID_UNINITIALIZED =-1 , +RSEQ_CPU_ID_REGISTRATION_FAILED =-2 , +}; + +/* linux/rseq.h defines struct rseq as aligned on 32 bytes. The kernel ABI +size is 20 bytes. */ +struct rseq { +uint32_t cpu_id_start; +uint32_t cpu_id; +uint64_t rseq_cs; +uint32_t flags; +} __attribute__ ((aligned (4 *sizeof (uint64_t )))); + +struct rseq_lib_abi +{ +uint32_t register_state; +uint32_t refcount; +}; + +#endif + +/* volatile because fields can be read/updated by the kernel. */ +__threadvolatile struct rseq __rseq_abi = { + .cpu_id =RSEQ_CPU_ID_UNINITIALIZED , +}; + +/* volatile because fields can be read/updated by signal handlers. */ +__threadvolatile struct rseq_lib_abi __rseq_lib_abi;sysdeps/unix/sysv/linux/s390/bits/rseq.h new file +24
-0@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist +0
-0@@ -2005,6 +2005,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/s390/s390-32/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/s390/s390-64/libc.abilist +0
-0@@ -1911,6 +1911,8 @@ GLIBC_2.29 __fentry__ FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/s390/s390-64/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/sh/libc.abilist +0
-0@@ -1887,6 +1887,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/sh/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist +0
-0@@ -1999,6 +1999,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist +0
-0@@ -1940,6 +1940,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/sys/rseq.h new file +65
-0@@ -0,0 +1,65 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +#define _SYS_RSEQ_H 1 + +/* We use the structures declarations from the kernel headers. */ +#include <linux/rseq.h> +/* Architecture-specific rseq signature. */ +#include <bits/rseq.h> +#include <stdint.h> + +enum rseq_register_state +{ +/* Value RSEQ_REGISTER_ALLOWED means it is allowed to update +the refcount field and to register/unregister rseq. */ +RSEQ_REGISTER_ALLOWED =0 , +/* Value RSEQ_REGISTER_ONGOING means a rseq registration is in progress, +so it is temporarily forbidden to update the refcount field or to +register/unregister rseq for this thread or signal handlers nested +on this thread. */ +RSEQ_REGISTER_ONGOING =1 , +/* Value RSEQ_REGISTER_EXITING means it is forbidden to update the +refcount field or to register/unregister rseq for the rest of the +thread's lifetime. */ +RSEQ_REGISTER_EXITING =2 , +}; + +struct rseq_lib_abi +{ +uint32_t register_state;/* enum rseq_register_state. */ +/* The refcount field keeps track of rseq users, so early adopters +of rseq can cooperate amongst each other and with glibc to +share rseq thread registration. The refcount field can only be +updated when allowed by the value of field register_state. +Registering rseq should be performed when incrementing refcount +from 0 to 1, and unregistering rseq should be performed when +decrementing refcount from 1 to 0. */ +uint32_t refcount; +}; + +/* volatile because fields can be read/updated by the kernel. */ +extern __thread volatile struct rseq __rseq_abi +__attribute__ ((tls_model ("initial-exec"))); + +/* volatile because fields can be read/updated by signal handlers. */ +extern __thread volatile struct rseq_lib_abi __rseq_lib_abi +__attribute__ ((tls_model ("initial-exec"))); + +#endif /* sys/rseq.h */ sysdeps/unix/sysv/linux/x86/bits/rseq.h new file +24
-0@@ -0,0 +1,24 @@ +/* Copyright (C) 2019 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by Mathieu Desnoyers <[email protected]>, 2019. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef _SYS_RSEQ_H +# error "Never use <bits/rseq.h> directly; include <sys/rseq.h> instead." +#endif + +/* Signature required before each abort handler code. */ +#define RSEQ_SIG 0x53053053sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +0
-0@@ -1898,6 +1898,8 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/x86_64/64/libc.abilist +2
-0+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8GLIBC_2.3
__ctype_b_locF
GLIBC_2.3__ctype_tolower_locF
GLIBC_2.3__ctype_toupper_locFsysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +0
-0@@ -2149,3 +2149,5 @@ GLIBC_2.28 thrd_yield FGLIBC_2.29 getcpu F
GLIBC_2.29posix_spawn_file_actions_addchdir_npF GLIBC_2.29posix_spawn_file_actions_addfchdir_npFsysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +2
-1+GLIBC_2.30 __rseq_abi T 0x20 +GLIBC_2.30 __rseq_lib_abi T 0x8 --2.17.1
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com