From 55c11fbdb046ec06fb9f9bca2ae772a413354c74 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 14 Mar 2003 22:34:02 +0000 Subject: [PATCH] 2003-03-14 Roland McGrath * descr.h (struct pthread): Move the union out of [!TLS_DTV_AT_TP], so we always define the padding space. [!TLS_DTV_AT_TP]: Give tcbhead_t field a name, `header', since GCC stopped supporting its own extensions fully. [TLS_MULTIPLE_THREADS_IN_TCB]: Put `multiple_threads' inside a wrapper struct also called `header', so `header.multiple_threads' is the field name to use on all machines. * allocatestack.c (allocate_stack): Use `header.' prefix. * sysdeps/pthread/createthread.c (create_thread): Likewise. * pthread_create.c (__pthread_create_2_1): Likewise. * sysdeps/i386/tls.h (INSTALL_NEW_DTV, THREAD_DTV): Likewise. (THREAD_SELF): Likewise. * sysdeps/x86_64/tls.h: Likewise. * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (SINGLE_THREAD_P): Likewise. * sysdeps/unix/sysv/linux/sh/sysdep-cancel.h (SINGLE_THREAD_P): Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h (SINGLE_THREAD_P): Likewise. --- nptl/allocatestack.c | 8 ++++---- nptl/descr.h | 20 ++++++++++++++------ nptl/pthread_create.c | 4 ++-- nptl/sysdeps/i386/tls.h | 6 +++--- nptl/sysdeps/pthread/createthread.c | 8 ++++---- nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h | 3 ++- .../unix/sysv/linux/s390/s390-64/sysdep-cancel.h | 2 +- nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h | 3 ++- nptl/sysdeps/x86_64/tls.h | 6 +++--- 9 files changed, 35 insertions(+), 25 deletions(-) diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index 14a2ab0..8e77543 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -321,14 +321,14 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, #ifdef TLS_MULTIPLE_THREADS_IN_TCB /* This is at least the second thread. */ - pd->multiple_threads = 1; + pd->header.multiple_threads = 1; #else __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1; #endif #ifdef NEED_DL_SYSINFO /* Copy the sysinfo value from the parent. */ - pd->sysinfo = THREAD_GETMEM (THREAD_SELF, sysinfo); + pd->header.sysinfo = THREAD_GETMEM (THREAD_SELF, header.sysinfo); #endif /* Allocate the DTV for this thread. */ @@ -446,14 +446,14 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, #ifdef TLS_MULTIPLE_THREADS_IN_TCB /* This is at least the second thread. */ - pd->multiple_threads = 1; + pd->header.multiple_threads = 1; #else __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1; #endif #ifdef NEED_DL_SYSINFO /* Copy the sysinfo value from the parent. */ - pd->sysinfo = THREAD_GETMEM (THREAD_SELF, sysinfo); + pd->header.sysinfo = THREAD_GETMEM (THREAD_SELF, header.sysinfo); #endif /* Allocate the DTV for this thread. */ diff --git a/nptl/descr.h b/nptl/descr.h index cbaa38f..5a4c99c 100644 --- a/nptl/descr.h +++ b/nptl/descr.h @@ -57,17 +57,25 @@ /* Thread descriptor data structure. */ struct pthread { -#if !TLS_DTV_AT_TP - /* This overlaps tcbhead_t (see tls.h), as used for TLS without threads. */ union { - tcbhead_t; - void *__padding[16]; - }; +#if !TLS_DTV_AT_TP + /* This overlaps the TCB as used for TLS without threads (see tls.h). */ + tcbhead_t header; #elif TLS_MULTIPLE_THREADS_IN_TCB - int multiple_threads; + struct + { + int multiple_threads; + } header; #endif + /* This extra padding has no special purpose, and this structure layout + is private and subject to change without affecting the official ABI. + We just have it here in case it might be convenient for some + implementation-specific instrumentation hack or suchlike. */ + void *__padding[16]; + }; + /* This descriptor's link on the `stack_used' or `__stack_user' list. */ list_t list; diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 0eb7dc7..ec00419 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -347,10 +347,10 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg) #ifdef TLS_TCB_AT_TP /* Reference to the TCB itself. */ - pd->self = pd; + pd->header.self = pd; /* Self-reference for TLS. */ - pd->tcb = pd; + pd->header.tcb = pd; #endif /* Store the address of the start routine and the parameter. Since diff --git a/nptl/sysdeps/i386/tls.h b/nptl/sysdeps/i386/tls.h index 6fb6adc..eea5e30 100644 --- a/nptl/sysdeps/i386/tls.h +++ b/nptl/sysdeps/i386/tls.h @@ -122,7 +122,7 @@ union user_desc_init /* Install new dtv for current thread. */ # define INSTALL_NEW_DTV(dtvp) \ ({ struct pthread *__pd; \ - THREAD_SETMEM (__pd, dtv, (dtvp)); }) + THREAD_SETMEM (__pd, header.dtv, (dtvp)); }) /* Return dtv of given thread descriptor. */ # define GET_DTV(descr) \ @@ -228,7 +228,7 @@ union user_desc_init /* Return the address of the dtv for the current thread. */ # define THREAD_DTV() \ ({ struct pthread *__pd; \ - THREAD_GETMEM (__pd, dtv); }) + THREAD_GETMEM (__pd, header.dtv); }) /* Return the thread descriptor for the current thread. @@ -240,7 +240,7 @@ union user_desc_init # define THREAD_SELF \ ({ struct pthread *__self; \ asm ("movl %%gs:%c1,%0" : "=r" (__self) \ - : "i" (offsetof (struct pthread, self))); \ + : "i" (offsetof (struct pthread, header.self))); \ __self;}) diff --git a/nptl/sysdeps/pthread/createthread.c b/nptl/sysdeps/pthread/createthread.c index 4ee92af..797176d 100644 --- a/nptl/sysdeps/pthread/createthread.c +++ b/nptl/sysdeps/pthread/createthread.c @@ -55,7 +55,7 @@ create_thread (struct pthread *pd, STACK_VARIABLES_PARMS) #endif #ifdef TLS_TCB_AT_TP - assert (pd->tcb != NULL); + assert (pd->header.tcb != NULL); #endif if (__builtin_expect (THREAD_GETMEM (THREAD_SELF, report_events), 0)) @@ -85,7 +85,7 @@ create_thread (struct pthread *pd, STACK_VARIABLES_PARMS) #ifdef TLS_MULTIPLE_THREADS_IN_TCB /* We now have for sure more than one thread. */ - pd->multiple_threads = 1; + pd->header.multiple_threads = 1; #else __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1; #endif @@ -114,7 +114,7 @@ create_thread (struct pthread *pd, STACK_VARIABLES_PARMS) } #ifdef NEED_DL_SYSINFO - assert (THREAD_GETMEM (THREAD_SELF, sysinfo) == pd->sysinfo); + assert (THREAD_GETMEM (THREAD_SELF, header.sysinfo) == pd->header.sysinfo); #endif /* We rely heavily on various flags the CLONE function understands: @@ -157,7 +157,7 @@ create_thread (struct pthread *pd, STACK_VARIABLES_PARMS) #ifdef TLS_MULTIPLE_THREADS_IN_TCB /* We now have for sure more than one thread. */ - THREAD_SETMEM (THREAD_SELF, multiple_threads, 1); + THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1); #endif return 0; diff --git a/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h b/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h index 6abb59a..35f05e1 100644 --- a/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h +++ b/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h @@ -78,7 +78,8 @@ # ifndef __ASSEMBLER__ # define SINGLE_THREAD_P \ - __builtin_expect (THREAD_GETMEM (THREAD_SELF, multiple_threads) == 0, 1) + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ + header.multiple_threads) == 0, 1) # else # define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET # endif diff --git a/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h index 5b99967..5a3ae51 100644 --- a/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h +++ b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h @@ -81,7 +81,7 @@ L(pseudo_end): # ifndef __ASSEMBLER__ # define SINGLE_THREAD_P \ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ - header.data.multiple_threads) == 0, 1) + header.multiple_threads) == 0, 1) # else # define SINGLE_THREAD_P \ ear %r1,%a0; \ diff --git a/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h b/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h index 2714747..16f8ad5 100644 --- a/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h +++ b/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h @@ -117,7 +117,8 @@ # ifndef __ASSEMBLER__ # define SINGLE_THREAD_P \ - __builtin_expect (THREAD_GETMEM (THREAD_SELF, multiple_threads) == 0, 1) + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ + header.multiple_threads) == 0, 1) # else # define SINGLE_THREAD_P \ stc gbr,r0; \ diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h index fb35b7b..e7fab7a 100644 --- a/nptl/sysdeps/x86_64/tls.h +++ b/nptl/sysdeps/x86_64/tls.h @@ -92,7 +92,7 @@ typedef struct /* Install new dtv for current thread. */ # define INSTALL_NEW_DTV(dtvp) \ ({ struct pthread *__pd; \ - THREAD_SETMEM (__pd, dtv, (dtvp)); }) + THREAD_SETMEM (__pd, header.dtv, (dtvp)); }) /* Return dtv of given thread descriptor. */ # define GET_DTV(descr) \ @@ -136,7 +136,7 @@ typedef struct /* Return the address of the dtv for the current thread. */ # define THREAD_DTV() \ ({ struct pthread *__pd; \ - THREAD_GETMEM (__pd, dtv); }) + THREAD_GETMEM (__pd, header.dtv); }) /* Return the thread descriptor for the current thread. @@ -148,7 +148,7 @@ typedef struct # define THREAD_SELF \ ({ struct pthread *__self; \ asm ("movq %%fs:%c1,%q0" : "=r" (__self) \ - : "i" (offsetof (struct pthread, self))); \ + : "i" (offsetof (struct pthread, header.self))); \ __self;}) -- 2.7.4