This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch roland/nacl created. glibc-2.21-370-g2b34fc4
- From: roland at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 19 May 2015 23:51:38 -0000
- Subject: GNU C Library master sources branch roland/nacl created. glibc-2.21-370-g2b34fc4
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, roland/nacl has been created
at 2b34fc42d8158928965a0c590332ac61b56c9fef (commit)
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=2b34fc42d8158928965a0c590332ac61b56c9fef
commit 2b34fc42d8158928965a0c590332ac61b56c9fef
Author: Roland McGrath <roland@hack.frob.com>
Date: Tue May 19 16:41:08 2015 -0700
NaCl: Set tid field to a unique value.
diff --git a/ChangeLog b/ChangeLog
index 5ea3db5..8bc88c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2015-05-19 Roland McGrath <roland@hack.frob.com>
+ * sysdeps/nacl/createthread.c (get_new_tid): New function.
+ (create_thread): Use it to initialize PD->tid.
+
[BZ #18434]
* nptl/tst-sem15.c: New file.
* nptl/Makefile (tests): Add it.
diff --git a/sysdeps/nacl/createthread.c b/sysdeps/nacl/createthread.c
index 9df4eae..19fa3ce 100644
--- a/sysdeps/nacl/createthread.c
+++ b/sysdeps/nacl/createthread.c
@@ -16,7 +16,45 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <assert.h>
#include <nacl-interfaces.h>
+#include <stdint.h>
+
+
+/* NaCl has no concept of PID or TID, nor even any notion of an
+ identifier for a thread within the process. But various places in
+ the NPTL implementation rely on using the 'tid' field of the TCB
+ (struct pthread) as an identifier that is unique at least among all
+ live threads in the process. So we must synthesize some number to
+ use. Conveniently, the 'pthread_t' value itself is already unique
+ in exactly this way (because it's the 'struct pthread' pointer).
+
+ The only wrinkle is that 'tid' is a (32-bit) 'int' and its high
+ (sign) bit is used for special purposes, so we must be absolutely
+ sure that we never use a pointer value with the high bit set. (It
+ also cannot be zero, but zero is never a valid pointer anyway.)
+ The NaCl sandbox models for 32-bit machines limit the address space
+ to less than 3GB (in fact, to 1GB), so it's already impossible that
+ a valid pointer will have its high bit set. But the NaCl x86-64
+ sandbox model allows a full 4GB of address space, so we cannot
+ assume that an arbitrary pointer value will not have the high bit
+ set. Conveniently, there are always unused bits in the pointer
+ value for a 'struct pthread', because it is always aligned to at
+ least 32 bits and so the low bits are always zero. Hence, we can
+ safely avoid the danger of a nonzero high bit just by shifting the
+ pointer value right. */
+
+static inline int
+get_new_tid (struct pthread *pd)
+{
+ uintptr_t id = (uintptr_t) pd;
+ int tid = id >> 1;
+ assert ((id & 1) == 0);
+ assert (sizeof id == sizeof tid);
+ assert (tid > 0);
+ return tid;
+}
+
/* See the comments in pthread_create.c for the requirements for these
two macros and the create_thread function. */
@@ -33,6 +71,8 @@ static int
create_thread (struct pthread *pd, const struct pthread_attr *attr,
bool stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
{
+ pd->tid = get_new_tid (pd);
+
pd->stopped_start = stopped_start;
if (__glibc_unlikely (stopped_start))
/* We make sure the thread does not run far by forcing it to get a
-----------------------------------------------------------------------
hooks/post-receive
--
GNU C Library master sources