2003-02-16 03:02:08 +00:00
|
|
|
/* Definitions for thread-local data handling. Hurd/i386 version.
|
2023-01-06 21:08:04 +00:00
|
|
|
Copyright (C) 2003-2023 Free Software Foundation, Inc.
|
2003-02-16 03:02:08 +00:00
|
|
|
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
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2003-02-16 03:02:08 +00:00
|
|
|
|
|
|
|
#ifndef _I386_TLS_H
|
|
|
|
#define _I386_TLS_H
|
|
|
|
|
|
|
|
|
|
|
|
/* Some things really need not be machine-dependent. */
|
2011-09-11 19:02:01 +00:00
|
|
|
#include <sysdeps/mach/hurd/tls.h>
|
2003-02-16 03:02:08 +00:00
|
|
|
|
2014-04-16 21:43:28 +00:00
|
|
|
|
|
|
|
#ifndef __ASSEMBLER__
|
2016-06-20 12:31:40 +00:00
|
|
|
# include <dl-dtv.h>
|
2014-04-16 21:43:28 +00:00
|
|
|
|
|
|
|
/* Type of the TCB. */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void *tcb; /* Points to this structure. */
|
|
|
|
dtv_t *dtv; /* Vector of pointers to TLS data. */
|
|
|
|
thread_t self; /* This thread's control port. */
|
2014-04-16 21:45:36 +00:00
|
|
|
int multiple_threads;
|
|
|
|
uintptr_t sysinfo;
|
|
|
|
uintptr_t stack_guard;
|
|
|
|
uintptr_t pointer_guard;
|
|
|
|
int gscope_flag;
|
|
|
|
int private_futex;
|
|
|
|
/* Reservation of some values for the TM ABI. */
|
|
|
|
void *__private_tm[4];
|
|
|
|
/* GCC split stack support. */
|
|
|
|
void *__private_ss;
|
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/threadvar.h>.
(_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 <tls.h>, do not include
<machine-sp.h>.
(__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/threadvar.h>
* hurd/sigunwind.c: Include <hurd/threadvar.h>
(_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 <errno.h> and
<hurd/threadvar.h>.
[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 <hurd/threadvar.h>
(__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 <hurd/threadvar.h>.
(__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.
2018-03-17 22:27:34 +00:00
|
|
|
|
2020-02-15 12:56:44 +00:00
|
|
|
/* Keep these fields last, so offsets of fields above can continue being
|
|
|
|
compatible with the i386 Linux version. */
|
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/threadvar.h>.
(_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 <tls.h>, do not include
<machine-sp.h>.
(__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/threadvar.h>
* hurd/sigunwind.c: Include <hurd/threadvar.h>
(_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 <errno.h> and
<hurd/threadvar.h>.
[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 <hurd/threadvar.h>
(__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 <hurd/threadvar.h>.
(__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.
2018-03-17 22:27:34 +00:00
|
|
|
mach_port_t reply_port; /* This thread's reply port. */
|
|
|
|
struct hurd_sigstate *_hurd_sigstate;
|
2022-11-03 08:39:31 +00:00
|
|
|
|
|
|
|
/* Used by the exception handling implementation in the dynamic loader. */
|
|
|
|
struct rtld_catch *rtld_catch;
|
2014-04-16 21:43:28 +00:00
|
|
|
} tcbhead_t;
|
|
|
|
|
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/threadvar.h>.
(_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 <tls.h>, do not include
<machine-sp.h>.
(__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/threadvar.h>
* hurd/sigunwind.c: Include <hurd/threadvar.h>
(_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 <errno.h> and
<hurd/threadvar.h>.
[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 <hurd/threadvar.h>
(__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 <hurd/threadvar.h>.
(__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.
2018-03-17 22:27:34 +00:00
|
|
|
/* 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. */
|
2022-08-22 20:34:31 +00:00
|
|
|
#ifndef SHARED
|
|
|
|
extern unsigned short __init1_desc;
|
|
|
|
#define __HURD_DESC_INITIAL(gs, ds) ((gs) == (ds) || (gs) == __init1_desc)
|
|
|
|
#else
|
|
|
|
#define __HURD_DESC_INITIAL(gs, ds) ((gs) == (ds))
|
|
|
|
#endif
|
|
|
|
|
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/threadvar.h>.
(_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 <tls.h>, do not include
<machine-sp.h>.
(__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/threadvar.h>
* hurd/sigunwind.c: Include <hurd/threadvar.h>
(_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 <errno.h> and
<hurd/threadvar.h>.
[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 <hurd/threadvar.h>
(__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 <hurd/threadvar.h>.
(__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.
2018-03-17 22:27:34 +00:00
|
|
|
#define __LIBC_NO_TLS() \
|
|
|
|
({ unsigned short ds, gs; \
|
|
|
|
asm ("movw %%ds,%w0; movw %%gs,%w1" : "=q" (ds), "=q" (gs)); \
|
2022-08-22 20:34:31 +00:00
|
|
|
__builtin_expect(__HURD_DESC_INITIAL(gs, ds), 0); })
|
|
|
|
#endif
|
2014-04-16 21:43:28 +00:00
|
|
|
|
2003-02-16 03:55:27 +00:00
|
|
|
/* The TCB can have any size and the memory following the address the
|
|
|
|
thread pointer points to is unspecified. Allocate the TCB there. */
|
2011-09-11 19:02:01 +00:00
|
|
|
#define TLS_TCB_AT_TP 1
|
2014-03-14 17:44:34 +00:00
|
|
|
#define TLS_DTV_AT_TP 0
|
2003-02-16 03:55:27 +00:00
|
|
|
|
2018-03-17 02:17:36 +00:00
|
|
|
/* Alignment requirement for TCB.
|
|
|
|
|
|
|
|
Some processors such as Intel Atom pay a big penalty on every
|
|
|
|
access using a segment override if that segment's base is not
|
|
|
|
aligned to the size of a cache line. (See Intel 64 and IA-32
|
|
|
|
Architectures Optimization Reference Manual, section 13.3.3.3,
|
|
|
|
"Segment Base".) On such machines, a cache line is 64 bytes. */
|
|
|
|
#define TCB_ALIGNMENT 64
|
|
|
|
|
2011-09-11 19:02:01 +00:00
|
|
|
#ifndef __ASSEMBLER__
|
2003-02-16 03:55:27 +00:00
|
|
|
|
2003-02-16 03:02:08 +00:00
|
|
|
/* Use i386-specific RPCs to arrange that %gs segment register prefix
|
|
|
|
addresses the TCB in each thread. */
|
|
|
|
# include <mach/i386/mach_i386.h>
|
|
|
|
|
2003-02-16 03:55:27 +00:00
|
|
|
# ifndef HAVE_I386_SET_GDT
|
2004-09-11 23:05:10 +00:00
|
|
|
# define __i386_set_gdt(thr, sel, desc) ((void) (thr), (void) (sel), (void) (desc), MIG_BAD_ID)
|
2003-02-16 03:55:27 +00:00
|
|
|
# endif
|
2003-02-16 03:02:08 +00:00
|
|
|
|
2003-02-16 03:55:27 +00:00
|
|
|
# include <errno.h>
|
|
|
|
# include <assert.h>
|
2003-02-16 03:02:08 +00:00
|
|
|
|
2011-09-11 19:02:01 +00:00
|
|
|
# define HURD_TLS_DESC_DECL(desc, tcb) \
|
2004-10-27 07:48:08 +00:00
|
|
|
struct descriptor desc = \
|
|
|
|
{ /* low word: */ \
|
|
|
|
0xffff /* limit 0..15 */ \
|
|
|
|
| (((unsigned int) (tcb)) << 16) /* base 0..15 */ \
|
|
|
|
, /* high word: */ \
|
|
|
|
((((unsigned int) (tcb)) >> 16) & 0xff) /* base 16..23 */ \
|
|
|
|
| ((0x12 | 0x60 | 0x80) << 8) /* access = ACC_DATA_W|ACC_PL_U|ACC_P */ \
|
|
|
|
| (0xf << 16) /* limit 16..19 */ \
|
|
|
|
| ((4 | 8) << 20) /* granularity = SZ_32|SZ_G */ \
|
|
|
|
| (((unsigned int) (tcb)) & 0xff000000) /* base 24..31 */ \
|
|
|
|
}
|
|
|
|
|
2018-03-17 23:06:19 +00:00
|
|
|
# define HURD_SEL_LDT(sel) (__builtin_expect ((sel) & 4, 0))
|
2004-10-27 07:48:08 +00:00
|
|
|
|
2022-11-03 16:28:03 +00:00
|
|
|
static inline bool __attribute__ ((unused))
|
2014-05-13 14:40:41 +00:00
|
|
|
_hurd_tls_init (tcbhead_t *tcb)
|
2003-02-16 03:02:08 +00:00
|
|
|
{
|
2004-10-27 07:48:08 +00:00
|
|
|
HURD_TLS_DESC_DECL (desc, tcb);
|
2018-03-18 19:27:16 +00:00
|
|
|
thread_t self = __mach_thread_self ();
|
2022-11-03 16:28:03 +00:00
|
|
|
bool success = true;
|
2003-02-16 03:02:08 +00:00
|
|
|
|
2014-05-13 14:40:41 +00:00
|
|
|
/* This field is used by TLS accesses to get our "thread pointer"
|
|
|
|
from the TLS point of view. */
|
|
|
|
tcb->tcb = tcb;
|
2018-07-19 23:12:08 +00:00
|
|
|
/* We always at least start the sigthread anyway. */
|
|
|
|
tcb->multiple_threads = 1;
|
2014-05-13 14:40:41 +00:00
|
|
|
|
|
|
|
/* Get the first available selector. */
|
|
|
|
int sel = -1;
|
2018-03-18 19:27:16 +00:00
|
|
|
error_t err = __i386_set_gdt (self, &sel, desc);
|
2014-05-13 14:40:41 +00:00
|
|
|
if (err == MIG_BAD_ID)
|
2003-02-16 03:02:08 +00:00
|
|
|
{
|
2014-05-13 14:40:41 +00:00
|
|
|
/* Old kernel, use a per-thread LDT. */
|
|
|
|
sel = 0x27;
|
2018-03-18 19:27:16 +00:00
|
|
|
err = __i386_set_ldt (self, sel, &desc, 1);
|
2014-05-13 14:40:41 +00:00
|
|
|
assert_perror (err);
|
|
|
|
if (err)
|
2018-03-18 19:27:16 +00:00
|
|
|
{
|
2022-11-03 16:28:03 +00:00
|
|
|
success = false;
|
2018-03-18 19:27:16 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2003-02-16 03:02:08 +00:00
|
|
|
}
|
2014-05-13 14:40:41 +00:00
|
|
|
else if (err)
|
2003-02-16 03:02:08 +00:00
|
|
|
{
|
2014-05-13 14:40:41 +00:00
|
|
|
assert_perror (err); /* Separate from above with different line #. */
|
2022-11-03 16:28:03 +00:00
|
|
|
success = false;
|
2018-03-18 19:27:16 +00:00
|
|
|
goto out;
|
2003-02-16 03:02:08 +00:00
|
|
|
}
|
|
|
|
|
2014-05-13 14:40:41 +00:00
|
|
|
/* Now install the new selector. */
|
|
|
|
asm volatile ("mov %w0, %%gs" :: "q" (sel));
|
|
|
|
|
2018-03-18 19:27:16 +00:00
|
|
|
out:
|
|
|
|
__mach_port_deallocate (__mach_task_self (), self);
|
2022-11-03 16:28:03 +00:00
|
|
|
return success;
|
2003-02-16 03:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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. */
|
2014-05-13 14:40:41 +00:00
|
|
|
# define TLS_INIT_TP(descr) \
|
|
|
|
_hurd_tls_init ((tcbhead_t *) (descr))
|
2004-09-02 23:58:23 +00:00
|
|
|
|
|
|
|
/* Return the TCB address of the current thread. */
|
2011-09-11 19:02:01 +00:00
|
|
|
# define THREAD_SELF \
|
2004-09-03 00:28:13 +00:00
|
|
|
({ tcbhead_t *__tcb; \
|
|
|
|
__asm__ ("movl %%gs:%c1,%0" : "=r" (__tcb) \
|
|
|
|
: "i" (offsetof (tcbhead_t, tcb))); \
|
2004-09-02 23:58:23 +00:00
|
|
|
__tcb;})
|
2003-02-16 03:02:08 +00:00
|
|
|
|
2020-02-15 13:04:02 +00:00
|
|
|
/* Read member of the thread descriptor directly. */
|
|
|
|
# define THREAD_GETMEM(descr, member) \
|
|
|
|
({ __typeof (descr->member) __value; \
|
2020-02-16 23:40:39 +00:00
|
|
|
_Static_assert (sizeof (__value) == 1 \
|
2020-02-17 10:08:15 +00:00
|
|
|
|| sizeof (__value) == 4 \
|
|
|
|
|| sizeof (__value) == 8, \
|
|
|
|
"size of per-thread data"); \
|
2020-02-15 13:04:02 +00:00
|
|
|
if (sizeof (__value) == 1) \
|
|
|
|
asm volatile ("movb %%gs:%P2,%b0" \
|
|
|
|
: "=q" (__value) \
|
|
|
|
: "0" (0), "i" (offsetof (tcbhead_t, member))); \
|
|
|
|
else if (sizeof (__value) == 4) \
|
|
|
|
asm volatile ("movl %%gs:%P1,%0" \
|
|
|
|
: "=r" (__value) \
|
|
|
|
: "i" (offsetof (tcbhead_t, member))); \
|
2020-02-16 23:40:39 +00:00
|
|
|
else /* 8 */ \
|
2020-02-15 13:04:02 +00:00
|
|
|
{ \
|
|
|
|
asm volatile ("movl %%gs:%P1,%%eax\n\t" \
|
|
|
|
"movl %%gs:%P2,%%edx" \
|
|
|
|
: "=A" (__value) \
|
|
|
|
: "i" (offsetof (tcbhead_t, member)), \
|
|
|
|
"i" (offsetof (tcbhead_t, member) + 4)); \
|
|
|
|
} \
|
|
|
|
__value; })
|
|
|
|
|
|
|
|
|
|
|
|
/* Same as THREAD_GETMEM, but the member offset can be non-constant. */
|
|
|
|
# define THREAD_GETMEM_NC(descr, member, idx) \
|
|
|
|
({ __typeof (descr->member[0]) __value; \
|
2020-02-16 23:40:39 +00:00
|
|
|
_Static_assert (sizeof (__value) == 1 \
|
2020-02-17 10:08:15 +00:00
|
|
|
|| sizeof (__value) == 4 \
|
|
|
|
|| sizeof (__value) == 8, \
|
|
|
|
"size of per-thread data"); \
|
2020-02-15 13:04:02 +00:00
|
|
|
if (sizeof (__value) == 1) \
|
|
|
|
asm volatile ("movb %%gs:%P2(%3),%b0" \
|
|
|
|
: "=q" (__value) \
|
|
|
|
: "0" (0), "i" (offsetof (tcbhead_t, member[0])), \
|
|
|
|
"r" (idx)); \
|
|
|
|
else if (sizeof (__value) == 4) \
|
|
|
|
asm volatile ("movl %%gs:%P1(,%2,4),%0" \
|
|
|
|
: "=r" (__value) \
|
|
|
|
: "i" (offsetof (tcbhead_t, member[0])), \
|
|
|
|
"r" (idx)); \
|
2020-02-16 23:40:39 +00:00
|
|
|
else /* 8 */ \
|
2020-02-15 13:04:02 +00:00
|
|
|
{ \
|
|
|
|
asm volatile ("movl %%gs:%P1(,%2,8),%%eax\n\t" \
|
|
|
|
"movl %%gs:4+%P1(,%2,8),%%edx" \
|
|
|
|
: "=&A" (__value) \
|
|
|
|
: "i" (offsetof (tcbhead_t, member[0])), \
|
|
|
|
"r" (idx)); \
|
|
|
|
} \
|
|
|
|
__value; })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Set member of the thread descriptor directly. */
|
|
|
|
# define THREAD_SETMEM(descr, member, value) \
|
2020-02-16 23:40:39 +00:00
|
|
|
({ \
|
|
|
|
_Static_assert (sizeof (descr->member) == 1 \
|
2020-02-17 10:08:15 +00:00
|
|
|
|| sizeof (descr->member) == 4 \
|
|
|
|
|| sizeof (descr->member) == 8, \
|
|
|
|
"size of per-thread data"); \
|
2020-02-16 23:40:39 +00:00
|
|
|
if (sizeof (descr->member) == 1) \
|
2020-02-15 13:04:02 +00:00
|
|
|
asm volatile ("movb %b0,%%gs:%P1" : \
|
|
|
|
: "iq" (value), \
|
|
|
|
"i" (offsetof (tcbhead_t, member))); \
|
|
|
|
else if (sizeof (descr->member) == 4) \
|
|
|
|
asm volatile ("movl %0,%%gs:%P1" : \
|
|
|
|
: "ir" (value), \
|
|
|
|
"i" (offsetof (tcbhead_t, member))); \
|
2020-02-16 23:40:39 +00:00
|
|
|
else /* 8 */ \
|
2020-02-15 13:04:02 +00:00
|
|
|
{ \
|
|
|
|
asm volatile ("movl %%eax,%%gs:%P1\n\t" \
|
|
|
|
"movl %%edx,%%gs:%P2" : \
|
|
|
|
: "A" ((uint64_t) cast_to_integer (value)), \
|
|
|
|
"i" (offsetof (tcbhead_t, member)), \
|
|
|
|
"i" (offsetof (tcbhead_t, member) + 4)); \
|
|
|
|
}})
|
|
|
|
|
|
|
|
|
|
|
|
/* Same as THREAD_SETMEM, but the member offset can be non-constant. */
|
|
|
|
# define THREAD_SETMEM_NC(descr, member, idx, value) \
|
2020-02-16 23:40:39 +00:00
|
|
|
({ \
|
|
|
|
_Static_assert (sizeof (descr->member[0]) == 1 \
|
2020-02-17 10:08:15 +00:00
|
|
|
|| sizeof (descr->member[0]) == 4 \
|
|
|
|
|| sizeof (descr->member[0]) == 8, \
|
|
|
|
"size of per-thread data"); \
|
2020-02-16 23:40:39 +00:00
|
|
|
if (sizeof (descr->member[0]) == 1) \
|
2020-02-15 13:04:02 +00:00
|
|
|
asm volatile ("movb %b0,%%gs:%P1(%2)" : \
|
|
|
|
: "iq" (value), \
|
|
|
|
"i" (offsetof (tcbhead_t, member)), \
|
|
|
|
"r" (idx)); \
|
|
|
|
else if (sizeof (descr->member[0]) == 4) \
|
|
|
|
asm volatile ("movl %0,%%gs:%P1(,%2,4)" : \
|
|
|
|
: "ir" (value), \
|
|
|
|
"i" (offsetof (tcbhead_t, member)), \
|
|
|
|
"r" (idx)); \
|
2020-02-16 23:40:39 +00:00
|
|
|
else /* 8 */ \
|
2020-02-15 13:04:02 +00:00
|
|
|
{ \
|
|
|
|
asm volatile ("movl %%eax,%%gs:%P1(,%2,8)\n\t" \
|
|
|
|
"movl %%edx,%%gs:4+%P1(,%2,8)" : \
|
|
|
|
: "A" ((uint64_t) cast_to_integer (value)), \
|
|
|
|
"i" (offsetof (tcbhead_t, member)), \
|
|
|
|
"r" (idx)); \
|
|
|
|
}})
|
|
|
|
|
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/threadvar.h>.
(_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 <tls.h>, do not include
<machine-sp.h>.
(__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/threadvar.h>
* hurd/sigunwind.c: Include <hurd/threadvar.h>
(_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 <errno.h> and
<hurd/threadvar.h>.
[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 <hurd/threadvar.h>
(__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 <hurd/threadvar.h>.
(__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.
2018-03-17 22:27:34 +00:00
|
|
|
/* 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; \
|
2018-03-17 23:06:19 +00:00
|
|
|
if (HURD_SEL_LDT (__sel)) \
|
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/threadvar.h>.
(_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 <tls.h>, do not include
<machine-sp.h>.
(__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/threadvar.h>
* hurd/sigunwind.c: Include <hurd/threadvar.h>
(_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 <errno.h> and
<hurd/threadvar.h>.
[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 <hurd/threadvar.h>
(__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 <hurd/threadvar.h>.
(__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.
2018-03-17 22:27:34 +00:00
|
|
|
__err = __i386_get_ldt ((thread), __sel, 1, &___desc, &__count); \
|
|
|
|
else \
|
|
|
|
__err = __i386_get_gdt ((thread), __sel, &__desc); \
|
|
|
|
assert_perror (__err); \
|
|
|
|
assert (__count == 1); \
|
2018-03-17 23:06:19 +00:00
|
|
|
HURD_DESC_TLS (___desc);})
|
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/threadvar.h>.
(_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 <tls.h>, do not include
<machine-sp.h>.
(__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/threadvar.h>
* hurd/sigunwind.c: Include <hurd/threadvar.h>
(_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 <errno.h> and
<hurd/threadvar.h>.
[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 <hurd/threadvar.h>
(__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 <hurd/threadvar.h>.
(__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.
2018-03-17 22:27:34 +00:00
|
|
|
|
2003-02-16 03:02:08 +00:00
|
|
|
/* Install new dtv for current thread. */
|
2004-09-03 00:28:13 +00:00
|
|
|
# define INSTALL_NEW_DTV(dtvp) \
|
|
|
|
({ asm volatile ("movl %0,%%gs:%P1" \
|
2004-09-02 23:58:23 +00:00
|
|
|
: : "ir" (dtvp), "i" (offsetof (tcbhead_t, dtv))); })
|
2003-02-16 03:02:08 +00:00
|
|
|
|
|
|
|
/* Return the address of the dtv for the current thread. */
|
2011-09-11 19:02:01 +00:00
|
|
|
# define THREAD_DTV() \
|
2004-09-03 20:49:00 +00:00
|
|
|
({ dtv_t *_dtv; \
|
2004-09-03 00:28:13 +00:00
|
|
|
asm ("movl %%gs:%P1,%0" : "=q" (_dtv) : "i" (offsetof (tcbhead_t, dtv)));\
|
2004-09-02 23:58:23 +00:00
|
|
|
_dtv; })
|
2003-02-16 03:02:08 +00:00
|
|
|
|
2020-06-06 00:00:19 +00:00
|
|
|
|
|
|
|
/* Set the stack guard field in TCB head. */
|
|
|
|
#define THREAD_SET_STACK_GUARD(value) \
|
|
|
|
THREAD_SETMEM (THREAD_SELF, stack_guard, value)
|
|
|
|
#define THREAD_COPY_STACK_GUARD(descr) \
|
|
|
|
((descr)->stack_guard \
|
|
|
|
= THREAD_GETMEM (THREAD_SELF, stack_guard))
|
|
|
|
|
2020-06-06 01:26:00 +00:00
|
|
|
/* Set the pointer guard field in the TCB head. */
|
|
|
|
#define THREAD_SET_POINTER_GUARD(value) \
|
|
|
|
THREAD_SETMEM (THREAD_SELF, pointer_guard, value)
|
|
|
|
#define THREAD_COPY_POINTER_GUARD(descr) \
|
|
|
|
((descr)->pointer_guard \
|
|
|
|
= THREAD_GETMEM (THREAD_SELF, pointer_guard))
|
|
|
|
|
2020-06-06 00:00:19 +00:00
|
|
|
|
2011-09-11 19:02:01 +00:00
|
|
|
# include <mach/machine/thread_status.h>
|
2004-10-29 01:25:24 +00:00
|
|
|
|
2018-03-17 02:17:36 +00:00
|
|
|
/* Set up TLS in the new thread of a fork child, copying from the original. */
|
|
|
|
static inline kern_return_t __attribute__ ((unused))
|
|
|
|
_hurd_tls_fork (thread_t child, thread_t orig, struct i386_thread_state *state)
|
|
|
|
{
|
|
|
|
/* Fetch the selector set by _hurd_tls_init. */
|
|
|
|
int sel;
|
|
|
|
asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
|
|
|
|
if (sel == state->ds) /* _hurd_tls_init was never called. */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
struct descriptor desc, *_desc = &desc;
|
|
|
|
error_t err;
|
|
|
|
unsigned int count = 1;
|
|
|
|
|
2018-03-17 23:06:19 +00:00
|
|
|
if (HURD_SEL_LDT (sel))
|
2018-03-17 02:17:36 +00:00
|
|
|
err = __i386_get_ldt (orig, sel, 1, &_desc, &count);
|
|
|
|
else
|
|
|
|
err = __i386_get_gdt (orig, sel, &desc);
|
|
|
|
|
|
|
|
assert_perror (err);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-03-17 23:06:19 +00:00
|
|
|
if (HURD_SEL_LDT (sel))
|
2018-03-17 02:17:36 +00:00
|
|
|
err = __i386_set_ldt (child, sel, &desc, 1);
|
|
|
|
else
|
|
|
|
err = __i386_set_gdt (child, &sel, desc);
|
|
|
|
|
|
|
|
state->gs = sel;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline kern_return_t __attribute__ ((unused))
|
|
|
|
_hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb)
|
2004-10-27 07:48:08 +00:00
|
|
|
{
|
|
|
|
/* Fetch the selector set by _hurd_tls_init. */
|
|
|
|
int sel;
|
2006-03-05 02:53:03 +00:00
|
|
|
asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
|
2004-10-27 07:48:08 +00:00
|
|
|
if (sel == state->ds) /* _hurd_tls_init was never called. */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
HURD_TLS_DESC_DECL (desc, tcb);
|
|
|
|
error_t err;
|
|
|
|
|
2018-03-17 02:17:36 +00:00
|
|
|
tcb->tcb = tcb;
|
|
|
|
tcb->self = child;
|
|
|
|
|
2018-03-17 23:06:19 +00:00
|
|
|
if (HURD_SEL_LDT (sel))
|
2004-10-27 07:48:08 +00:00
|
|
|
err = __i386_set_ldt (child, sel, &desc, 1);
|
|
|
|
else
|
|
|
|
err = __i386_set_gdt (child, &sel, desc);
|
|
|
|
|
|
|
|
state->gs = sel;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-09-15 17:11:09 +00:00
|
|
|
/* Global scope switch support. */
|
|
|
|
# define THREAD_GSCOPE_FLAG_UNUSED 0
|
|
|
|
# define THREAD_GSCOPE_FLAG_USED 1
|
|
|
|
# define THREAD_GSCOPE_FLAG_WAIT 2
|
|
|
|
|
|
|
|
# define THREAD_GSCOPE_SET_FLAG() \
|
|
|
|
THREAD_SETMEM (THREAD_SELF, gscope_flag, THREAD_GSCOPE_FLAG_USED)
|
|
|
|
|
|
|
|
# define THREAD_GSCOPE_RESET_FLAG() \
|
|
|
|
({ \
|
|
|
|
int __flag; \
|
|
|
|
asm volatile ("xchgl %0, %%gs:%P1" \
|
|
|
|
: "=r" (__flag) \
|
|
|
|
: "i" (offsetof (tcbhead_t, gscope_flag)), \
|
|
|
|
"0" (THREAD_GSCOPE_FLAG_UNUSED)); \
|
|
|
|
if (__flag == THREAD_GSCOPE_FLAG_WAIT) \
|
|
|
|
lll_wake (THREAD_SELF->gscope_flag, LLL_PRIVATE); \
|
|
|
|
})
|
|
|
|
|
2011-09-11 19:02:01 +00:00
|
|
|
#endif /* !__ASSEMBLER__ */
|
2003-02-16 03:02:08 +00:00
|
|
|
|
|
|
|
#endif /* i386/tls.h */
|