public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
@ 2018-12-05 10:53 Florian Weimer
  2018-12-05 16:20 ` Joseph Myers
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Florian Weimer @ 2018-12-05 10:53 UTC (permalink / raw)
  To: libc-alpha

This commit adds gettid to <unistd.h> on Linux, and not to the
kernel-independent GNU API.

2018-12-05  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.
	* sysdeps/unix/sysv/linux/Makefile [subdir == misc] (tests): Add
	tst-gettid.
	(tst-gettid): Link with $(shared-thread-library).
	* sysdeps/unix/sysv/linux/Version (GLIBC_2.29): 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/aarch64/libc.abilist (GLIBC_2.29):
	Add gettid.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist (GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist (GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/tst-setgetname.c (gettid): Remove.

diff --git a/posix/Makefile b/posix/Makefile
index a8fb1e1839..49d7a91b77 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..8019cfa758
--- /dev/null
+++ b/posix/bits/unistd_ext.h
@@ -0,0 +1,21 @@
+/* System-specific extensions of <unistd.h>, generic version.
+   Copyright (C) 2018 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 a8cf28b5e7..127ed494ce 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 362cf3b950..99884799e6 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -48,7 +48,7 @@ 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
 tests-internal += tst-ofdlocks-compat
 
 
@@ -100,6 +100,8 @@ $(objpfx)tst-sysconf-iov_max: $(objpfx)tst-sysconf-iov_max-uapi.o
 
 $(objpfx)tst-pkey: $(shared-thread-library)
 
+$(objpfx)tst-gettid: $(shared-thread-library)
+
 endif # $(subdir) == misc
 
 ifeq ($(subdir),time)
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 336c13b57d..6b5cd99b51 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -171,6 +171,9 @@ libc {
     mlock2;
     pkey_alloc; pkey_free; pkey_set; pkey_get; pkey_mprotect;
   }
+  GLIBC_2.29 {
+    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 e66c741d04..a9851a9450 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -2138,4 +2138,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index 8df162fe99..b9cdd685e4 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -2033,6 +2033,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index 43c804f9dc..958d9d4f2b 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ 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..5f964bca94
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
@@ -0,0 +1,32 @@
+/* System-specific extensions of <unistd.h>, Linux version.
+   Copyright (C) 2018 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.  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/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 88b01c2e75..ff3656d3bb 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -1880,6 +1880,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index 6d02f31612..9abad3352d 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -2045,6 +2045,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist
index 4249712611..1c1018e84e 100644
--- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
@@ -1914,6 +1914,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index d47b808862..f8f6c42be4 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -124,6 +124,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.4 _Exit F
 GLIBC_2.4 _IO_2_1_stderr_ D 0x98
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index d5e38308be..8d73f730b7 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -1989,6 +1989,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
index 8596b84399..21daf81c03 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
@@ -2130,4 +2130,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 88e0f896d5..0e519f164b 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -1967,6 +1967,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index aff7462c34..da97eae834 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -1965,6 +1965,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 71d82444aa..d522182d71 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -1973,6 +1973,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index de6c53d293..b284b21f78 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -1968,6 +1968,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index e724bab9fb..dbbe729e18 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -2171,4 +2171,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index e9ecbccb71..35231739ea 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -1993,6 +1993,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index da83ea6028..cea0accf60 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -1997,6 +1997,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
index 4535b40d15..55d2d0c621 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
@@ -2228,4 +2228,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
index 65725de4f0..a4962c13a8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
@@ -123,6 +123,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 _Exit F
 GLIBC_2.3 _IO_2_1_stderr_ D 0xe0
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index bbb3c4a8e7..06372f7b97 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -2100,4 +2100,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index e85ac2a178..403f30aa3e 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -2002,6 +2002,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
index d56931022c..c5095fad6f 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
@@ -1908,6 +1908,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 __fentry__ F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
index ff939a15c4..9b4b9328d3 100644
--- a/sysdeps/unix/sysv/linux/sh/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
@@ -1884,6 +1884,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 64fa9e10a5..5c3480af84 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -1996,6 +1996,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index db909d1506..2928506213 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -1937,6 +1937,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index e24ea29e35..544ab5d54a 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -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.c b/sysdeps/unix/sysv/linux/tst-gettid.c
new file mode 100644
index 0000000000..78bbaee4f3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-gettid.c
@@ -0,0 +1,79 @@
+/* Smoke test for the gettid system call.
+   Copyright (C) 2018 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>
diff --git a/sysdeps/unix/sysv/linux/tst-setgetname.c b/sysdeps/unix/sysv/linux/tst-setgetname.c
index b80ff59074..95d8bb9ba4 100644
--- a/sysdeps/unix/sysv/linux/tst-setgetname.c
+++ b/sysdeps/unix/sysv/linux/tst-setgetname.c
@@ -43,12 +43,6 @@
    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)
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 3b175f104b..ae93b8719b 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -1895,6 +1895,7 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.3 __ctype_b_loc F
 GLIBC_2.3 __ctype_tolower_loc F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index 1b57710477..02110bac19 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -2146,4 +2146,5 @@ GLIBC_2.28 thrd_current F
 GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-05 10:53 [PATCH] Linux: Add gettid system call wrapper [BZ #6399] Florian Weimer
@ 2018-12-05 16:20 ` Joseph Myers
  2018-12-05 18:25   ` Florian Weimer
  2018-12-07  8:49 ` Florian Weimer
  2018-12-14 21:11 ` Carlos O'Donell
  2 siblings, 1 reply; 25+ messages in thread
From: Joseph Myers @ 2018-12-05 16:20 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

On Wed, 5 Dec 2018, Florian Weimer wrote:

> This commit adds gettid to <unistd.h> on Linux, and not to the
> kernel-independent GNU API.

This is missing a NEWS entry, and documentation (which seems particularly 
important in this case, to discuss what a tid is and is not and what 
interfaces it can be used with).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-05 16:20 ` Joseph Myers
@ 2018-12-05 18:25   ` Florian Weimer
  2018-12-05 18:30     ` Joseph Myers
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer @ 2018-12-05 18:25 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

* Joseph Myers:

> On Wed, 5 Dec 2018, Florian Weimer wrote:
>
>> This commit adds gettid to <unistd.h> on Linux, and not to the
>> kernel-independent GNU API.
>
> This is missing a NEWS entry,

I plan to add this:

+* On Linux, the gettid function has been added.

> and documentation (which seems particularly 
> important in this case, to discuss what a tid is and is not and what 
> interfaces it can be used with).

I can put more details into the comment:

/* 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.  */

I do not want to contribute to the manual at this point.

I would rather improve the manpages project documentation and clarify
there when a PID is actually a TID and deals with what are essentially
task properties.

Should we have a separate conversation about the future of the manual?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-05 18:25   ` Florian Weimer
@ 2018-12-05 18:30     ` Joseph Myers
  2018-12-07 13:56       ` Carlos O'Donell
  2018-12-10 11:35       ` Florian Weimer
  0 siblings, 2 replies; 25+ messages in thread
