]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Linux: Add gettid system call wrapper [BZ #6399]
authorFlorian Weimer <fweimer@redhat.com>
Sat, 2 Feb 2019 14:17:02 +0000 (15:17 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 8 Feb 2019 10:27:55 +0000 (11:27 +0100)
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:
ChangeLog
NEWS
manual/process.texi
posix/Makefile
posix/bits/unistd_ext.h [new file with mode: 0644]
posix/unistd.h
sysdeps/unix/sysv/linux/Makefile
sysdeps/unix/sysv/linux/Versions
sysdeps/unix/sysv/linux/aarch64/libc.abilist
sysdeps/unix/sysv/linux/alpha/libc.abilist
sysdeps/unix/sysv/linux/arm/libc.abilist
sysdeps/unix/sysv/linux/bits/unistd_ext.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/csky/libc.abilist
sysdeps/unix/sysv/linux/hppa/libc.abilist
sysdeps/unix/sysv/linux/i386/libc.abilist
sysdeps/unix/sysv/linux/ia64/libc.abilist
sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
sysdeps/unix/sysv/linux/microblaze/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
sysdeps/unix/sysv/linux/nios2/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
sysdeps/unix/sysv/linux/sh/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
sysdeps/unix/sysv/linux/syscalls.list
sysdeps/unix/sysv/linux/tst-gettid-kill.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/tst-gettid.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/tst-setgetname.c
sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist

index 20ff76ab62d4e0b506afb6e04ca8067a31018790..78ea38a0860687135496f87c541375b3aeff6e35 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/NEWS b/NEWS
index 45792f62a99be9c3c60a591fe54a5f49156655fa..0a3b6c7a5a16d4c757d5768b1b4d83de7143bbdd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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,
index 652b0001b5dea709eebfc3f6be16be2a244e20e5..5728bde2cbb20aed6608ad134b32b426c95ffc47 100644 (file)
@@ -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
 
index 873947f72e2c1c5e49728a9366b4ce0c8a8ff03b..93c3a290d79c656e9c70486b650758fb04ae0821 100644 (file)
@@ -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 (file)
index 0000000..d6e88f3
--- /dev/null
@@ -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
index f67452122b0ee518a48a355a3f142c1e24f7cbb3..55a989f7bb41f31163428b0b192fa4e468756e4b 100644 (file)
@@ -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  */
index 5f8c2c7c7dac9e3b61c9389ab2c11e964f70ecc3..52ac6ad4844a6bb90976ffcecc1b60c30019c1c0 100644 (file)
@@ -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)
index f1e12d9c690661507286a5339ca696142aa4b81e..5166ccff25159bd5d4324406383d329a09892cd0 100644 (file)
@@ -174,6 +174,9 @@ libc {
   GLIBC_2.29 {
     getcpu;
   }
+  GLIBC_2.30 {
+    gettid;
+  }
   GLIBC_PRIVATE {
     # functions used in other libraries
     __syscall_rt_sigqueueinfo;
index 9c330f325e32adc2518cf657972ffb8abf88c5e5..f3b44d723f87a800a8d5dd377f4f483c1140f733 100644 (file)
@@ -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
index f630fa4c6fcd6c17cb933c9ca771121354d35e58..fe0de20b2b11c13bbbbe2356930df951dd0b1bad 100644 (file)
@@ -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
index b96f45590f554469aa1a3eab0d16a043c2f49eb8..f451fefac93c56a8a30dc4f8a41ecb2c74d40c1c 100644 (file)
@@ -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 (file)
index 0000000..0061172
--- /dev/null
@@ -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
index 019044c3cdaf1c3852751dc9ac3c92e44a135816..018d02b414444931881c5e88eaac6cc506e96a61 100644 (file)
@@ -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
index 088a8ee3696029001532acc4412298ec8ee14218..fc3c5d5c27049053274d59e729e624ae6211d67b 100644 (file)
@@ -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
index f7ff2c57b91543e9138e40fc89d5da567b70a5ba..f2b04dbbffd9cc9a8d5f4308afb0445639204b3b 100644 (file)
@@ -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
index becd8b103359f8a20cf64547d419a5c61b4fcda4..10ecf2e47ca8c5727d0cdafaecdd9735255316e0 100644 (file)
@@ -2069,6 +2069,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
index 74e42a5209936c276790ddd11e78d4b928dbb7dd..814e81b9d2625513bc767c72aa62bbc6153059ff 100644 (file)
@@ -127,6 +127,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 0x98
 GLIBC_2.4 _IO_2_1_stdin_ D 0x98
index 4af5a74e8a47d619f5661977ea60ff150fd2d51d..68e80372e716fb7c19b400d290cd5d1a1e38c755 100644 (file)
@@ -2146,6 +2146,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
index ccef673fd22f57b5a3d4556c43e663b7b10e4986..31178e4f54e9eb52a24929768c2e00471784ba97 100644 (file)
@@ -2133,3 +2133,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
index 1054bb599e5c1f00b0cd9545c39a4ff28fc242ed..70745736380b90c24ed68f5c3b4e311abe4a2ce7 100644 (file)
@@ -2120,6 +2120,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
index 4f5b5ffebf975663ced26cc099d04a65680b8a9a..154f9c77fc508829ea29a3e92946c55c8482de21 100644 (file)
@@ -2118,6 +2118,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
index 943aee58d443057c08a985e361ae4438167ef4f9..97b8f42d5c4f9c77040649cca8a51e1434103e17 100644 (file)
@@ -2126,6 +2126,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
index 17a5d17ef9e007f0212baf049fc6ca639572c8f0..5b3e85de93e5e798d3ae92a8d96d678318617658 100644 (file)
@@ -2120,6 +2120,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
index 4d62a540fd02701a3ba34d82ce3cf966dda013d2..04a130a81cac2e7a6e20841594aecf8747a10315 100644 (file)
@@ -2174,3 +2174,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
index ecc2d6fa13e3f09713bcf3e4b160e47a8eed9836..d99a83554413981fdf82075db0f06eb1448aef31 100644 (file)
@@ -2164,6 +2164,7 @@ GLIBC_2.3.4 siglongjmp F
 GLIBC_2.3.4 swapcontext 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
index f5830f9c33fc37afb7a1c9e2cbd3f4acf733e675..826772777a046152a23c5e242ebda294b2d9554f 100644 (file)
@@ -2197,6 +2197,7 @@ GLIBC_2.3.4 siglongjmp F
 GLIBC_2.3.4 swapcontext 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
index 633d8f4792987f412d51d12e4db907a07c362191..5aa038971b406d268b4a18bdc252e35d4d1c3cfd 100644 (file)
@@ -2027,6 +2027,7 @@ GLIBC_2.3.4 siglongjmp F
 GLIBC_2.3.4 swapcontext 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
index 2c712636ef13c75cec3ab5146776c95c3a72c6dd..c630d0c37de2132afecf8512dd859c1f8f1abbe2 100644 (file)
@@ -2231,3 +2231,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
index 195bc8b2cf28be1936db8abb2d22662a8df4ec82..da123d3867ac1354a43379fcf2524b876efa8729 100644 (file)
@@ -2103,3 +2103,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
index 334def033c375afe5f8646dca9043c6e717d59f7..361240400cebfafeb978c4a66aff901050fa0518 100644 (file)
@@ -2159,6 +2159,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
index 536f4c4ced282049e84c835e687794f0481158ba..f44f178a086a4c5a6d55061ea064066c7b9c1391 100644 (file)
@@ -2063,6 +2063,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
index 30ae3b6ebb6510f6eecb04eb1e80b21fb4d2166f..24a8f934cb76e6a98e307b681c403d2ae8635fa2 100644 (file)
@@ -2041,6 +2041,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
index 68b107d08058c383a5eb71ca87d28e4c02d00307..37957959e23eb72186dfb1d417dbdd126e4c58a5 100644 (file)
@@ -2153,6 +2153,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
index e5b6a4da50e9295da4ca5db1c66a9ba61c547dc5..0992349b061c5c6ecce563114ea584dffd1bb631 100644 (file)
@@ -2092,6 +2092,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
index e24ea29e352db4ae02e7d001e6e697dc5ab1ed51..544ab5d54aa1c66668dadf78769e83205e4f9111 100644 (file)
@@ -112,3 +112,4 @@ process_vm_writev EXTRA     process_vm_writev i:ipipii process_vm_writev
 memfd_create    EXTRA  memfd_create    i:si    memfd_create
 pkey_alloc     EXTRA   pkey_alloc      i:ii    pkey_alloc
 pkey_free      EXTRA   pkey_free       i:i     pkey_free
+gettid          EXTRA   gettid          Ei:     __gettid       gettid
diff --git a/sysdeps/unix/sysv/linux/tst-gettid-kill.c b/sysdeps/unix/sysv/linux/tst-gettid-kill.c
new file mode 100644 (file)
index 0000000..98a7c27
--- /dev/null
@@ -0,0 +1,129 @@
+/* Verify the interaction of kill and thread groups.
+   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/>.  */
+
+/* This test demonstrates that a signal which is sent to a specified
+   thread ID using the kill function is delivered to the entire thread
+   group (as if it had been sent to the process group).  */
+
+#include <errno.h>
+#include <signal.h>
+#include <support/check.h>
+#include <support/xsignal.h>
+#include <support/xthread.h>
+#include <support/xunistd.h>
+
+/* Signal set containing SIGUSR1.  */
+static sigset_t sigusr1_set;
+
+/* Used to synchronize the threads.  */
+static pthread_barrier_t barrier;
+
+/* TID of the thread to which the signal is sent.  */
+static pid_t target_tid;
+
+/* Thread which is expected to receive the SIGUSR1 signal.  */
+static pthread_t signal_thread;
+
+/* Pipe used to block and terminate the signal thread.  */
+static int pipe_signal[2];
+
+static volatile sig_atomic_t handler_tid;
+
+static void
+sigusr1_handler (int signo)
+{
+  TEST_COMPARE (signo, SIGUSR1);
+  TEST_VERIFY (pthread_self () == signal_thread);
+  TEST_COMPARE (handler_tid, 0);
+  handler_tid = gettid ();
+  TEST_VERIFY (handler_tid > 0);
+  /* Ensure that the read system call in thread_read exits if the
+     signal is delivered before the system call is invoked.  */
+  char ch = 'X';
+  xwrite (pipe_signal[1], &ch, 1);
+}
+
+/* Thread which calls pause without expecting it to return.  The TID
+   of this thread is used as the target in the kill function call.  */
+static void *
+thread_pause_noreturn (void *closure)
+{
+  target_tid = gettid ();
+  TEST_VERIFY (target_tid > 0);
+  xpthread_barrier_wait (&barrier);
+  pause ();
+  FAIL_EXIT1 ("The pause function returned");
+  return NULL;
+}
+
+/* Thread which is expected to receive the signal.  */
+static void *
+thread_read_signal (void *closure)
+{
+  xpthread_sigmask (SIG_UNBLOCK, &sigusr1_set, NULL);
+  xpthread_barrier_wait (&barrier);
+  TEST_VERIFY (target_tid > 0);
+  TEST_VERIFY (gettid () != target_tid);
+  char ch;
+  ssize_t ret = read (pipe_signal[0], &ch, 1);
+  if (ret == 1)
+    /* The signal was delivered before we entered the read system
+       call.  */
+    TEST_COMPARE (ch, 'X');
+  else
+    {
+      /* The signal was delivered while blocked in the read system
+         call.  */
+      TEST_COMPARE (ret, -1);
+      TEST_COMPARE (errno, EINTR);
+    }
+  TEST_COMPARE (handler_tid, gettid ());
+  return NULL;
+}
+
+static int
+do_test (void)
+{
+  /* Block the SIGUSR1 signal in all threads.  */
+  sigemptyset (&sigusr1_set);
+  sigaddset (&sigusr1_set, SIGUSR1);
+  xpthread_sigmask (SIG_BLOCK, &sigusr1_set, NULL);
+
+  xsignal (SIGUSR1, sigusr1_handler);
+  xpipe (pipe_signal);
+
+  xpthread_barrier_init (&barrier, NULL, 3);
+
+  pthread_t target_thread
+    = xpthread_create (NULL, thread_pause_noreturn, NULL);
+  signal_thread = xpthread_create (NULL, thread_read_signal, NULL);
+  xpthread_barrier_wait (&barrier);
+
+  /* Send the SIGUSR1 signal to the thread which has it blocked, and
+     expect it to be delivered to the other thread.  */
+  TEST_COMPARE (kill (target_tid, SIGUSR1), 0);
+
+  xpthread_join (signal_thread);
+  xpthread_cancel (target_thread);
+  xpthread_join (target_thread);
+
+  xpthread_barrier_destroy (&barrier);
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/unix/sysv/linux/tst-gettid.c b/sysdeps/unix/sysv/linux/tst-gettid.c
new file mode 100644 (file)
index 0000000..26b579e
--- /dev/null
@@ -0,0 +1,79 @@
+/* Smoke test for the gettid system call.
+   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/>.  */
+
+#include <support/check.h>
+#include <support/namespace.h>
+#include <support/xthread.h>
+#include <support/xunistd.h>
+
+/* TID of the initial (main) thread.  */
+static pid_t initial_tid;
+
+/* Check that PID and TID are the same in a subprocess.  */
+static void
+subprocess (void *closure)
+{
+  TEST_COMPARE (getpid (), gettid ());
+  TEST_VERIFY (gettid () != initial_tid);
+}
+
+/* Check that the TID changes in a new thread.  */
+static void *
+threadfunc (void *closure)
+{
+  TEST_VERIFY (getpid () != gettid ());
+  TEST_VERIFY (gettid () != initial_tid);
+  return NULL;
+}
+
+/* Check for interactions with vfork.  */
+static void
+test_vfork (void)
+{
+  pid_t proc = vfork ();
+  if (proc == 0)
+    {
+      if (getpid () != gettid ())
+        _exit (1);
+      if (gettid () == initial_tid)
+        _exit (2);
+      _exit (0);
+    }
+  int status;
+  xwaitpid (proc, &status, 0);
+  TEST_COMPARE (status, 0);
+}
+
+static int
+do_test (void)
+{
+  initial_tid = gettid ();
+
+  /* The main thread has the same TID as the PID.  */
+  TEST_COMPARE (getpid (), gettid ());
+
+  test_vfork ();
+
+  support_isolate_in_subprocess (subprocess, NULL);
+
+  xpthread_join (xpthread_create (NULL, threadfunc, NULL));
+
+  return 0;
+}
+
+#include <support/test-driver.c>
index 23184aae20dc4aa740cf4950762ddeeb6bf35bc2..c373e61492eb867414acecfec61c639004aa6413 100644 (file)
    terminator.  */
 #define TASK_COMM_LEN 16
 
-long
-gettid (void)
-{
-    return syscall(__NR_gettid);
-}
-
 /* On Linux we can read this task's name from /proc.  */
 int
 get_self_comm (long tid, char *buf, size_t len)
index 86dfb0c94d66f586aa590cb5b0a9734b6970c18c..af004fcff61a929898dbbce88011aea0cb0b44cc 100644 (file)
@@ -2050,6 +2050,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
index dd688263aa728f84abbf5814b12beaf1739f0fab..84015f0a57a1ed8954e2946d8f937e19a81f6124 100644 (file)
@@ -2149,3 +2149,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