mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
hurd: add TLS support
* sysdeps/generic/thread_state.h (MACHINE_NEW_THREAD_STATE_FLAVOR): Define macro. * sysdeps/mach/thread_state.h (MACHINE_THREAD_STATE_FIX_NEW): New macro. * sysdeps/mach/i386/thread_state.h (MACHINE_NEW_THREAD_STATE_FLAVOR): New macro, defined to i386_THREAD_STATE. (MACHINE_THREAD_STATE_FLAVOR): Define to i386_REGS_SEGS_STATE instead of i386_THREAD_STATE. (MACHINE_THREAD_STATE_FIX_NEW): New macro, reads segments. * sysdeps/mach/hurd/i386/trampoline.c (_hurd_setup_sighandler): Use i386_REGS_SEGS_STATE instead of i386_THREAD_STATE. * sysdeps/mach/hurd/i386/tls.h (TCB_ALIGNMENT, HURD_SEL_LDT): New macros. (_hurd_tls_fork): Add original thread parameter, Duplicate existing LDT descriptor instead of creating a new one. (_hurd_tls_new): New function, creates a new descriptor and updates tcb. * mach/setup-thread.c: Include <ldsodefs.h>. (__mach_setup_thread): Call _dl_allocate_tls, pass MACHINE_NEW_THREAD_STATE_FLAVOR to __thread_set_state instead of MACHINE_THREAD_STATE_FLAVOR, before getting MACHINE_THREAD_STATE_FLAVOR, calling _hurd_tls_new, and setting MACHINE_THREAD_STATE_FLAVOR with the result. * hurd/hurdfault.c (_hurdsig_fault_init): Call MACHINE_THREAD_STATE_FIX_NEW. * sysdeps/mach/hurd/fork.c (__fork): Call _hurd_tls_fork for sigthread too. Add original thread parameter.
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
#include <thread_state.h>
|
||||
#include <string.h>
|
||||
#include <mach/machine/vm_param.h>
|
||||
#include <ldsodefs.h>
|
||||
#include "sysdep.h" /* Defines stack direction. */
|
||||
|
||||
#define STACK_SIZE (16 * 1024 * 1024) /* 16MB, arbitrary. */
|
||||
@ -41,6 +42,7 @@ __mach_setup_thread (task_t task, thread_t thread, void *pc,
|
||||
vm_address_t stack;
|
||||
vm_size_t size;
|
||||
int anywhere;
|
||||
tcbhead_t *tcb;
|
||||
|
||||
size = stack_size ? *stack_size ? : STACK_SIZE : STACK_SIZE;
|
||||
stack = stack_base ? *stack_base ? : 0 : 0;
|
||||
@ -50,6 +52,10 @@ __mach_setup_thread (task_t task, thread_t thread, void *pc,
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
tcb = _dl_allocate_tls(NULL);
|
||||
if (tcb == NULL)
|
||||
return KERN_RESOURCE_SHORTAGE;
|
||||
|
||||
if (stack_size)
|
||||
*stack_size = size;
|
||||
|
||||
@ -72,8 +78,21 @@ __mach_setup_thread (task_t task, thread_t thread, void *pc,
|
||||
if (error = __vm_protect (task, stack, __vm_page_size, 0, VM_PROT_NONE))
|
||||
return error;
|
||||
|
||||
return __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
|
||||
(natural_t *) &ts, tssize);
|
||||
if (error = __thread_set_state (thread, MACHINE_NEW_THREAD_STATE_FLAVOR,
|
||||
(natural_t *) &ts, tssize))
|
||||
return error;
|
||||
|
||||
if (error = __thread_get_state (thread, MACHINE_THREAD_STATE_FLAVOR,
|
||||
(natural_t *) &ts, &tssize))
|
||||
return error;
|
||||
assert (tssize == MACHINE_THREAD_STATE_COUNT);
|
||||
|
||||
_hurd_tls_new(thread, &ts, tcb);
|
||||
|
||||
error = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
|
||||
(natural_t *) &ts, tssize);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
weak_alias (__mach_setup_thread, mach_setup_thread)
|
||||
|
Reference in New Issue
Block a user