diff options
author | Roland McGrath <roland@hack.frob.com> | 2014-06-09 12:52:55 -0700 |
---|---|---|
committer | Roland McGrath <roland@hack.frob.com> | 2014-06-09 12:52:55 -0700 |
commit | 962b744d06c1df8653570f32c03da572801e4b6b (patch) | |
tree | 408556ab7597eba9480e1bd53379681c01c2a55b /nptl/sysdeps | |
parent | 2976feab1f37ad7b4e06b253f0a2e844505217da (diff) | |
download | glibc-962b744d06c1df8653570f32c03da572801e4b6b.tar glibc-962b744d06c1df8653570f32c03da572801e4b6b.tar.gz glibc-962b744d06c1df8653570f32c03da572801e4b6b.tar.bz2 glibc-962b744d06c1df8653570f32c03da572801e4b6b.zip |
Start cleaning up TLS initial value for pthread_create.
Diffstat (limited to 'nptl/sysdeps')
-rw-r--r-- | nptl/sysdeps/i386/tls.h | 45 | ||||
-rw-r--r-- | nptl/sysdeps/pthread/createthread.c | 22 | ||||
-rw-r--r-- | nptl/sysdeps/x86_64/tls.h | 2 |
3 files changed, 47 insertions, 22 deletions
diff --git a/nptl/sysdeps/i386/tls.h b/nptl/sysdeps/i386/tls.h index 2f8d11def1..ac9c9a22f9 100644 --- a/nptl/sysdeps/i386/tls.h +++ b/nptl/sysdeps/i386/tls.h @@ -192,6 +192,26 @@ union user_desc_init # endif #endif +static inline void __attribute__ ((unused, always_inline)) +tls_fill_user_desc (union user_desc_init *desc, + unsigned int entry_number, + void *pd) +{ + desc->vals[0] = entry_number; + /* The 'base_addr' field. Pointer to the TCB. */ + desc->vals[1] = (unsigned long int) pd; + /* The 'limit' field. We use 4GB which is 0xfffff pages. */ + desc->vals[2] = 0xfffff; + /* Collapsed value of the bitfield: + .seg_32bit = 1 + .contents = 0 + .read_exec_only = 0 + .limit_in_pages = 1 + .seg_not_present = 0 + .useable = 1 */ + desc->vals[3] = 0x51; +} + /* Code to initially initialize the thread pointer. This might need special attention since 'errno' is not yet available and if the operation can cause a failure 'errno' must not be touched. */ @@ -207,20 +227,8 @@ union user_desc_init /* New syscall handling support. */ \ INIT_SYSINFO; \ \ - /* The 'entry_number' field. Let the kernel pick a value. */ \ - _segdescr.vals[0] = -1; \ - /* The 'base_addr' field. Pointer to the TCB. */ \ - _segdescr.vals[1] = (unsigned long int) _thrdescr; \ - /* The 'limit' field. We use 4GB which is 0xfffff pages. */ \ - _segdescr.vals[2] = 0xfffff; \ - /* Collapsed value of the bitfield: \ - .seg_32bit = 1 \ - .contents = 0 \ - .read_exec_only = 0 \ - .limit_in_pages = 1 \ - .seg_not_present = 0 \ - .useable = 1 */ \ - _segdescr.vals[3] = 0x51; \ + /* Let the kernel pick a value for the 'entry_number' field. */ \ + tls_fill_user_desc (&_segdescr, -1, _thrdescr); \ \ /* Install the TLS. */ \ asm volatile (TLS_LOAD_EBX \ @@ -244,6 +252,15 @@ union user_desc_init _result == 0 ? NULL \ : "set_thread_area failed when setting up thread-local storage\n"; }) +# define TLS_DEFINE_INIT_TP(tp, pd) \ + union user_desc_init _segdescr; \ + /* Find the 'entry_number' field that the kernel selected in TLS_INIT_TP. \ + The first three bits of the segment register value select the GDT, \ + ignore them. We get the index from the value of the %gs register in \ + the current thread. */ \ + tls_fill_user_desc (&_segdescr, TLS_GET_GS () >> 3, pd); \ + const struct user_desc *tp = &_segdescr.desc + /* Return the address of the dtv for the current thread. */ # define THREAD_DTV() \ diff --git a/nptl/sysdeps/pthread/createthread.c b/nptl/sysdeps/pthread/createthread.c index e1856f7b1c..28c1ea67d3 100644 --- a/nptl/sysdeps/pthread/createthread.c +++ b/nptl/sysdeps/pthread/createthread.c @@ -30,10 +30,18 @@ #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD) -/* Unless otherwise specified, the thread "register" is going to be - initialized with a pointer to the TCB. */ -#ifndef TLS_VALUE -# define TLS_VALUE pd +/* The <tls.h> header should define the macro TLS_DEFINE_INIT_TP such that: + TLS_DEFINE_INIT_TP (VAR, PD); + Declares and initializes a variable VAR with the value that should + be passed to the OS thread creation function (e.g. clone) to initialize + its TLS state for the 'struct pthread *' PD. */ +#ifndef TLS_DEFINE_INIT_TP +/* For a transitional period while all the <tls.h> implementations are + getting updated, we define it using the old TLS_VALUE macro. */ +# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = TLS_VALUE +# ifndef TLS_VALUE +# define TLS_VALUE pd +# endif #endif #ifndef ARCH_CLONE @@ -52,9 +60,7 @@ do_clone (struct pthread *pd, const struct pthread_attr *attr, int clone_flags, int (*fct) (void *), STACK_VARIABLES_PARMS, int stopped) { -#ifdef PREPARE_CREATE - PREPARE_CREATE; -#endif + TLS_DEFINE_INIT_TP (tp, pd); if (__glibc_unlikely (stopped != 0)) /* We make sure the thread does not run far by forcing it to get a @@ -73,7 +79,7 @@ do_clone (struct pthread *pd, const struct pthread_attr *attr, atomic_increment (&__nptl_nthreads); int rc = ARCH_CLONE (fct, STACK_VARIABLES_ARGS, clone_flags, - pd, &pd->tid, TLS_VALUE, &pd->tid); + pd, &pd->tid, tp, &pd->tid); if (__glibc_unlikely (rc == -1)) { diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h index fb671f4795..3e811b6aea 100644 --- a/nptl/sysdeps/x86_64/tls.h +++ b/nptl/sysdeps/x86_64/tls.h @@ -164,6 +164,8 @@ typedef struct _result ? "cannot set %fs base address for thread-local storage" : 0; \ }) +# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + /* Return the address of the dtv for the current thread. */ # define THREAD_DTV() \ |