From: Joseph Myers @ 2018-12-05 18:30 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

On Wed, 5 Dec 2018, Florian Weimer wrote:

> I do not want to contribute to the manual at this point.

I think additions to the manual should generally be required for adding 
new functions to glibc.

I'm also wondering about adding a testcase that fails if any undocumented 
function is declared in a header unless the lack of documentation for that 
function is XFAILed with reference to an open bug, to make it more obvious 
when documentation is missing from a patch submission.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-05 10:53 [PATCH] Linux: Add gettid system call wrapper [BZ #6399] Florian Weimer
  2018-12-05 16:20 ` Joseph Myers
@ 2018-12-07  8:49 ` Florian Weimer
  2018-12-07 13:28   ` Florian Weimer
  2018-12-14 21:11 ` Carlos O'Donell
  2 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer @ 2018-12-07  8:49 UTC (permalink / raw)
  To: libc-alpha

* Florian Weimer:

> This commit adds gettid to <unistd.h> on Linux, and not to the
> kernel-independent GNU API.
>
> 2018-12-05  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.
> 	* sysdeps/unix/sysv/linux/Makefile [subdir == misc] (tests): Add
> 	tst-gettid.
> 	(tst-gettid): Link with $(shared-thread-library).
> 	* sysdeps/unix/sysv/linux/Version (GLIBC_2.29): Export gettid.
> 	* sysdeps/unix/sysv/linux/bits/unistd_ext.h: New file.

Any comments on the technical approach chosen here?  Is the declaration
in <unistd.h> reasonable?  Is the mechanism to make <unistd.h>
extensible okay?

Or should the prototype go into <sched.h>?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-07  8:49 ` Florian Weimer
@ 2018-12-07 13:28   ` Florian Weimer
  0 siblings, 0 replies; 25+ messages in thread
From: Florian Weimer @ 2018-12-07 13:28 UTC (permalink / raw)
  To: libc-alpha

* Florian Weimer:

> This commit adds gettid to <unistd.h> on Linux, and not to the
> kernel-independent GNU API.
>
> 2018-12-05  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.
> 	* sysdeps/unix/sysv/linux/Makefile [subdir == misc] (tests): Add
> 	tst-gettid.
> 	(tst-gettid): Link with $(shared-thread-library).
> 	* sysdeps/unix/sysv/linux/Version (GLIBC_2.29): Export gettid.
> 	* sysdeps/unix/sysv/linux/bits/unistd_ext.h: New file.

Any comments on the technical approach chosen here?  Is the declaration
in <unistd.h> reasonable?  Is the mechanism to make <unistd.h>
extensible okay?

Or should the prototype go into <sched.h>?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-05 18:30     ` Joseph Myers
@ 2018-12-07 13:56       ` Carlos O'Donell
  2018-12-10 11:35       ` Florian Weimer
  1 sibling, 0 replies; 25+ messages in thread
From: Carlos O'Donell @ 2018-12-07 13:56 UTC (permalink / raw)
  To: Joseph Myers, Florian Weimer; +Cc: libc-alpha

On 12/5/18 1:30 PM, Joseph Myers wrote:
> On Wed, 5 Dec 2018, Florian Weimer wrote:
> 
>> I do not want to contribute to the manual at this point.
> 
> I think additions to the manual should generally be required for adding 
> new functions to glibc.

I agree, even if the documentation is minimal, and you can always ask for
help in writing the manual pages.

> I'm also wondering about adding a testcase that fails if any undocumented 
> function is declared in a header unless the lack of documentation for that 
> function is XFAILed with reference to an open bug, to make it more obvious 
> when documentation is missing from a patch submission.

Agreed.

-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-05 18:30     ` Joseph Myers
  2018-12-07 13:56       ` Carlos O'Donell
@ 2018-12-10 11:35       ` Florian Weimer
  2018-12-10 12:02         ` Christian Brauner
  2018-12-14 20:58         ` Carlos O'Donell
  1 sibling, 2 replies; 25+ messages in thread
From: Florian Weimer @ 2018-12-10 11:35 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

* Joseph Myers:

> On Wed, 5 Dec 2018, Florian Weimer wrote:
>
>> I do not want to contribute to the manual at this point.
>
> I think additions to the manual should generally be required for adding 
> new functions to glibc.

I posted some precursor patches to document thread IDs:

  <https://sourceware.org/ml/libc-alpha/2018-12/msg00236.html>
  <https://sourceware.org/ml/libc-alpha/2018-12/msg00237.html>

Once at least the first one is in, I can add documentation for gettid as
well.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-10 11:35       ` Florian Weimer
@ 2018-12-10 12:02         ` Christian Brauner
  2018-12-10 12:08           ` Florian Weimer
  2018-12-14 20:58         ` Carlos O'Donell
  1 sibling, 1 reply; 25+ messages in thread
From: Christian Brauner @ 2018-12-10 12:02 UTC (permalink / raw)
  To: libc-alpha, Florian Weimer, Joseph Myers

On December 10, 2018 11:46:21 AM GMT+01:00, Florian Weimer <fweimer@redhat.com> wrote:
>* Joseph Myers:
>
>> On Wed, 5 Dec 2018, Florian Weimer wrote:
>>
>>> I do not want to contribute to the manual at this point.
>>
>> I think additions to the manual should generally be required for
>adding 
>> new functions to glibc.
>
>I posted some precursor patches to document thread IDs:
>
>  <https://sourceware.org/ml/libc-alpha/2018-12/msg00236.html>

Florian, if this is not just about POSIX but also about the actual implementation
could you maybe add a section to the manual what happens when:
- the thread-group leader exits
- the thread-group leader becomes a zombie
- whether a thread-group can be reparented
?
Obviously all three are closely related.

Christian

>  <https://sourceware.org/ml/libc-alpha/2018-12/msg00237.html>
>
>Once at least the first one is in, I can add documentation for gettid
>as
>well.
>
>Thanks,
>Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-10 12:02         ` Christian Brauner
@ 2018-12-10 12:08           ` Florian Weimer
  2018-12-10 12:20             ` Christian Brauner
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer @ 2018-12-10 12:08 UTC (permalink / raw)
  To: Christian Brauner; +Cc: libc-alpha, Joseph Myers

* Christian Brauner:

> Florian, if this is not just about POSIX but also about the actual
> implementation could you maybe add a section to the manual what
> happens when:

> - the thread-group leader exits
> - the thread-group leader becomes a zombie
> - whether a thread-group can be reparented
> ?
> Obviously all three are closely related.

I lack the technical expertise in this area to do this, but input is
welcome.  I can probably come up with wording.  Some of this should
perhaps go to the man-pages project because I think the glibc manual
should document only cases which are possible to observe with the glibc
implementation (with NPTL using CLONE_THREAD etc.).

I think we really need to document the different effects of returning
from main (or calling exit directly) on the one hand, and calling
pthread_exit from the main thread on the other.  Some of the thread
group behavior could be included in that.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-10 12:08           ` Florian Weimer
@ 2018-12-10 12:20             ` Christian Brauner
  0 siblings, 0 replies; 25+ messages in thread
From: Christian Brauner @ 2018-12-10 12:20 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha, Joseph Myers

On December 10, 2018 1:02:46 PM GMT+01:00, Florian Weimer <fweimer@redhat.com> wrote:
>* Christian Brauner:
>
>> Florian, if this is not just about POSIX but also about the actual
>> implementation could you maybe add a section to the manual what
>> happens when:
>
>> - the thread-group leader exits
>> - the thread-group leader becomes a zombie
>> - whether a thread-group can be reparented
>> ?
>> Obviously all three are closely related.
>
>I lack the technical expertise in this area to do this, but input is
>welcome.  I can probably come up with*

*If* [sic!] pidfd_send_signal() gets in I have
follow up patches that do allow sending signals to process groups and threads.
I've been looking into the exact behavior
of thread-groups and process groups
so I can spend some time documenting it.
I will have to write this down for myself anyway. (If I haven't made it clear: that's a big *if* on whether signaling via fds lands).

> wording.  Some of this should
>perhaps go to the man-pages project because I think the glibc manual
>should document only cases which are possible to observe with the glibc
>implementation (with NPTL using CLONE_THREAD etc.).
>
>I think we really need to document the different effects of returning
>from main (or calling exit directly) on the one hand, and calling
>pthread_exit from the main thread on the other.  Some of the thread
>group behavior could be included in that.

Very much agreed!

Thanks for all the work!
Christian

>
>Thanks,
>Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-10 11:35       ` Florian Weimer
  2018-12-10 12:02         ` Christian Brauner
@ 2018-12-14 20:58         ` Carlos O'Donell
  1 sibling, 0 replies; 25+ messages in thread
From: Carlos O'Donell @ 2018-12-14 20:58 UTC (permalink / raw)
  To: Florian Weimer, Joseph Myers; +Cc: libc-alpha

On 12/10/18 5:46 AM, Florian Weimer wrote:
> * Joseph Myers:
> 
>> On Wed, 5 Dec 2018, Florian Weimer wrote:
>>
>>> I do not want to contribute to the manual at this point.
>>
>> I think additions to the manual should generally be required for adding 
>> new functions to glibc.
> 
> I posted some precursor patches to document thread IDs:
> 
>   <https://sourceware.org/ml/libc-alpha/2018-12/msg00236.html>
>   <https://sourceware.org/ml/libc-alpha/2018-12/msg00237.html>
> 
> Once at least the first one is in, I can add documentation for gettid as
> well.

I have reviewed both. The first I think is OK now, the second needs some
iteration.

-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-05 10:53 [PATCH] Linux: Add gettid system call wrapper [BZ #6399] Florian Weimer
  2018-12-05 16:20 ` Joseph Myers
  2018-12-07  8:49 ` Florian Weimer
@ 2018-12-14 21:11 ` Carlos O'Donell
  2018-12-15 14:18   ` Florian Weimer
  2 siblings, 1 reply; 25+ messages in thread
From: Carlos O'Donell @ 2018-12-14 21:11 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

On 12/5/18 5:53 AM, Florian Weimer wrote:
> This commit adds gettid to <unistd.h> on Linux, and not to the
> kernel-independent GNU API.

NEWS:

+* On Linux, the gettid function has been added.

OK.

Overall this looks good to me, regarding unistd_ext.h, that also looks
OK to me and is an internal implementation detail we can refine if we
find commonality among other headers and a different structure appears
that we like better.

This patch needs a manual entry for gettid. Post a v2 with that and I
can go ahead and ACK this, conditional on the other 2 manual patches
going in, then we'll have:

* Documentation for a tid.
* Documentation for sched_* issues.
* Wrapper and documentation for gettid.

That would be all we need and we'd have a new wrapper for gettid().

> 2018-12-05  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.
> 	* sysdeps/unix/sysv/linux/Makefile [subdir == misc] (tests): Add
> 	tst-gettid.
> 	(tst-gettid): Link with $(shared-thread-library).
> 	* sysdeps/unix/sysv/linux/Version (GLIBC_2.29): 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/aarch64/libc.abilist (GLIBC_2.29):
> 	Add gettid.
[snip abilist]

> 	* sysdeps/unix/sysv/linux/tst-setgetname.c (gettid): Remove.
> 
> diff --git a/posix/Makefile b/posix/Makefile
> index a8fb1e1839..49d7a91b77 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

OK.

>  
>  routines :=								      \
>  	uname								      \
> diff --git a/posix/bits/unistd_ext.h b/posix/bits/unistd_ext.h
> new file mode 100644
> index 0000000000..8019cfa758
> --- /dev/null
> +++ b/posix/bits/unistd_ext.h
> @@ -0,0 +1,21 @@
> +/* System-specific extensions of <unistd.h>, generic version.
> +   Copyright (C) 2018 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

OK.

> diff --git a/posix/unistd.h b/posix/unistd.h
> index a8cf28b5e7..127ed494ce 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>

OK. I think this idea in general is OK. We have used types/foo.h for type split out
from headers, but have not generalized splitting out extensions like this.

> +
>  __END_DECLS
>  
>  #endif /* unistd.h  */
> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
> index 362cf3b950..99884799e6 100644
> --- a/sysdeps/unix/sysv/linux/Makefile
> +++ b/sysdeps/unix/sysv/linux/Makefile
> @@ -48,7 +48,7 @@ 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

OK.

>  tests-internal += tst-ofdlocks-compat
>  
>  
> @@ -100,6 +100,8 @@ $(objpfx)tst-sysconf-iov_max: $(objpfx)tst-sysconf-iov_max-uapi.o
>  
>  $(objpfx)tst-pkey: $(shared-thread-library)
>  
> +$(objpfx)tst-gettid: $(shared-thread-library)

OK.

> +
>  endif # $(subdir) == misc
>  
>  ifeq ($(subdir),time)
> diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
> index 336c13b57d..6b5cd99b51 100644
> --- a/sysdeps/unix/sysv/linux/Versions
> +++ b/sysdeps/unix/sysv/linux/Versions
> @@ -171,6 +171,9 @@ libc {
>      mlock2;
>      pkey_alloc; pkey_free; pkey_set; pkey_get; pkey_mprotect;
>    }
> +  GLIBC_2.29 {
> +    gettid;
> +  }

OK.

>    GLIBC_PRIVATE {
>      # functions used in other libraries
>      __syscall_rt_sigqueueinfo;

[snip ablist diffs]

> 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..5f964bca94
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
> @@ -0,0 +1,32 @@
> +/* System-specific extensions of <unistd.h>, Linux version.
> +   Copyright (C) 2018 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

OK, makse sense to be under USE_GNU.

> +
> +/* Return the kernel thread ID (TID) of the current thread.  The
> +   returned value is not subject to caching.  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;

OK.

> +
> +#endif

[snip abilist diffs]

> diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
> index e24ea29e35..544ab5d54a 100644
> --- a/sysdeps/unix/sysv/linux/syscalls.list
> +++ b/sysdeps/unix/sysv/linux/syscalls.list
> @@ -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

OK.

> diff --git a/sysdeps/unix/sysv/linux/tst-gettid.c b/sysdeps/unix/sysv/linux/tst-gettid.c
> new file mode 100644
> index 0000000000..78bbaee4f3
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tst-gettid.c
> @@ -0,0 +1,79 @@
> +/* Smoke test for the gettid system call.
> +   Copyright (C) 2018 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);

OK.

> +}
> +
> +/* Check that the TID changes in a new thread.  */
> +static void *
> +threadfunc (void *closure)
> +{
> +  TEST_VERIFY (getpid () != gettid ());
> +  TEST_VERIFY (gettid () != initial_tid);

OK.

> +  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);

OK.

> +      _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));

OK.

> +
> +  return 0;
> +}
> +
> +#include <support/test-driver.c>
> diff --git a/sysdeps/unix/sysv/linux/tst-setgetname.c b/sysdeps/unix/sysv/linux/tst-setgetname.c
> index b80ff59074..95d8bb9ba4 100644
> --- a/sysdeps/unix/sysv/linux/tst-setgetname.c
> +++ b/sysdeps/unix/sysv/linux/tst-setgetname.c
> @@ -43,12 +43,6 @@
>     terminator.  */
>  #define TASK_COMM_LEN 16
>  
> -long
> -gettid (void)
> -{
> -    return syscall(__NR_gettid);
> -}

