diff options
Diffstat (limited to 'sysdeps/mach')
-rw-r--r-- | sysdeps/mach/hurd/Versions | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/cthreads.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/dl-sysdep.c | 19 | ||||
-rw-r--r-- | sysdeps/mach/hurd/errno-loc.c | 22 | ||||
-rw-r--r-- | sysdeps/mach/hurd/errno.c | 1 | ||||
-rw-r--r-- | sysdeps/mach/hurd/fork.c | 7 | ||||
-rw-r--r-- | sysdeps/mach/hurd/i386/init-first.c | 37 | ||||
-rw-r--r-- | sysdeps/mach/hurd/i386/libc.abilist | 1 | ||||
-rw-r--r-- | sysdeps/mach/hurd/i386/sigreturn.c | 5 | ||||
-rw-r--r-- | sysdeps/mach/hurd/i386/tls.h | 33 | ||||
-rw-r--r-- | sysdeps/mach/hurd/i386/trampoline.c | 2 | ||||
-rw-r--r-- | sysdeps/mach/hurd/libc-lock.h | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/libc-tsd.h | 34 | ||||
-rw-r--r-- | sysdeps/mach/hurd/mig-reply.c | 39 | ||||
-rw-r--r-- | sysdeps/mach/hurd/profil.c | 6 |
15 files changed, 74 insertions, 144 deletions
diff --git a/sysdeps/mach/hurd/Versions b/sysdeps/mach/hurd/Versions index 89e19061af..7cab8e8551 100644 --- a/sysdeps/mach/hurd/Versions +++ b/sysdeps/mach/hurd/Versions @@ -6,6 +6,7 @@ libc { GLIBC_PRIVATE { # Functions shared with the dynamic linker __libc_read; __libc_write; __libc_lseek64; + __libc_lock_self0; _dl_init_first; } @@ -14,8 +15,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 @@ -33,5 +32,6 @@ ld { # functions that must be shared with libc __libc_read; __libc_write; __libc_lseek64; + __libc_lock_self0; } } diff --git a/sysdeps/mach/hurd/cthreads.c b/sysdeps/mach/hurd/cthreads.c index e0cf4ddca7..640c97ec1d 100644 --- a/sysdeps/mach/hurd/cthreads.c +++ b/sysdeps/mach/hurd/cthreads.c @@ -19,6 +19,10 @@ #include <errno.h> #include <stdlib.h> +/* This serves as stub "self" pointer for libc locks when TLS is not initialized + yet. */ +char __libc_lock_self0[0]; + /* Placeholder for key creation routine from Hurd cthreads library. */ int weak_function diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index 1317fd5328..cbf4e05862 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -70,25 +70,6 @@ void *_dl_random attribute_relro = NULL; struct hurd_startup_data *_dl_hurd_data; -/* This is used only within ld.so, via dl-minimal.c's __errno_location. */ -#undef errno -int errno attribute_hidden; - -/* 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/errno-loc.c b/sysdeps/mach/hurd/errno-loc.c index 7b1e7ce347..95d0fe47c4 100644 --- a/sysdeps/mach/hurd/errno-loc.c +++ b/sysdeps/mach/hurd/errno-loc.c @@ -16,13 +16,21 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ -#include <errno.h> -#include <hurd/threadvar.h> - -int * +#if IS_IN (rtld) +/* + * rtld can not access TLS too early, thus rtld_errno. + * + * Instead of making __open/__close pass errno from TLS to rtld_errno, simply + * use a weak __errno_location using rtld_errno, which will be overriden by the + * libc definition. + */ +static int rtld_errno; +int * weak_function __errno_location (void) { - return (int *) __hurd_threadvar_location (_HURD_THREADVAR_ERRNO); + return &rtld_errno; } -strong_alias (__errno_location, __hurd_errno_location) -libc_hidden_def (__errno_location) +libc_hidden_weak (__errno_location) +#else +#include "../../../csu/errno-loc.c" +#endif diff --git a/sysdeps/mach/hurd/errno.c b/sysdeps/mach/hurd/errno.c deleted file mode 100644 index a29091b5e2..0000000000 --- a/sysdeps/mach/hurd/errno.c +++ /dev/null @@ -1 +0,0 @@ -/* No definition of `errno' variable on the Hurd. */ diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c index cc322ebee5..2d1e64c8d1 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. */ @@ -483,19 +484,17 @@ __fork (void) (natural_t *) &state, &statecount)) LOSE; #ifdef 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 965b53ca9e..f4a4df33de 100644 --- a/sysdeps/mach/hurd/i386/init-first.c +++ b/sysdeps/mach/hurd/i386/init-first.c @@ -35,7 +35,6 @@ extern void __mach_init (void); extern void __init_misc (int, char **, char **); extern void __libc_global_ctors (void); -unsigned int __hurd_threadvar_max; unsigned long int __hurd_threadvar_stack_offset; unsigned long int __hurd_threadvar_stack_mask; @@ -169,15 +168,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); - threadvars[_HURD_THREADVAR_LOCALE] = (unsigned long int) &_nl_global_locale; - __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 @@ -190,13 +180,6 @@ init (int *data) ++envp; d = (void *) ++envp; - /* 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 @@ -212,11 +195,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); @@ -257,25 +235,10 @@ 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/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist index 991c41b374..9545e898c1 100644 --- a/sysdeps/mach/hurd/i386/libc.abilist +++ b/sysdeps/mach/hurd/i386/libc.abilist @@ -285,7 +285,6 @@ GLIBC_2.2.6 __gettimeofday F GLIBC_2.2.6 __gmtime_r F GLIBC_2.2.6 __h_errno_location F GLIBC_2.2.6 __hurd_fail F -GLIBC_2.2.6 __hurd_threadvar_max D 0x4 GLIBC_2.2.6 __hurd_threadvar_stack_mask D 0x4 GLIBC_2.2.6 __hurd_threadvar_stack_offset D 0x4 GLIBC_2.2.6 __isalnum_l F diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c index 8ec1d4b91f..07633e17c8 100644 --- a/sysdeps/mach/hurd/i386/sigreturn.c +++ b/sysdeps/mach/hurd/i386/sigreturn.c @@ -68,7 +68,7 @@ __sigreturn (struct sigcontext *scp) if (scp->sc_onstack) { - ss->sigaltstack.ss_flags &= ~SS_ONSTACK; /* XXX threadvars */ + ss->sigaltstack.ss_flags &= ~SS_ONSTACK; /* XXX cannot unlock until off sigstack */ abort (); } @@ -77,8 +77,7 @@ __sigreturn (struct sigcontext *scp) /* Destroy the MiG reply port used by the signal handler, and restore the reply port in use by the thread when interrupted. */ - reply_port = - (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY); + reply_port = &__hurd_local_reply_port; if (*reply_port) { mach_port_t port = *reply_port; diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h index 4c78685045..6cd1730887 100644 --- a/sysdeps/mach/hurd/i386/tls.h +++ b/sysdeps/mach/hurd/i386/tls.h @@ -43,9 +43,27 @@ typedef struct void *__private_tm[4]; /* GCC split stack support. */ void *__private_ss; + + /* Keep this field last, so fields above can continue being compatible with + the Linux version. */ + mach_port_t reply_port; /* This thread's reply port. */ + struct hurd_sigstate *_hurd_sigstate; } tcbhead_t; #endif +/* Return tcbhead_t from a TLS segment descriptor. */ +# define HURD_DESC_TLS(desc) \ + ({ \ + (tcbhead_t *) ( (desc->low_word >> 16) \ + | ((desc->high_word & 0xff) << 16) \ + | (desc->high_word & 0xff000000)); \ + }) + +/* Return 1 if TLS is not initialized yet. */ +#define __LIBC_NO_TLS() \ + ({ unsigned short ds, gs; \ + asm ("movw %%ds,%w0; movw %%gs,%w1" : "=q" (ds), "=q" (gs)); \ + __builtin_expect(ds == gs, 0); }) /* The TCB can have any size and the memory following the address the thread pointer points to is unspecified. Allocate the TCB there. */ @@ -138,6 +156,21 @@ _hurd_tls_init (tcbhead_t *tcb) : "i" (offsetof (tcbhead_t, tcb))); \ __tcb;}) +/* Return the TCB address of a thread given its state. + Note: this is expensive. */ +# define THREAD_TCB(thread, thread_state) \ + ({ int __sel = (thread_state)->basic.gs; \ + struct descriptor __desc, *___desc = &__desc; \ + unsigned int __count = 1; \ + kern_return_t __err; \ + if (HURD_SEL_LDT(__sel)) \ + __err = __i386_get_ldt ((thread), __sel, 1, &___desc, &__count); \ + else \ + __err = __i386_get_gdt ((thread), __sel, &__desc); \ + assert_perror (__err); \ + assert (__count == 1); \ + HURD_DESC_TLS(___desc);}) + /* Install new dtv for current thread. */ # define INSTALL_NEW_DTV(dtvp) \ ({ asm volatile ("movl %0,%%gs:%P1" \ diff --git a/sysdeps/mach/hurd/i386/trampoline.c b/sysdeps/mach/hurd/i386/trampoline.c index 0c68759f42..0e795f9389 100644 --- a/sysdeps/mach/hurd/i386/trampoline.c +++ b/sysdeps/mach/hurd/i386/trampoline.c @@ -79,8 +79,6 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, { sigsp = ss->sigaltstack.ss_sp + ss->sigaltstack.ss_size; ss->sigaltstack.ss_flags |= SS_ONSTACK; - /* XXX need to set up base of new stack for - per-thread variables, cthreads. */ } /* This code has intimate knowledge of the special mach_msg system call done in intr-msg.c; that code does (see intr-msg.h): diff --git a/sysdeps/mach/hurd/libc-lock.h b/sysdeps/mach/hurd/libc-lock.h index 371912efb7..2dfade93eb 100644 --- a/sysdeps/mach/hurd/libc-lock.h +++ b/sysdeps/mach/hurd/libc-lock.h @@ -21,7 +21,6 @@ #if (_LIBC - 0) || (_CTHREADS_ - 0) #include <cthreads.h> -#include <hurd/threadvar.h> /* The locking here is very inexpensive, even for inlining. */ #define _IO_lock_inexpensive 1 @@ -35,7 +34,8 @@ typedef struct } __libc_lock_recursive_t; typedef __libc_lock_recursive_t __rtld_lock_recursive_t; -#define __libc_lock_owner_self() ((void *) __hurd_threadvar_location (0)) +extern char __libc_lock_self0[0]; +#define __libc_lock_owner_self() (__LIBC_NO_TLS() ? &__libc_lock_self0 : THREAD_SELF) #else typedef struct __libc_lock_opaque__ __libc_lock_t; diff --git a/sysdeps/mach/hurd/libc-tsd.h b/sysdeps/mach/hurd/libc-tsd.h deleted file mode 100644 index fa131a2d5a..0000000000 --- a/sysdeps/mach/hurd/libc-tsd.h +++ /dev/null @@ -1,34 +0,0 @@ -/* libc-internal interface for thread-specific data. Hurd version. - Copyright (C) 1998-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ - -#ifndef _LIBC_TSD_H -#define _LIBC_TSD_H 1 - -#include <hurd/threadvar.h> - -#define __libc_tsd_define(CLASS, TYPE, KEY) /* nothing, always have threadvars */ - -#define __libc_tsd_address(TYPE, KEY) \ - ((TYPE *) __hurd_threadvar_location (_HURD_THREADVAR_##KEY)) - -#define __libc_tsd_get(TYPE, KEY) \ - (*__libc_tsd_address (TYPE, KEY)) -#define __libc_tsd_set(TYPE, KEY, VALUE) \ - (*__libc_tsd_address (TYPE, KEY) = (VALUE)) - -#endif /* libc-tsd.h */ diff --git a/sysdeps/mach/hurd/mig-reply.c b/sysdeps/mach/hurd/mig-reply.c index ed3705dc41..ddad12e070 100644 --- a/sysdeps/mach/hurd/mig-reply.c +++ b/sysdeps/mach/hurd/mig-reply.c @@ -18,26 +18,20 @@ #include <mach.h> #include <hurd/threadvar.h> -#define GETPORT \ - mach_port_t *portloc = \ - (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY) -#define reply_port (*(use_threadvar ? portloc : &global_reply_port)) - -static int use_threadvar; -static mach_port_t global_reply_port; - /* These functions are called by MiG-generated code. */ +mach_port_t __hurd_reply_port0; + /* Called by MiG to get a reply port. */ mach_port_t __mig_get_reply_port (void) { - GETPORT; - - if (reply_port == MACH_PORT_NULL) - reply_port = __mach_reply_port (); + if (__hurd_local_reply_port == MACH_PORT_NULL || + (&__hurd_local_reply_port != &__hurd_reply_port0 + && __hurd_local_reply_port == __hurd_reply_port0)) + __hurd_local_reply_port = __mach_reply_port (); - return reply_port; + return __hurd_local_reply_port; } weak_alias (__mig_get_reply_port, mig_get_reply_port) @@ -45,12 +39,8 @@ weak_alias (__mig_get_reply_port, mig_get_reply_port) void __mig_dealloc_reply_port (mach_port_t arg) { - mach_port_t port; - - GETPORT; - - port = reply_port; - reply_port = MACH_PORT_NULL; /* So the mod_refs RPC won't use it. */ + mach_port_t port = __hurd_local_reply_port; + __hurd_local_reply_port = MACH_PORT_NULL; /* So the mod_refs RPC won't use it. */ if (MACH_PORT_VALID (port)) __mach_port_mod_refs (__mach_task_self (), port, @@ -73,15 +63,6 @@ weak_alias (__mig_put_reply_port, mig_put_reply_port) void __mig_init (void *stack) { - use_threadvar = stack != 0; - - if (use_threadvar) - { - /* Recycle the reply port used before multithreading was enabled. */ - mach_port_t *portloc = (mach_port_t *) - __hurd_threadvar_location_from_sp (_HURD_THREADVAR_MIG_REPLY, stack); - *portloc = global_reply_port; - global_reply_port = MACH_PORT_NULL; - } + /* Do nothing. */ } weak_alias (__mig_init, mig_init) diff --git a/sysdeps/mach/hurd/profil.c b/sysdeps/mach/hurd/profil.c index b3f201b016..952398b4fa 100644 --- a/sysdeps/mach/hurd/profil.c +++ b/sysdeps/mach/hurd/profil.c @@ -141,7 +141,7 @@ weak_alias (__profil, profil) static volatile error_t special_profil_failure; /* 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) @@ -176,7 +176,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 |