diff options
| author | Florian Weimer <fweimer@redhat.com> | 2019-02-02 15:17:02 +0100 |
|---|---|---|
| committer | Florian Weimer <fweimer@redhat.com> | 2019-02-08 11:27:55 +0100 |
| commit | 1d0fc213824eaa2a8f8c4385daaa698ee8fb7c92 (patch) | |
| tree | a1979a3d4ef860e9f4565aab20cb2549b0a3303e | |
| parent | f289e656ec8221756519a601042bc9fbe1b310fb (diff) | |
| download | glibc-1d0fc213824eaa2a8f8c4385daaa698ee8fb7c92.tar.xz glibc-1d0fc213824eaa2a8f8c4385daaa698ee8fb7c92.zip | |
Linux: Add gettid system call wrapper [BZ #6399]
This commit adds gettid to <unistd.h> on Linux, and not to the
kernel-independent GNU API.
gettid is now supportable on Linux because too many things assume a
1:1 mapping between libpthread threads and kernel threads.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
40 files changed, 388 insertions, 9 deletions
@@ -1,3 +1,73 @@ +2019-01-31 Florian Weimer <fweimer@redhat.com> + + [BZ #6399] + Linux: Add gettid system call wrapper. + * posix/Makefile (headers): Add bits/unistd_ext.h. + * posix/bits/unistd_ext.h: New file. + * posix/unistd.h: Include it. + * manual/process.texi (Process Identification): Document gettid. + * sysdeps/unix/sysv/linux/Makefile [subdir == misc] (tests): Add + tst-gettid, tst-gettid-kill. + (tst-gettid): Link with $(shared-thread-library). + * sysdeps/unix/sysv/linux/Version (GLIBC_2.30): Export gettid. + * sysdeps/unix/sysv/linux/bits/unistd_ext.h: New file. + * sysdeps/unix/sysv/linux/bits/syscalls.list (gettid): Add. + * sysdeps/unix/sysv/linux/bits/tst-gettid.c: New file. + * sysdeps/unix/sysv/linux/bits/tst-gettid-kill.c: Likewise. + * sysdeps/unix/sysv/linux/aarch64/libc.abilist (GLIBC_2.30): + Add gettid. + * sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/arm/libc.abilist (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/csky/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/hppa/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/i386/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/ia64/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/microblaze/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist + (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist + (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist + (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist + (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/nios2/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist + (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist + (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist + (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist + (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/sh/libc.abilist (GLIBC_2.30): Likewise. + * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist (GLIBC_2.30): + Likewise. + * sysdeps/unix/sysv/linux/tst-setgetname.c (gettid): Remove. + 2019-02-07 Florian Weimer <fweimer@redhat.com> * rt/clock-compat.c (COMPAT_REDIRECT): Turn librt forwarders into @@ -12,6 +12,8 @@ Major new features: * The dynamic linker accepts the --preload argument to preload shared objects, in addition to the LD_PRELOAD environment variable. +* On Linux, the gettid function has been added. + Deprecated and removed features, and other changes affecting compatibility: * The functions clock_gettime, clock_getres, clock_settime, diff --git a/manual/process.texi b/manual/process.texi index 652b0001b5..5728bde2cb 100644 --- a/manual/process.texi +++ b/manual/process.texi @@ -228,6 +228,17 @@ The @code{getppid} function returns the process ID of the parent of the current process. @end deftypefun +@deftypefun pid_t gettid (void) +@standards{Linux, unistd.h} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +The @code{gettid} function returns the thread ID of the current +thread. The returned value is obtained from the Linux kernel and is +not subject to caching. See the discussion of thread IDs above, +especially regarding reuse of the IDs of threads which have exited. + +This function is specific to Linux. +@end deftypefun + @node Creating a Process @section Creating a Process diff --git a/posix/Makefile b/posix/Makefile index 873947f72e..93c3a290d7 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -31,7 +31,8 @@ headers := sys/utsname.h sys/times.h sys/wait.h sys/types.h unistd.h \ bits/local_lim.h tar.h bits/utsname.h bits/confname.h \ bits/waitflags.h bits/waitstatus.h sys/unistd.h sched.h \ bits/sched.h bits/cpu-set.h re_comp.h wait.h bits/environments.h \ - cpio.h spawn.h bits/unistd.h bits/types/struct_sched_param.h + cpio.h spawn.h bits/unistd.h bits/types/struct_sched_param.h \ + bits/unistd_ext.h routines := \ uname \ diff --git a/posix/bits/unistd_ext.h b/posix/bits/unistd_ext.h new file mode 100644 index 0000000000..d6e88f3bd4 --- /dev/null +++ b/posix/bits/unistd_ext.h @@ -0,0 +1,21 @@ +/* System-specific extensions of <unistd.h>, generic version. + Copyright (C) 2019 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 + <http://www.gnu.org/licenses/>. */ + +#ifndef _UNISTD_H +# error "Never include <bits/unistd_ext.h> directly; use <unistd.h> instead." +#endif diff --git a/posix/unistd.h b/posix/unistd.h index f67452122b..55a989f7bb 100644 --- a/posix/unistd.h +++ b/posix/unistd.h @@ -1166,6 +1166,9 @@ int getentropy (void *__buffer, size_t __length) __wur; # include <bits/unistd.h> #endif +/* System-specific extensions. */ +#include <bits/unistd_ext.h> + __END_DECLS #endif /* unistd.h */ diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 5f8c2c7c7d..52ac6ad484 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -53,10 +53,9 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \ test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \ - tst-rlimit-infinity tst-ofdlocks + tst-rlimit-infinity tst-ofdlocks tst-gettid tst-gettid-kill tests-internal += tst-ofdlocks-compat - # Generate the list of SYS_* macros for the system calls (__NR_* # macros). The file syscall-names.list contains all possible system # call names, and the generated header file produces SYS_* macros for @@ -114,6 +113,9 @@ $(objpfx)tst-mman-consts.out: ../sysdeps/unix/sysv/linux/tst-mman-consts.py $(CPPFLAGS))" \ < /dev/null > $@ 2>&1; $(evaluate-test) +$(objpfx)tst-gettid: $(shared-thread-library) +$(objpfx)tst-gettid-kill: $(shared-thread-library) + endif # $(subdir) == misc ifeq ($(subdir),time) diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions index f1e12d9c69..5166ccff25 100644 --- a/sysdeps/unix/sysv/linux/Versions +++ b/sysdeps/unix/sysv/linux/Versions @@ -174,6 +174,9 @@ libc { GLIBC_2.29 { getcpu; } + GLIBC_2.30 { + gettid; + } GLIBC_PRIVATE { # functions used in other libraries __syscall_rt_sigqueueinfo; diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist index 9c330f325e..f3b44d723f 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist @@ -2141,3 +2141,4 @@ 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 gettid F diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist index f630fa4c6f..fe0de20b2b 100644 --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist @@ -2204,6 +2204,7 @@ GLIBC_2.3.4 setipv4sourcefilter F GLIBC_2.3.4 setsourcefilter F GLIBC_2.3.4 xdr_quad_t F GLIBC_2.3.4 xdr_u_quad_t F +GLIBC_2.30 gettid F GLIBC_2.4 _IO_fprintf F GLIBC_2.4 _IO_printf F GLIBC_2.4 _IO_sprintf F diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist index b96f45590f..f451fefac9 100644 --- a/sysdeps/unix/sysv/linux/arm/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/libc.abilist @@ -126,6 +126,7 @@ 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 gettid F GLIBC_2.4 _Exit F GLIBC_2.4 _IO_2_1_stderr_ D 0xa0 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0 diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h new file mode 100644 index 0000000000..0061172f23 --- /dev/null +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h @@ -0,0 +1,36 @@ +/* System-specific extensions of <unistd.h>, Linux version. + Copyright (C) 2019 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 + <http://www.gnu.org/licenses/>. */ + +#ifndef _UNISTD_H +# error "Never include <bits/unistd_ext.h> directly; use <unistd.h> instead." +#endif + +#ifdef __USE_GNU + +/* Return the kernel thread ID (TID) of the current thread. The + returned value is not subject to caching. Most Linux system calls + accept a TID in place of a PID. Using the TID to change properties + of a thread that has been created using pthread_create can lead to + undefined behavior (comparable to manipulating file descriptors + directly that have not been created explicitly). Note that a TID + uniquely identifies a thread only while this thread is running; a + TID can be reused once a thread has exited, even if the thread is + not detached and has not been joined. */ +extern __pid_t gettid (void) __THROW; + +#endif diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist index 019044c3cd..018d02b414 100644 --- a/sysdeps/unix/sysv/linux/csky/libc.abilist +++ b/sysdeps/unix/sysv/linux/csky/libc.abilist @@ -2085,3 +2085,4 @@ GLIBC_2.29 xdrstdio_create F GLIBC_2.29 xencrypt F GLIBC_2.29 xprt_register F GLIBC_2.29 xprt_unregister F +GLIBC_2.30 gettid F diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist index 088a8ee369..fc3c5d5c27 100644 --- a/sysdeps/unix/sysv/linux/hppa/libc.abilist +++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist @@ -2037,6 +2037,7 @@ GLIBC_2.3.4 setipv4sourcefilter F GLIBC_2.3.4 setsourcefilter F GLIBC_2.3.4 xdr_quad_t F GLIBC_2.3.4 xdr_u_quad_t F +GLIBC_2.30 gettid F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index f7ff2c57b9..f2b04dbbff 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -2203,6 +2203,7 @@ GLIBC_2.3.4 setsourcefilter F GLIBC_2.3.4 vm86 F GLIBC_2.3.4 xdr_quad_t F GLIBC_2.3.4 xdr_u_quad_t F +GLIBC_2.30 gettid F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist index becd8b1033..10ecf2e47c 100644 |