OK.

> -
>  /* On Linux we can read this task's name from /proc.  */
>  int
>  get_self_comm (long tid, char *buf, size_t len)

[snip abilist diffs]


-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-14 21:11 ` Carlos O'Donell
@ 2018-12-15 14:18   ` Florian Weimer
  2018-12-15 14:37     ` Andreas Schwab
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer @ 2018-12-15 14:18 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha

* Carlos O'Donell:

> Overall this looks good to me, regarding unistd_ext.h, that also looks
> OK to me and is an internal implementation detail we can refine if we
> find commonality among other headers and a different structure appears
> that we like better.

Thanks.

> This patch needs a manual entry for gettid. Post a v2 with that and I
> can go ahead and ACK this, conditional on the other 2 manual patches
> going in, then we'll have:
>
> * Documentation for a tid.
> * Documentation for sched_* issues.

The sched_* update is not strictly necessary, I think.  But I've posted
an updated patch as well.

> * Wrapper and documentation for gettid.
>
> That would be all we need and we'd have a new wrapper for gettid().

I've also added a new test case which demonstrates the thread group
behavior.

Thanks,
Florian

-----
This commit adds gettid to <unistd.h> on Linux, and not to the
kernel-independent GNU API.

2018-12-15  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.29): 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.29):
	Add gettid.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist (GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
	(GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist (GLIBC_2.29): Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist (GLIBC_2.29):
	Likewise.
	* sysdeps/unix/sysv/linux/tst-setgetname.c (gettid): Remove.

diff --git a/NEWS b/NEWS
index ae80818df4..02d649517a 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,8 @@ Major new features:
   incosistent mutex state after fork call in multithread environment.
   In both popen and system there is no direct access to user-defined mutexes.
 
+* On Linux, the gettid function has been added.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * The glibc.tune tunable namespace has been renamed to glibc.cpu and the
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 d5a6844c88..0b7d9dbe61 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..8019cfa758
--- /dev/null
+++ b/posix/bits/unistd_ext.h
@@ -0,0 +1,21 @@
+/* System-specific extensions of <unistd.h>, generic version.
+   Copyright (C) 2018 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 a8cf28b5e7..127ed494ce 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 da44c274c6..705dd5ea5e 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -48,10 +48,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
@@ -100,6 +99,9 @@ $(objpfx)tst-sysconf-iov_max: $(objpfx)tst-sysconf-iov_max-uapi.o
 
 $(objpfx)tst-pkey: $(shared-thread-library)
 
+$(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..936a0eb411 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -173,6 +173,7 @@ libc {
   }
   GLIBC_2.29 {
     getcpu;
+    gettid;
   }
   GLIBC_PRIVATE {
     # functions used in other libraries
diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
index 9c330f325e..fb58cdca55 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist
@@ -2139,5 +2139,6 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index f630fa4c6f..5df9a93aac 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -2034,6 +2034,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/arm/libc.abilist b/sysdeps/unix/sysv/linux/arm/libc.abilist
index b96f45590f..e912eb48ee 100644
--- a/sysdeps/unix/sysv/linux/arm/libc.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libc.abilist
@@ -124,6 +124,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.4 _Exit F
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..8d7a8a07d0
--- /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) 2018 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/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist
index 088a8ee369..1289f14dc1 100644
--- a/sysdeps/unix/sysv/linux/hppa/libc.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist
@@ -1881,6 +1881,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist
index f7ff2c57b9..d020c28039 100644
--- a/sysdeps/unix/sysv/linux/i386/libc.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libc.abilist
@@ -2046,6 +2046,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist
index becd8b1033..d9256fbafd 100644
--- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
@@ -1915,6 +1915,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index 74e42a5209..54ef1de463 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -125,6 +125,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.4 _Exit F
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index 4af5a74e8a..4736785bfa 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -1990,6 +1990,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
index ccef673fd2..b1dd5e229c 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
@@ -2131,5 +2131,6 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 1054bb599e..bcbeb3e116 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -1968,6 +1968,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index 4f5b5ffebf..e830ba91ff 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -1966,6 +1966,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 943aee58d4..098e54210a 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -1974,6 +1974,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index 17a5d17ef9..f53d2b1344 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -1969,6 +1969,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index 4d62a540fd..a71dd48e57 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -2172,5 +2172,6 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index ecc2d6fa13..4ff4d1648a 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -1994,6 +1994,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index f5830f9c33..14f33b00a1 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -1998,6 +1998,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
index 633d8f4792..ff68442d3c 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
@@ -124,6 +124,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 _Exit F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
index 2c712636ef..f72cda8896 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
@@ -2229,5 +2229,6 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index 195bc8b2cf..2f1e7fef66 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -2101,5 +2101,6 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index 334def033c..5b2dfc68ff 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -2003,6 +2003,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
index 536f4c4ced..92a3f82436 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
@@ -1909,6 +1909,7 @@ GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 __fentry__ F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
index 30ae3b6ebb..ca87cfc81f 100644
--- a/sysdeps/unix/sysv/linux/sh/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
@@ -1885,6 +1885,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 68b107d080..3b0eb4874e 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -1997,6 +1997,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index e5b6a4da50..fa272fbda1 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -1938,6 +1938,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index e24ea29e35..544ab5d54a 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -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
index 0000000000..5005380748
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-gettid-kill.c
@@ -0,0 +1,129 @@
+/* Verify the interaction of kill and thread groups.
+   Copyright (C) 2018 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
index 0000000000..78bbaee4f3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-gettid.c
@@ -0,0 +1,79 @@
+/* Smoke test for the gettid system call.
+   Copyright (C) 2018 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>
diff --git a/sysdeps/unix/sysv/linux/tst-setgetname.c b/sysdeps/unix/sysv/linux/tst-setgetname.c
index b80ff59074..95d8bb9ba4 100644
--- a/sysdeps/unix/sysv/linux/tst-setgetname.c
+++ b/sysdeps/unix/sysv/linux/tst-setgetname.c
@@ -43,12 +43,6 @@
    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)
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 86dfb0c94d..735e31a017 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -1896,6 +1896,7 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F
 GLIBC_2.3 __ctype_b_loc F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index dd688263aa..c54d8974b6 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -2147,5 +2147,6 @@ GLIBC_2.28 thrd_equal F
 GLIBC_2.28 thrd_sleep F
 GLIBC_2.28 thrd_yield F
 GLIBC_2.29 getcpu F
+GLIBC_2.29 gettid F
 GLIBC_2.29 posix_spawn_file_actions_addchdir_np F
 GLIBC_2.29 posix_spawn_file_actions_addfchdir_np F

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-15 14:18   ` Florian Weimer
@ 2018-12-15 14:37     ` Andreas Schwab
  2018-12-15 15:23       ` Florian Weimer
  0 siblings, 1 reply; 25+ messages in thread
