From dc33bef307ad6eeb1cc4e4e230b69c6058890388 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 17 Mar 2018 23:27:34 +0100 Subject: hurd: Replace threadvars with TLS This gets rid of a lot of kludge and gets closer to other ports. * hurd/Makefile (headers): Remove threadvar.h. (inline-headers): Remove threadvar.h. * hurd/Versions (GLIBC_2.0: Remove __hurd_sigthread_stack_base, __hurd_sigthread_stack_end, __hurd_sigthread_variables, __hurd_threadvar_max, __hurd_errno_location. (HURD_CTHREADS_0.3): Add pthread_getattr_np, pthread_attr_getstack. * hurd/hurd/signal.h: Do not include . (_hurd_self_sigstate): Use THREAD_SELF to get _hurd_sigstate. (_HURD_SIGNAL_H_EXTERN_INLINE): Use THREAD_SELF to get _hurd_sigstate, unless TLS is not initialized yet, in which case we do not need a critical section yet anyway. * hurd/hurd/threadvar.h: Include , do not include . (__hurd_sigthread_variables, __hurd_threadvar_max): Remove variables declarations. (__hurd_threadvar_index): Remove enum. (_HURD_THREADVAR_H_EXTERN_INLINE): Remove macro. (__hurd_threadvar_location_from_sp,__hurd_threadvar_location): Remove inlines. (__hurd_reply_port0): New variable declaration. (__hurd_local_reply_port): New macro. * hurd/hurdsig.c (__hurd_sigthread_variables): Remove variable. (interrupted_reply_port_location): Add thread_t parameter. Use it with THREAD_TCB to access thread-local variables. (_hurdsig_abort_rpcs): Pass ss->thread to interrupted_reply_port_location. (_hurd_internal_post_signal): Likewise. (_hurdsig_init): Use presence of cthread_fork instead of __hurd_threadvar_stack_mask to start signal thread by hand. Remove signal thread threadvar initialization. * hurd/hurdstartup.c: Do not include * hurd/sigunwind.c: Include (_hurdsig_longjmp_from_handler): Use __hurd_local_reply_port instead of threadvar. * sysdeps/mach/hurd/Versions (libc.GLIBC_PRIVATE): Add __libc_lock_self0. (ld.GLIBC_2.0): Remove __hurd_sigthread_stack_base, __hurd_sigthread_stack_end, __hurd_sigthread_variables. (ld.GLIBC_PRIVATE): Add __libc_lock_self0. * sysdeps/mach/hurd/cthreads.c: Add __libc_lock_self0. * sysdeps/mach/hurd/dl-sysdep.c (errno, __hurd_sigthread_stack_base, __hurd_sigthread_stack_end, __hurd_sigthread_variables, threadvars, __hurd_threadvar_stack_offset, __hurd_threadvar_stack_mask): Do not define variables. * sysdeps/mach/hurd/errno-loc.c: Do not include and . [IS_IN(rtld)] (rtld_errno): New variable. [IS_IN(rtld)] (__errno_location): New weak function. [!IS_IN(rtld)]: Include "../../../csu/errno-loc.c". * sysdeps/mach/hurd/errno.c: Remove file. * sysdeps/mach/hurd/fork.c: Include (__fork): Remove THREADVAR_SPACE macro and its use. * sysdeps/mach/hurd/i386/init-first.c (__hurd_threadvar_max): Remove variable. (init): Do not initialize threadvar. * sysdeps/mach/hurd/i386/libc.abilist (__hurd_threadvar_max): Remove symbol. * sysdeps/mach/hurd/i386/sigreturn.c (__sigreturn): Use __hurd_local_reply_port instead of threadvar. * sysdeps/mach/hurd/i386/tls.h (tcbhead_t): Add reply_port and _hurd_sigstate fields. (HURD_DESC_TLS, __LIBC_NO_TLS, THREAD_TCB): New macro. * sysdeps/mach/hurd/i386/trampoline.c: Remove outdated comment. * sysdeps/mach/hurd/libc-lock.h: Do not include . (__libc_lock_owner_self): Use &__libc_lock_self0 and THREAD_SELF instead of threadvar. * sysdeps/mach/hurd/libc-tsd.h: Remove file. * sysdeps/mach/hurd/mig-reply.c (GETPORT, reply_port): Remove macros. (use_threadvar, global_reply_port): Remove variables. (__hurd_reply_port0): New variable. (__mig_get_reply_port): Use __hurd_local_reply_port and __hurd_reply_port0 instead of threadvar. (__mig_dealloc_reply_port): Likewise. (__mig_init): Do not initialize threadvar. * sysdeps/mach/hurd/profil.c: Fix comment. --- hurd/hurdsig.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'hurd/hurdsig.c') diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c index 198546f..8069de3 100644 --- a/hurd/hurdsig.c +++ b/hurd/hurdsig.c @@ -49,7 +49,6 @@ thread_t _hurd_sigthread; /* These are set up by _hurdsig_init. */ unsigned long int __hurd_sigthread_stack_base; unsigned long int __hurd_sigthread_stack_end; -unsigned long int *__hurd_sigthread_variables; /* Linked-list of per-thread signal state. */ struct hurd_sigstate *_hurd_sigstates; @@ -235,14 +234,14 @@ abort_thread (struct hurd_sigstate *ss, struct machine_thread_all_state *state, that this location can be set without faulting, or else return NULL. */ static mach_port_t * -interrupted_reply_port_location (struct machine_thread_all_state *thread_state, +interrupted_reply_port_location (thread_t thread, + struct machine_thread_all_state *thread_state, int sigthread) { - mach_port_t *portloc = (mach_port_t *) __hurd_threadvar_location_from_sp - (_HURD_THREADVAR_MIG_REPLY, (void *) thread_state->basic.SP); + mach_port_t *portloc = &THREAD_TCB(thread, thread_state)->reply_port; if (sigthread && _hurdsig_catch_memory_fault (portloc)) - /* Faulted trying to read the stack. */ + /* Faulted trying to read the TCB. */ return NULL; /* Fault now if this pointer is bogus. */ @@ -324,7 +323,8 @@ _hurdsig_abort_rpcs (struct hurd_sigstate *ss, int signo, int sigthread, our nonzero return tells the trampoline code to finish the message receive operation before running the handler. */ - mach_port_t *reply = interrupted_reply_port_location (state, + mach_port_t *reply = interrupted_reply_port_location (ss->thread, + state, sigthread); error_t err = __interrupt_operation (intr_port, _hurdsig_interrupt_timeout); @@ -836,7 +836,8 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss, if (! machine_get_basic_state (ss->thread, &thread_state)) goto sigbomb; - loc = interrupted_reply_port_location (&thread_state, 1); + loc = interrupted_reply_port_location (ss->thread, + &thread_state, 1); if (loc && *loc != MACH_PORT_NULL) /* This is the reply port for the context which called sigreturn. Since we are abandoning that context entirely @@ -902,7 +903,8 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss, { /* Fetch the thread variable for the MiG reply port, and set it to MACH_PORT_NULL. */ - mach_port_t *loc = interrupted_reply_port_location (&thread_state, + mach_port_t *loc = interrupted_reply_port_location (ss->thread, + &thread_state, 1); if (loc) { @@ -1256,7 +1258,8 @@ _hurdsig_init (const int *intarray, size_t intarraysize) /* Start the signal thread listening on the message port. */ - if (__hurd_threadvar_stack_mask == 0) +#pragma weak cthread_fork + if (!cthread_fork) { err = __thread_create (__mach_task_self (), &_hurd_msgport_thread); assert_perror (err); @@ -1269,14 +1272,6 @@ _hurdsig_init (const int *intarray, size_t intarraysize) assert_perror (err); __hurd_sigthread_stack_end = __hurd_sigthread_stack_base + stacksize; - __hurd_sigthread_variables = - malloc (__hurd_threadvar_max * sizeof (unsigned long int)); - if (__hurd_sigthread_variables == NULL) - __libc_fatal ("hurd: Can't allocate threadvars for signal thread\n"); - memset (__hurd_sigthread_variables, 0, - __hurd_threadvar_max * sizeof (unsigned long int)); - __hurd_sigthread_variables[_HURD_THREADVAR_LOCALE] - = (unsigned long int) &_nl_global_locale; /* Reinitialize the MiG support routines so they will use a per-thread variable for the cached reply port. */ @@ -1296,7 +1291,6 @@ _hurdsig_init (const int *intarray, size_t intarraysize) we'll let the signal thread's per-thread variables be found as for any normal cthread, and just leave the magic __hurd_sigthread_* values all zero so they'll be ignored. */ -#pragma weak cthread_fork #pragma weak cthread_detach #pragma weak pthread_getattr_np #pragma weak pthread_attr_getstack -- cgit v1.1