hurd: Move thread state manipulation into _hurd_tls_new ()

This is going to be done differently on x86_64.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20230218203717.373211-2-bugaevc@gmail.com>
This commit is contained in:
Sergey Bugaev 2023-02-18 23:37:09 +03:00 committed by Samuel Thibault
parent a307e1b315
commit e48f33e76b
2 changed files with 22 additions and 21 deletions

View file

@ -83,25 +83,11 @@ weak_alias (__mach_setup_thread, mach_setup_thread)
kern_return_t kern_return_t
__mach_setup_tls (thread_t thread) __mach_setup_tls (thread_t thread)
{ {
kern_return_t error; tcbhead_t *tcb = _dl_allocate_tls (NULL);
struct machine_thread_state ts;
mach_msg_type_number_t tssize = MACHINE_THREAD_STATE_COUNT;
tcbhead_t *tcb;
tcb = _dl_allocate_tls (NULL);
if (tcb == NULL) if (tcb == NULL)
return KERN_RESOURCE_SHORTAGE; return KERN_RESOURCE_SHORTAGE;
if (error = __thread_get_state (thread, MACHINE_THREAD_STATE_FLAVOR, return _hurd_tls_new (thread, tcb);
(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_tls, mach_setup_tls) weak_alias (__mach_setup_tls, mach_setup_tls)

View file

@ -378,16 +378,25 @@ _hurd_tls_fork (thread_t child, thread_t orig, struct i386_thread_state *state)
} }
static inline kern_return_t __attribute__ ((unused)) static inline kern_return_t __attribute__ ((unused))
_hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb) _hurd_tls_new (thread_t child, tcbhead_t *tcb)
{ {
error_t err;
/* Fetch the target thread's state. */
struct i386_thread_state state;
mach_msg_type_number_t state_count = i386_THREAD_STATE_COUNT;
err = __thread_get_state (child, i386_REGS_SEGS_STATE,
(thread_state_t) &state,
&state_count);
if (err)
return err;
assert (state_count == i386_THREAD_STATE_COUNT);
/* Fetch the selector set by _hurd_tls_init. */ /* Fetch the selector set by _hurd_tls_init. */
int sel; int sel;
asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0)); asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
if (sel == state->ds) /* _hurd_tls_init was never called. */ if (sel == state.ds) /* _hurd_tls_init was never called. */
return 0; return 0;
HURD_TLS_DESC_DECL (desc, tcb); HURD_TLS_DESC_DECL (desc, tcb);
error_t err;
tcb->tcb = tcb; tcb->tcb = tcb;
tcb->self = child; tcb->self = child;
@ -397,8 +406,14 @@ _hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb)
else else
err = __i386_set_gdt (child, &sel, desc); err = __i386_set_gdt (child, &sel, desc);
state->gs = sel; if (err)
return err; return err;
/* Update gs to use the selector. */
state.gs = sel;
return __thread_set_state (child, i386_REGS_SEGS_STATE,
(thread_state_t) &state,
state_count);
} }
/* Global scope switch support. */ /* Global scope switch support. */