From: Andreas Schwab @ 2018-12-15 14:37 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Carlos O'Donell, libc-alpha

On Dez 15 2018, Florian Weimer <fweimer@redhat.com> wrote:

> 	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
> 	(GLIBC_2.29): Likewise.
> 	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
> 	(GLIBC_2.29): Likewise.

libc-le.abilist -> le/libc.abilist, libc.abilist -> be/libc.abilist

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2018-12-15 14:37     ` Andreas Schwab
@ 2018-12-15 15:23       ` Florian Weimer
  0 siblings, 0 replies; 25+ messages in thread
From: Florian Weimer @ 2018-12-15 15:23 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Carlos O'Donell, libc-alpha

* Andreas Schwab:

> On Dez 15 2018, Florian Weimer <fweimer@redhat.com> wrote:
>
>> 	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
>> 	(GLIBC_2.29): Likewise.
>> 	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
>> 	(GLIBC_2.29): Likewise.
>
> libc-le.abilist -> le/libc.abilist, libc.abilist -> be/libc.abilist

Thanks, fixed locally.

Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2019-02-08 15:56           ` Florian Weimer
@ 2019-02-08 16:05             ` Florian Weimer
  0 siblings, 0 replies; 25+ messages in thread
From: Florian Weimer @ 2019-02-08 16:05 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha, carlos

