diff options
-rw-r--r-- | hurd/Versions | 4 | ||||
-rw-r--r-- | hurd/hurd/signal.h | 1 | ||||
-rw-r--r-- | hurd/hurd/threadvar.h | 78 | ||||
-rw-r--r-- | hurd/hurdsig.c | 32 | ||||
-rw-r--r-- | hurd/hurdstartup.c | 1 | ||||
-rw-r--r-- | hurd/sigunwind.c | 1 | ||||
-rw-r--r-- | sysdeps/mach/hurd/Versions | 2 | ||||
-rw-r--r-- | sysdeps/mach/hurd/dl-sysdep.c | 15 | ||||
-rw-r--r-- | sysdeps/mach/hurd/fork.c | 7 | ||||
-rw-r--r-- | sysdeps/mach/hurd/i386/init-first.c | 34 | ||||
-rw-r--r-- | sysdeps/mach/hurd/i386/makecontext-helper.c | 2 | ||||
-rw-r--r-- | sysdeps/mach/hurd/i386/makecontext.S | 2 | ||||
-rw-r--r-- | sysdeps/mach/hurd/profil.c | 6 |
13 files changed, 37 insertions, 148 deletions
diff --git a/hurd/Versions b/hurd/Versions index 2264faf25e..738281da15 100644 --- a/hurd/Versions +++ b/hurd/Versions @@ -25,14 +25,13 @@ libc { # weak refs to libthreads functions that libc calls iff libthreads in use cthread_fork; cthread_detach; + pthread_getattr_np; pthread_attr_getstack; %endif # necessary for the Hurd brk implementation _end; # variables used in macros & inline functions - __hurd_sigthread_stack_base; __hurd_sigthread_stack_end; - __hurd_sigthread_variables; __hurd_threadvar_max; __hurd_threadvar_stack_mask; __hurd_threadvar_stack_offset; @@ -158,6 +157,7 @@ libc { HURD_CTHREADS_0.3 { # weak refs to libthreads functions that libc calls iff libthreads in use cthread_fork; cthread_detach; + pthread_getattr_np; pthread_attr_getstack; # variables used for detecting cthreads _cthread_exit_routine; _cthread_init_routine; diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h index e9e0e0da1a..e633debe7c 100644 --- a/hurd/hurd/signal.h +++ b/hurd/hurd/signal.h @@ -40,7 +40,6 @@ #include <cthreads.h> /* For `struct mutex'. */ #include <setjmp.h> /* For `jmp_buf'. */ #include <spin-lock.h> -#include <hurd/threadvar.h> /* We cache sigstate in a threadvar. */ struct hurd_signal_preemptor; /* <hurd/sigpreempt.h> */ diff --git a/hurd/hurd/threadvar.h b/hurd/hurd/threadvar.h index 6dad87ab00..888d5354e9 100644 --- a/hurd/hurd/threadvar.h +++ b/hurd/hurd/threadvar.h @@ -31,93 +31,23 @@ __hurd_threadvar_stack_offset to a small offset that skips the data cthreads itself maintains at the base of each thread's stack. - In the single-threaded case, __hurd_threadvar_stack_mask is zero, so the - stack pointer is ignored; and __hurd_threadvar_stack_offset gives the - address of a small allocated region which contains the variables for the - single thread. */ + In the single-threaded or libpthread case, __hurd_threadvar_stack_mask is + zero, so the stack pointer is ignored. */ extern unsigned long int __hurd_threadvar_stack_mask; extern unsigned long int __hurd_threadvar_stack_offset; -/* A special case must always be made for the signal thread. Even when there - is only one user thread and an allocated region can be used for the user - thread's variables, the signal thread needs to have its own location for - per-thread variables. The variables __hurd_sigthread_stack_base and +/* The variables __hurd_sigthread_stack_base and __hurd_sigthread_stack_end define the bounds of the stack used by the signal thread, so that thread can always be specifically identified. */ extern unsigned long int __hurd_sigthread_stack_base; extern unsigned long int __hurd_sigthread_stack_end; -extern unsigned long int *__hurd_sigthread_variables; -/* At the location described by the two variables above, - there are __hurd_threadvar_max `unsigned long int's of per-thread data. */ +/* We do not use threadvars any more, this is kept as zero for compatibility with cthreads */ extern unsigned int __hurd_threadvar_max; -/* These values are the indices for the standard per-thread variables. */ -enum __hurd_threadvar_index - { - _HURD_THREADVAR_MIG_REPLY, /* Reply port for MiG user stub functions. */ - _HURD_THREADVAR_ERRNO, /* `errno' value for this thread. */ - _HURD_THREADVAR_SIGSTATE, /* This thread's `struct hurd_sigstate'. */ - _HURD_THREADVAR_DYNAMIC_USER, /* Dynamically-assigned user variables. */ - _HURD_THREADVAR_MALLOC, /* For use of malloc. */ - _HURD_THREADVAR_DL_ERROR, /* For use of -ldl and dynamic linker. */ - _HURD_THREADVAR_RPC_VARS, /* For state of RPC functions. */ - _HURD_THREADVAR_LOCALE, /* For thread-local locale setting. */ - _HURD_THREADVAR_CTYPE_B, /* Cache of thread-local locale data. */ - _HURD_THREADVAR_CTYPE_TOLOWER, /* Cache of thread-local locale data. */ - _HURD_THREADVAR_CTYPE_TOUPPER, /* Cache of thread-local locale data. */ - _HURD_THREADVAR_MAX /* Default value for __hurd_threadvar_max. */ - }; - - -#ifndef _HURD_THREADVAR_H_EXTERN_INLINE -#define _HURD_THREADVAR_H_EXTERN_INLINE __extern_inline -#endif - -/* Return the location of the value for the per-thread variable with index - INDEX used by the thread whose stack pointer is SP. */ - -extern unsigned long int *__hurd_threadvar_location_from_sp - (enum __hurd_threadvar_index __index, void *__sp); - -#if defined __USE_EXTERN_INLINES && defined _LIBC -_HURD_THREADVAR_H_EXTERN_INLINE unsigned long int * -__hurd_threadvar_location_from_sp (enum __hurd_threadvar_index __index, - void *__sp) -{ - unsigned long int __stack = (unsigned long int) __sp; - return &((__stack >= __hurd_sigthread_stack_base && - __stack < __hurd_sigthread_stack_end) - ? __hurd_sigthread_variables - : (unsigned long int *) ((__stack & __hurd_threadvar_stack_mask) + - __hurd_threadvar_stack_offset))[__index]; -} -#endif - -#include <machine-sp.h> /* Define __thread_stack_pointer. */ - -/* Return the location of the current thread's value for the - per-thread variable with index INDEX. */ - -extern unsigned long int * -__hurd_threadvar_location (enum __hurd_threadvar_index __index) __THROW - /* This declaration tells the compiler that the value is constant - given the same argument. We assume this won't be called twice from - the same stack frame by different threads. */ - __attribute__ ((__const__)); - -#if defined __USE_EXTERN_INLINES && defined _LIBC -_HURD_THREADVAR_H_EXTERN_INLINE unsigned long int * -__hurd_threadvar_location (enum __hurd_threadvar_index __index) -{ - return __hurd_threadvar_location_from_sp (__index, - __thread_stack_pointer ()); -} -#endif - extern mach_port_t __hurd_reply_port0; #define __hurd_local_reply_port (*(__LIBC_NO_TLS() ? &__hurd_reply_port0 : &THREAD_SELF->reply_port)) diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c index ee4227a294..1d87e2e973 100644 --- a/hurd/hurdsig.c +++ b/hurd/hurdsig.c @@ -20,6 +20,7 @@ #include <string.h> #include <cthreads.h> /* For `struct mutex'. */ +#include <pthread.h> #include <mach.h> #include <mach/thread_switch.h> @@ -48,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; /* Per-thread signal state. */ __thread struct hurd_sigstate *_hurd_sigstate; @@ -1261,7 +1261,11 @@ _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 +#pragma weak cthread_detach +#pragma weak pthread_getattr_np +#pragma weak pthread_attr_getstack + if (!cthread_fork) { err = __thread_create (__mach_task_self (), &_hurd_msgport_thread); assert_perror (err); @@ -1276,12 +1280,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)); /* Reinitialize the MiG support routines so they will use a per-thread variable for the cached reply port. */ @@ -1292,6 +1290,7 @@ _hurdsig_init (const int *intarray, size_t intarraysize) } else { + cthread_t thread; /* When cthreads is being used, we need to make the signal thread a proper cthread. Otherwise it cannot use mutex_lock et al, which will be the cthreads versions. Various of the message port RPC @@ -1301,9 +1300,20 @@ _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 - cthread_detach (cthread_fork ((cthread_fn_t) &_hurd_msgport_receive, 0)); + cthread_detach (thread = cthread_fork ((cthread_fn_t) &_hurd_msgport_receive, 0)); + + if (pthread_getattr_np) + { + /* Record stack layout for fork() */ + pthread_attr_t attr; + void *addr; + size_t size; + + pthread_getattr_np ((pthread_t) thread, &attr); + pthread_attr_getstack (&attr, &addr, &size); + __hurd_sigthread_stack_base = (uintptr_t) addr; + __hurd_sigthread_stack_end = __hurd_sigthread_stack_base + size; + } /* XXX We need the thread port for the signal thread further on in this thread (see hurdfault.c:_hurdsigfault_init). diff --git a/hurd/hurdstartup.c b/hurd/hurdstartup.c index 38147c94ea..688772ad35 100644 --- a/hurd/hurdstartup.c +++ b/hurd/hurdstartup.c @@ -23,7 +23,6 @@ #include <hurd.h> #include <hurd/exec_startup.h> #include <sysdep.h> -#include <hurd/threadvar.h> #include <unistd.h> #include <elf.h> #include <set-hooks.h> diff --git a/hurd/sigunwind.c b/hurd/sigunwind.c index 40af749479..a1819a2b36 100644 --- a/hurd/sigunwind.c +++ b/hurd/sigunwind.c @@ -18,6 +18,7 @@ #include <hurd.h> #include <thread_state.h> +#include <hurd/threadvar.h> #include <jmpbuf-unwind.h> #include <assert.h> #include <stdint.h> diff --git a/sysdeps/mach/hurd/Versions b/sysdeps/mach/hurd/Versions index 1f04244aea..9ecdbaf90e 100644 --- a/sysdeps/mach/hurd/Versions +++ b/sysdeps/mach/hurd/Versions @@ -16,8 +16,6 @@ libc { ld { GLIBC_2.0 { # variables that must be shared with libc - __hurd_sigthread_stack_base; __hurd_sigthread_stack_end; - __hurd_sigthread_variables; __hurd_threadvar_stack_mask; __hurd_threadvar_stack_offset; # functions that must be shared with libc diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index b5e7636e76..cea4a95991 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -64,21 +64,6 @@ hp_timing_t _dl_cpuclock_offset; struct hurd_startup_data *_dl_hurd_data; -/* Defining these variables here avoids the inclusion of hurdsig.c. */ -unsigned long int __hurd_sigthread_stack_base; -unsigned long int __hurd_sigthread_stack_end; -unsigned long int *__hurd_sigthread_variables; - -/* Defining these variables here avoids the inclusion of init-first.c. - We need to provide temporary storage for the per-thread variables - of the main user thread here, since it is used for storing the - `errno' variable. Note that this information is lost once we - relocate the dynamic linker. */ -static unsigned long int threadvars[_HURD_THREADVAR_MAX]; -unsigned long int __hurd_threadvar_stack_offset - = (unsigned long int) &threadvars; -unsigned long int __hurd_threadvar_stack_mask; - #define FMH defined(__i386__) #if ! FMH # define fmh() ((void)0) diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c index c3f88a90d8..6e7fe5f1ee 100644 --- a/sysdeps/mach/hurd/fork.c +++ b/sysdeps/mach/hurd/fork.c @@ -19,6 +19,7 @@ #include <unistd.h> #include <hurd.h> #include <hurd/signal.h> +#include <hurd/threadvar.h> #include <setjmp.h> #include <thread_state.h> #include <sysdep.h> /* For stack growth direction. */ @@ -497,19 +498,17 @@ __fork (void) (natural_t *) &state, &statecount)) LOSE; #if STACK_GROWTH_UP -#define THREADVAR_SPACE (__hurd_threadvar_max \ - * sizeof *__hurd_sightread_variables) if (__hurd_sigthread_stack_base == 0) { state.SP &= __hurd_threadvar_stack_mask; - state.SP += __hurd_threadvar_stack_offset + THREADVAR_SPACE; + state.SP += __hurd_threadvar_stack_offset; } else state.SP = __hurd_sigthread_stack_base; #else if (__hurd_sigthread_stack_end == 0) { - /* The signal thread has a normal stack assigned by cthreads. + /* The signal thread has a stack assigned by cthreads. The threadvar_stack variables conveniently tell us how to get to the highest address in the stack, just below the per-thread variables. */ diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c index 6cfbf48105..e9d1f04dfe 100644 --- a/sysdeps/mach/hurd/i386/init-first.c +++ b/sysdeps/mach/hurd/i386/init-first.c @@ -155,14 +155,6 @@ init (int *data) char **argv = (void *) (data + 1); char **envp = &argv[argc + 1]; struct hurd_startup_data *d; - unsigned long int threadvars[_HURD_THREADVAR_MAX]; - - /* Provide temporary storage for thread-specific variables on the - startup stack so the cthreads initialization code can use them - for malloc et al, or so we can use malloc below for the real - threadvars array. */ - memset (threadvars, 0, sizeof threadvars); - __hurd_threadvar_stack_offset = (unsigned long int) threadvars; /* Since the cthreads initialization code uses malloc, and the malloc initialization code needs to get at the environment, make @@ -208,13 +200,6 @@ init (int *data) __pthread_initialize_minimal(); #endif - /* The user might have defined a value for this, to get more variables. - Otherwise it will be zero on startup. We must make sure it is set - properly before before cthreads initialization, so cthreads can know - how much space to leave for thread variables. */ - if (__hurd_threadvar_max < _HURD_THREADVAR_MAX) - __hurd_threadvar_max = _HURD_THREADVAR_MAX; - /* After possibly switching stacks, call `init1' (above) with the user code as the return address, and the argument data immediately above @@ -230,11 +215,6 @@ init (int *data) __libc_stack_end = newsp; - /* Copy per-thread variables from that temporary - area onto the new cthread stack. */ - memcpy (__hurd_threadvar_location_from_sp (0, newsp), - threadvars, sizeof threadvars); - /* Copy the argdata from the old stack to the new one. */ newsp = memcpy (newsp - ((char *) &d[1] - (char *) data), data, (char *) d - (char *) data); @@ -275,25 +255,11 @@ init (int *data) } else { - /* We are not using cthreads, so we will have just a single allocated - area for the per-thread variables of the main user thread. */ - unsigned long int *array; unsigned int i; int usercode; void call_init1 (void); - array = malloc (__hurd_threadvar_max * sizeof (unsigned long int)); - if (array == NULL) - __libc_fatal ("Can't allocate single-threaded thread variables."); - - /* Copy per-thread variables from the temporary array into the - newly malloc'd space. */ - memcpy (array, threadvars, sizeof threadvars); - __hurd_threadvar_stack_offset = (unsigned long int) array; - for (i = _HURD_THREADVAR_MAX; i < __hurd_threadvar_max; ++i) - array[i] = 0; - /* The argument data is just above the stack frame we will unwind by returning. Mutate our own return address to run the code below. */ /* The following expression would typically be written as diff --git a/sysdeps/mach/hurd/i386/makecontext-helper.c b/sysdeps/mach/hurd/i386/makecontext-helper.c index 6db3b7e018..e604488264 100644 --- a/sysdeps/mach/hurd/i386/makecontext-helper.c +++ b/sysdeps/mach/hurd/i386/makecontext-helper.c @@ -22,6 +22,7 @@ #include <string.h> #include <ucontext.h> +#if 0 void __makecontext_helper (ucontext_t *ucp) @@ -67,3 +68,4 @@ __makecontext_helper (ucontext_t *ucp) ucp->uc_stack.ss_size -= t_size; } } +#endif diff --git a/sysdeps/mach/hurd/i386/makecontext.S b/sysdeps/mach/hurd/i386/makecontext.S index 7f3f6b0b90..b81403b04f 100644 --- a/sysdeps/mach/hurd/i386/makecontext.S +++ b/sysdeps/mach/hurd/i386/makecontext.S @@ -27,7 +27,7 @@ ENTRY(__makecontext) subl $4, %esp cfi_adjust_cfa_offset (4) movl %eax, (%esp) - call HIDDEN_JUMPTARGET (__makecontext_helper) + /* call HIDDEN_JUMPTARGET (__makecontext_helper) */ addl $4, %esp cfi_adjust_cfa_offset (-4) diff --git a/sysdeps/mach/hurd/profil.c b/sysdeps/mach/hurd/profil.c index e4be9483c4..7cae6ac7f6 100644 --- a/sysdeps/mach/hurd/profil.c +++ b/sysdeps/mach/hurd/profil.c @@ -139,7 +139,7 @@ __profil (u_short *sample_buffer, size_t size, size_t offset, u_int scale) weak_alias (__profil, profil) /* Fetch PC samples. This function must be very careful not to depend - on Hurd threadvar variables. We arrange that by using a special + on Hurd TLS variables. We arrange that by using a special stub arranged for at the end of this file. */ static void fetch_samples (void) @@ -175,7 +175,7 @@ fetch_samples (void) } -/* This function must be very careful not to depend on Hurd threadvar +/* This function must be very careful not to depend on Hurd TLS variables. We arrange that by using special stubs arranged for at the end of this file. */ static void @@ -267,7 +267,7 @@ text_set_element (_hurd_fork_child_hook, fork_profil_child); are fatal in profile_waiter anyhow. */ #define __mig_put_reply_port(foo) -/* Use our static variable instead of the usual threadvar mechanism for +/* Use our static variable instead of the usual TLS mechanism for this. */ #define __mig_get_reply_port() profil_reply_port |