* Florian Weimer:

> * Florian Weimer:
>
>> This should be the fix:
>>
>> posix: Fix missing wrapper header for <bits/unistd_ext.h>
>>
>> 2019-02-08  Florian Weimer  <fweimer@redhat.com>
>>
>> 	* include/bits/unistd_ext.h: New file.
>>
>> diff --git a/include/bits/unistd_ext.h b/include/bits/unistd_ext.h
>> new file mode 100644
>> index 0000000000..24e8d09ba8
>> --- /dev/null
>> +++ b/include/bits/unistd_ext.h
>> @@ -0,0 +1 @@
>> +#include <posix/bits/unistd_ext.h>
>
> Well, it broke the Linux build.  It turns out that installed sysdeps
> headers must only live under sysdeps.  I'm testing the fix below.
>
> This stuff is way too difficult.
>
> Florian
>
> Provide <bits/unistd_ext.h> as a sysdeps header exclusively
>
> Non-sysdeps headers cannot be overriden by sysdeps headers across the
> entire build, so it is necessary to turn such extension headers into
> sysdeps headers themselves.  The approach here follows the existing
> <bits/shm.h> header (although it uses sysdeps/gnu instead of
> sysdeps/generic).
>
> Fixes commit 1d0fc213824eaa2a8f8c4385daaa698ee8fb7c92 ("Linux: Add
> gettid system call wrapper [BZ #6399]") and commit
> 8f89ab216f205c2ffd90d1fc8454efdfc0b01dee ("posix: Fix missing wrapper
> header for <bits/unistd_ext.h>").
>
> 2019-02-08  Florian Weimer  <fweimer@redhat.com>
>
> 	* include/bits/unistd_ext.h: Remove file.
> 	* posix/bits/unistd_ext.h: Move to ...
> 	* sysdeps/generic/bits/unistd_ext.h: ... here.

Testing suggests that this does the right thing.  The correct header is
installed on Hurd and Linux.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2019-02-08 14:55         ` Florian Weimer
  2019-02-08 15:29           ` Carlos O'Donell
@ 2019-02-08 15:56           ` Florian Weimer
  2019-02-08 16:05             ` Florian Weimer
  1 sibling, 1 reply; 25+ messages in thread
From: Florian Weimer @ 2019-02-08 15:56 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha, carlos

* Florian Weimer:

> This should be the fix:
>
> posix: Fix missing wrapper header for <bits/unistd_ext.h>
>
> 2019-02-08  Florian Weimer  <fweimer@redhat.com>
>
> 	* include/bits/unistd_ext.h: New file.
>
> diff --git a/include/bits/unistd_ext.h b/include/bits/unistd_ext.h
> new file mode 100644
> index 0000000000..24e8d09ba8
> --- /dev/null
> +++ b/include/bits/unistd_ext.h
> @@ -0,0 +1 @@
> +#include <posix/bits/unistd_ext.h>

Well, it broke the Linux build.  It turns out that installed sysdeps
headers must only live under sysdeps.  I'm testing the fix below.

This stuff is way too difficult.

Florian

Provide <bits/unistd_ext.h> as a sysdeps header exclusively

Non-sysdeps headers cannot be overriden by sysdeps headers across the
entire build, so it is necessary to turn such extension headers into
sysdeps headers themselves.  The approach here follows the existing
<bits/shm.h> header (although it uses sysdeps/gnu instead of
sysdeps/generic).

Fixes commit 1d0fc213824eaa2a8f8c4385daaa698ee8fb7c92 ("Linux: Add
gettid system call wrapper [BZ #6399]") and commit
8f89ab216f205c2ffd90d1fc8454efdfc0b01dee ("posix: Fix missing wrapper
header for <bits/unistd_ext.h>").

2019-02-08  Florian Weimer  <fweimer@redhat.com>

	* include/bits/unistd_ext.h: Remove file.
	* posix/bits/unistd_ext.h: Move to ...
	* sysdeps/generic/bits/unistd_ext.h: ... here.

diff --git a/include/bits/unistd_ext.h b/include/bits/unistd_ext.h
deleted file mode 100644
index 24e8d09ba8..0000000000
--- a/include/bits/unistd_ext.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <posix/bits/unistd_ext.h>
diff --git a/posix/bits/unistd_ext.h b/sysdeps/generic/bits/unistd_ext.h
similarity index 100%
rename from posix/bits/unistd_ext.h
rename to sysdeps/generic/bits/unistd_ext.h

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2019-02-08 14:55         ` Florian Weimer
@ 2019-02-08 15:29           ` Carlos O'Donell
  2019-02-08 15:56           ` Florian Weimer
  1 sibling, 0 replies; 25+ messages in thread
From: Carlos O'Donell @ 2019-02-08 15:29 UTC (permalink / raw)
  To: Florian Weimer, Adhemerval Zanella; +Cc: libc-alpha

On 2/8/19 9:55 AM, Florian Weimer wrote:
> * Florian Weimer:
> 
>> * Adhemerval Zanella:
>>
>>> On 02/02/2019 12:18, Florian Weimer wrote:
>>>> * Carlos O'Donell:
>>>>
>>>>> OK for master if you fix the copyright years to 2019.
>>>>
>>>> Thanks, I've made this change locally.
>>>>
>>>> I will push this some time next week, unless there are objections.
>>>>
>>>> Florian
>>>>
>>>
>>> Hurd build is failing with:
>>>
>>> In file included from ../include/unistd.h:2,
>>>                  from mach_init.c:20:
>>> ../posix/unistd.h:1170:10: fatal error: bits/unistd_ext.h: No such file or directory
>>>  #include <bits/unistd_ext.h>
>>>
>>> when building mach_init.c. It seems it adds sysdeps/posix in sysdeps
>>> search, but not posix itself:
>>
>> It's a missing wrapper header under include.  I will fix it.
> 
> This should be the fix:
> 
> posix: Fix missing wrapper header for <bits/unistd_ext.h>
> 
> 2019-02-08  Florian Weimer  <fweimer@redhat.com>
> 
> 	* include/bits/unistd_ext.h: New file.
> 
> diff --git a/include/bits/unistd_ext.h b/include/bits/unistd_ext.h
> new file mode 100644
> index 0000000000..24e8d09ba8
> --- /dev/null
> +++ b/include/bits/unistd_ext.h
> @@ -0,0 +1 @@
> +#include <posix/bits/unistd_ext.h>
 
My bmg of i686-gnu passes with this patch.

OK for master.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2019-02-08 14:21       ` Florian Weimer
@ 2019-02-08 14:55         ` Florian Weimer
  2019-02-08 15:29           ` Carlos O'Donell
  2019-02-08 15:56           ` Florian Weimer
  0 siblings, 2 replies; 25+ messages in thread
From: Florian Weimer @ 2019-02-08 14:55 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha, carlos

* Florian Weimer:

> * Adhemerval Zanella:
>
>> On 02/02/2019 12:18, Florian Weimer wrote:
>>> * Carlos O'Donell:
>>> 
>>>> OK for master if you fix the copyright years to 2019.
>>> 
>>> Thanks, I've made this change locally.
>>> 
>>> I will push this some time next week, unless there are objections.
>>> 
>>> Florian
>>> 
>>
>> Hurd build is failing with:
>>
>> In file included from ../include/unistd.h:2,
>>                  from mach_init.c:20:
>> ../posix/unistd.h:1170:10: fatal error: bits/unistd_ext.h: No such file or directory
>>  #include <bits/unistd_ext.h>
>>
>> when building mach_init.c. It seems it adds sysdeps/posix in sysdeps
>> search, but not posix itself:
>
> It's a missing wrapper header under include.  I will fix it.

This should be the fix:

posix: Fix missing wrapper header for <bits/unistd_ext.h>

2019-02-08  Florian Weimer  <fweimer@redhat.com>

	* include/bits/unistd_ext.h: New file.

diff --git a/include/bits/unistd_ext.h b/include/bits/unistd_ext.h
new file mode 100644
index 0000000000..24e8d09ba8
--- /dev/null
+++ b/include/bits/unistd_ext.h
@@ -0,0 +1 @@
+#include <posix/bits/unistd_ext.h>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2019-02-08 14:12     ` Adhemerval Zanella
@ 2019-02-08 14:21       ` Florian Weimer
  2019-02-08 14:55         ` Florian Weimer
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer @ 2019-02-08 14:21 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

* Adhemerval Zanella:

> On 02/02/2019 12:18, Florian Weimer wrote:
>> * Carlos O'Donell:
>> 
>>> OK for master if you fix the copyright years to 2019.
>> 
>> Thanks, I've made this change locally.
>> 
>> I will push this some time next week, unless there are objections.
>> 
>> Florian
>> 
>
> Hurd build is failing with:
>
> In file included from ../include/unistd.h:2,
>                  from mach_init.c:20:
> ../posix/unistd.h:1170:10: fatal error: bits/unistd_ext.h: No such file or directory
>  #include <bits/unistd_ext.h>
>
> when building mach_init.c. It seems it adds sysdeps/posix in sysdeps
> search, but not posix itself:

It's a missing wrapper header under include.  I will fix it.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2019-02-02 14:18   ` Florian Weimer
@ 2019-02-08 14:12     ` Adhemerval Zanella
  2019-02-08 14:21       ` Florian Weimer
  0 siblings, 1 reply; 25+ messages in thread
From: Adhemerval Zanella @ 2019-02-08 14:12 UTC (permalink / raw)
  To: libc-alpha



On 02/02/2019 12:18, Florian Weimer wrote:
> * Carlos O'Donell:
> 
>> OK for master if you fix the copyright years to 2019.
> 
> Thanks, I've made this change locally.
> 
> I will push this some time next week, unless there are objections.
> 
> Florian
> 

Hurd build is failing with:

In file included from ../include/unistd.h:2,
                 from mach_init.c:20:
../posix/unistd.h:1170:10: fatal error: bits/unistd_ext.h: No such file or directory
 #include <bits/unistd_ext.h>

when building mach_init.c. It seems it adds sysdeps/posix in sysdeps search, but
not posix itself:

-I../include -I<builddir>/i686-gnu/mach  -I<builddir>i686-gnu  -I../sysdeps/mach/hurd/i386  -I../sysdeps/mach/hurd/x86  -I../sysdeps/mach/hurd/i386/htl  -I../sysdeps/mach/hurd/htl  -I../sysdeps/hurd/htl  -I../sysdeps/mach/htl  -I../sysdeps/htl  -I../sysdeps/pthread  -I../sysdeps/i386/htl  -I../sysdeps/mach/hurd  -I../sysdeps/gnu  -I../sysdeps/unix/bsd  -I../sysdeps/unix/inet  -I../sysdeps/mach/i386  -I../sysdeps/mach/include -I../sysdeps/mach  -I../sysdeps/i386/i686/fpu  -I../sysdeps/i386/i686  -I../sysdeps/i386/fpu  -I../sysdeps/x86/fpu/include -I../sysdeps/x86/fpu  -I../sysdeps/i386  -I../sysdeps/x86  -I../sysdeps/wordsize-32  -I../sysdeps/ieee754/float128  -I../sysdeps/ieee754/ldbl-96/include -I../sysdeps/ieee754/ldbl-96  -I../sysdeps/ieee754/dbl-64  -I../sysdeps/ieee754/flt-32  -I../sysdeps/hurd/include -I../sysdeps/hurd  -I../sysdeps/unix  -I../sysdeps/posix  -I../sysdeps/ieee754  -I../sysdeps/generic -I../hurd

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2019-02-01 22:45 ` Carlos O'Donell
@ 2019-02-02 14:18   ` Florian Weimer
  2019-02-08 14:12     ` Adhemerval Zanella
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer @ 2019-02-02 14:18 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha, Andreas Schwab, Joseph S. Myers

* Carlos O'Donell:

> OK for master if you fix the copyright years to 2019.

Thanks, I've made this change locally.

I will push this some time next week, unless there are objections.

Florian

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
  2019-01-31 18:54 Florian Weimer
@ 2019-02-01 22:45 ` Carlos O'Donell
  2019-02-02 14:18   ` Florian Weimer
  0 siblings, 1 reply; 25+ messages in thread
From: Carlos O'Donell @ 2019-02-01 22:45 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha, Andreas Schwab, Joseph S. Myers

On 1/31/19 1:53 PM, Florian Weimer wrote:
> This repost changes the symbol version to GLIBC_2.30 and updates the
> C-SKY ABI list as well.
> 
> I would welcome a couple of acks that this indeed the direction in which
> we want to move.

I'm going to review this again, with an eye towards establishing consensus.

Firstly, there has been a long-standing complaint that we should not expose
any details that imply a threading model in which the userspace thread is
expected to stay on the same kernel thread. This is not a valid complaint
today. We set all kinds of parameters on the thread via the tid and the
syscalls support that, and so the userspace thread will always be tied to
that tid until it exits. This kind of model is not going away.

Secondly, my complaint has been that any change adding gettid should have
documentation updates. You have gone through the manual and clarified all
of the APIs for which this is required, and I appreciate that. This meeds
my criteria for inclusion.

Since this is being added only for the Linux API, and not the GNU API,
I see no problem with this since it doesn't need to be implemented by the
other operating systems that glibc supports, in this case Hurd (or
kFreeBSD, the other OS port I know about). We know that NaCl is no longer
supported, so that doesn't restrict us in any way either.

I have reviewed all of the comments in bug 6399, and as always it surprises
me to see the speed with which we move, this was filed by Michael in 2008.
Florian I appreciate your contributions to such long standing issues as this.

The most salient point around 2015 is made by Nicholas Miell in which he
points out that all pid_t/tid APIs are inherently flawed because of the reuse
race conditions, but this does not materially impact exposing gettid().
However it does raise the interesting point, that if we accept tid reuse
why not accept the patch for pthread_thread_number_np()?
https://sourceware.org/ml/libc-alpha/2018-03/msg00030.html
I'm digressing here a bit, but wanted to draw an analog between the two
functions. The bigger problem is that gettid() is Linux-specific while
pthread_thread_number_np() is a GNU API. So there is more stringent
requirements to get it right. Perhaps we should just be looking at a fd-based
API to extend things.

Reviewing the rest of the comments up to 2018 does not show any further
sustained objections against the inclusion of the patches. Therefore I
believe we have a set of patches here which can be applied to master for
release in 2.30.

I looked for libc-alpha discussions on the inclusion of gettid(), but didn't
find any that blocked consensus.  The following documents were useful in
my own review:
"Glibc and the kernel user-space API" (2013)
https://lwn.net/Articles/534682/
"RFC: POSIX timers and threads in a realtime context" (2015)
https://sourceware.org/ml/libc-alpha/2015-10/msg00068.html
- Wherein it's clear gettid would help.
"Principles for Syscall Wrappers" (2015)
https://lwn.net/Articles/711058/
"C library system-call wrappers, or the lack thereof"
https://news.ycombinator.com/item?id=18439100
"Re: Official Linux system wrapper library?"
https://lkml.org/lkml/2018/11/14/810
"Re: support for calling Linux syscalls directly"
https://sourceware.org/ml/libc-alpha/2013-02/msg00030.html
- gettid on the "Strong candidates" list.

OK for master if you fix the copyright years to 2019.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> ---
> 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.
> 
> 2019-01-31  Florian Weimer  <fweimer@redhat.com>
> 
> 	[BZ #6399]

OK. What a wonderfully low bug number to close :-)

> 	Linux: Add gettid system call wrapper.

OK.

> 	* 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.

OK.

> 
> diff --git a/NEWS b/NEWS
> index 38ffd10c09..bdd1eaccd0 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -9,7 +9,7 @@ Version 2.30
>  
>  Major new features:
>  
> -  [Add new features here]
> +* On Linux, the gettid function has been added.

OK.

>  
>  Deprecated and removed features, and other changes affecting compatibility:
>  
> 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.

OK.

> +
> +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 cfd914ff21..9307ecb3b0 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

OK.

>  
>  routines :=								      \
>  	uname								      \
> diff --git a/posix/bits/unistd_ext.h b/posix/bits/unistd_ext.h
> new file mode 100644
> index 0000000000..8019cfa758
> --- /dev/null
> +++ b/posix/bits/unistd_ext.h
> @@ -0,0 +1,21 @@
> +/* System-specific extensions of <unistd.h>, generic version.

OK.

> +   Copyright (C) 2018 Free Software Foundation, Inc.

Wrong year.

> +   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

OK.

> 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>

OK.

> +
>  __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

OK.

>  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)

OK.

> +
>  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;
> +  }

OK.

>    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

OK.

> 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..8d7a8a07d0
> --- /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) 2018 Free Software Foundation, Inc.

Wrong year.

> +   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;

OK. I'll note that we do have POSIX rules for switching between underlying
fd/stream so I wonder if we can't some day define such rules for threads
or if they are even required.

> +
> +#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
> --- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
> index 74e42a5209..814e81b9d2 100644
> --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
> index 4af5a74e8a..68e80372e7 100644
> --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
> index ccef673fd2..31178e4f54 100644
> --- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
> index 1054bb599e..7074573638 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
> index 4f5b5ffebf..154f9c77fc 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
> index 943aee58d4..97b8f42d5c 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
> index 17a5d17ef9..5b3e85de93 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
> index 4d62a540fd..04a130a81c 100644
> --- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
> index ecc2d6fa13..d99a835544 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
> index f5830f9c33..826772777a 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
> index 633d8f4792..5aa038971b 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
> index 2c712636ef..c630d0c37d 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
> index 195bc8b2cf..da123d3867 100644
> --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
> index 334def033c..361240400c 100644
> --- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
> index 536f4c4ced..f44f178a08 100644
> --- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
> index 30ae3b6ebb..24a8f934cb 100644
> --- a/sysdeps/unix/sysv/linux/sh/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
> index 68b107d080..37957959e2 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
> index e5b6a4da50..0992349b06 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
> index e24ea29e35..544ab5d54a 100644
> --- a/sysdeps/unix/sysv/linux/syscalls.list
> +++ b/sysdeps/unix/sysv/linux/syscalls.list
> @@ -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
> index 0000000000..5005380748
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tst-gettid-kill.c
> @@ -0,0 +1,129 @@
> +/* Verify the interaction of kill and thread groups.

OK.

> +   Copyright (C) 2018 Free Software Foundation, Inc.

Wrong year.

> +   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;

OK.

> +}
> +
> +#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
> index 0000000000..78bbaee4f3
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tst-gettid.c
> @@ -0,0 +1,79 @@
> +/* Smoke test for the gettid system call.

OK.

> +   Copyright (C) 2018 Free Software Foundation, Inc.

Wrong year.

> +   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>

OK.

> diff --git a/sysdeps/unix/sysv/linux/tst-setgetname.c b/sysdeps/unix/sysv/linux/tst-setgetname.c
> index 23184aae20..c373e61492 100644
> --- a/sysdeps/unix/sysv/linux/tst-setgetname.c
> +++ b/sysdeps/unix/sysv/linux/tst-setgetname.c
> @@ -43,12 +43,6 @@
>     terminator.  */
>  #define TASK_COMM_LEN 16
>  
> -long
> -gettid (void)
> -{
> -    return syscall(__NR_gettid);
> -}

OK.

> -
>  /* On Linux we can read this task's name from /proc.  */
>  int
>  get_self_comm (long tid, char *buf, size_t len)
> diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
> index 86dfb0c94d..af004fcff6 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
> @@ -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
> diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
> index dd688263aa..84015f0a57 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
> +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
> @@ -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
> 


-- 
Cheers,
Carlos.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH] Linux: Add gettid system call wrapper [BZ #6399]
@ 2019-01-31 18:54 Florian Weimer
  2019-02-01 22:45 ` Carlos O'Donell
  0 siblings, 1 reply; 25+ messages in thread
From: Florian Weimer @ 2019-01-31 18:54 UTC (permalink / raw)
  To: libc-alpha

This repost changes the symbol version to GLIBC_2.30 and updates the
C-SKY ABI list as well.

I would welcome a couple of acks that this indeed the direction in which
we want to move.

Thanks,
Florian

---
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.

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.

diff --git a/NEWS b/NEWS
index 38ffd10c09..bdd1eaccd0 100644
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,7 @@ Version 2.30
 
 Major new features:
 
-  [Add new features here]
+* On Linux, the gettid function has been added.
 
 Deprecated and removed features, and other changes affecting compatibility:
 
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 cfd914ff21..9307ecb3b0 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..8019cfa758
--- /dev/null
+++ b/posix/bits/unistd_ext.h
@@ -0,0 +1,21 @@
+/* System-specific extensions of <unistd.h>, generic version.
+   Copyright (C) 2018 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..8d7a8a07d0
--- /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) 2018 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
--- a/sysdeps/unix/sysv/linux/ia64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
index 74e42a5209..814e81b9d2 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
index 4af5a74e8a..68e80372e7 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/microblaze/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
index ccef673fd2..31178e4f54 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libc.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
index 1054bb599e..7074573638 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
index 4f5b5ffebf..154f9c77fc 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
index 943aee58d4..97b8f42d5c 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
index 17a5d17ef9..5b3e85de93 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist
index 4d62a540fd..04a130a81c 100644
--- a/sysdeps/unix/sysv/linux/nios2/libc.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
index ecc2d6fa13..d99a835544 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
index f5830f9c33..826772777a 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
index 633d8f4792..5aa038971b 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
index 2c712636ef..c630d0c37d 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
index 195bc8b2cf..da123d3867 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
index 334def033c..361240400c 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
index 536f4c4ced..f44f178a08 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/sh/libc.abilist b/sysdeps/unix/sysv/linux/sh/libc.abilist
index 30ae3b6ebb..24a8f934cb 100644
--- a/sysdeps/unix/sysv/linux/sh/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
index 68b107d080..37957959e2 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
index e5b6a4da50..0992349b06 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index e24ea29e35..544ab5d54a 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -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
index 0000000000..5005380748
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-gettid-kill.c
@@ -0,0 +1,129 @@
+/* Verify the interaction of kill and thread groups.
+   Copyright (C) 2018 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
index 0000000000..78bbaee4f3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-gettid.c
@@ -0,0 +1,79 @@
+/* Smoke test for the gettid system call.
+   Copyright (C) 2018 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>
diff --git a/sysdeps/unix/sysv/linux/tst-setgetname.c b/sysdeps/unix/sysv/linux/tst-setgetname.c
index 23184aae20..c373e61492 100644
--- a/sysdeps/unix/sysv/linux/tst-setgetname.c
+++ b/sysdeps/unix/sysv/linux/tst-setgetname.c
@@ -43,12 +43,6 @@
    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)
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
index 86dfb0c94d..af004fcff6 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
@@ -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
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
index dd688263aa..84015f0a57 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist
@@ -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

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2019-02-08 16:05 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-05 10:53 [PATCH] Linux: Add gettid system call wrapper [BZ #6399] Florian Weimer
2018-12-05 16:20 ` Joseph Myers
2018-12-05 18:25   ` Florian Weimer
2018-12-05 18:30     ` Joseph Myers
2018-12-07 13:56       ` Carlos O'Donell
2018-12-10 11:35       ` Florian Weimer
2018-12-10 12:02         ` Christian Brauner
2018-12-10 12:08           ` Florian Weimer
2018-12-10 12:20             ` Christian Brauner
2018-12-14 20:58         ` Carlos O'Donell
2018-12-07  8:49 ` Florian Weimer
2018-12-07 13:28   ` Florian Weimer
2018-12-14 21:11 ` Carlos O'Donell
2018-12-15 14:18   ` Florian Weimer
2018-12-15 14:37     ` Andreas Schwab
2018-12-15 15:23       ` Florian Weimer
2019-01-31 18:54 Florian Weimer
2019-02-01 22:45 ` Carlos O'Donell
2019-02-02 14:18   ` Florian Weimer
2019-02-08 14:12     ` Adhemerval Zanella
2019-02-08 14:21       ` Florian Weimer
2019-02-08 14:55         ` Florian Weimer
2019-02-08 15:29           ` Carlos O'Donell
2019-02-08 15:56           ` Florian Weimer
2019-02-08 16:05             ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).