From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1792) id 17C1D3858D39; Sun, 19 Feb 2023 23:32:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17C1D3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676849565; bh=FNTKnJGUvLqT/rZUsmKzyaadAMl0H+wPYRld0z4DA9k=; h=From:To:Subject:Date:From; b=igwLgluzopKN/Mf4cns9wXyLZlJ841L8J46H93Uor+phi58xTiZvngIVpIQGabwKr kN/eLPMRMMNxjRAdkQ00JmljSQ3yt1g1Nfl+kBzcNemfN/lbJS49QCQEDUOu7+x2lq kvNQhqYR/+zKDpEuMz0k3A8Pl7D6ApWbXKp7Lb58= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Samuel Thibault To: glibc-cvs@sourceware.org Subject: [glibc] hurd: Move thread state manipulation into _hurd_tls_new () X-Act-Checkin: glibc X-Git-Author: Sergey Bugaev X-Git-Refname: refs/heads/master X-Git-Oldrev: a307e1b31551821946b242ca98f5db9e7d9f558a X-Git-Newrev: e48f33e76be2a3baa920b7e9f472354f7ff0c0a6 Message-Id: <20230219233245.17C1D3858D39@sourceware.org> Date: Sun, 19 Feb 2023 23:32:45 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e48f33e76be2a3baa920b7e9f472354f7ff0c0a6 commit e48f33e76be2a3baa920b7e9f472354f7ff0c0a6 Author: Sergey Bugaev Date: Sat Feb 18 23:37:09 2023 +0300 hurd: Move thread state manipulation into _hurd_tls_new () This is going to be done differently on x86_64. Signed-off-by: Sergey Bugaev Message-Id: <20230218203717.373211-2-bugaevc@gmail.com> Diff: --- mach/setup-thread.c | 18 ++---------------- sysdeps/mach/hurd/i386/tls.h | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/mach/setup-thread.c b/mach/setup-thread.c index 6ce5c13d37..ae24a14955 100644 --- a/mach/setup-thread.c +++ b/mach/setup-thread.c @@ -83,25 +83,11 @@ weak_alias (__mach_setup_thread, mach_setup_thread) kern_return_t __mach_setup_tls (thread_t thread) { - kern_return_t error; - struct machine_thread_state ts; - mach_msg_type_number_t tssize = MACHINE_THREAD_STATE_COUNT; - tcbhead_t *tcb; - - tcb = _dl_allocate_tls (NULL); + tcbhead_t *tcb = _dl_allocate_tls (NULL); if (tcb == NULL) return KERN_RESOURCE_SHORTAGE; - 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; + return _hurd_tls_new (thread, tcb); } weak_alias (__mach_setup_tls, mach_setup_tls) diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h index 590abd47fe..0f8dd24145 100644 --- a/sysdeps/mach/hurd/i386/tls.h +++ b/sysdeps/mach/hurd/i386/tls.h @@ -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)) -_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. */ int sel; 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; HURD_TLS_DESC_DECL (desc, tcb); - error_t err; tcb->tcb = tcb; tcb->self = child; @@ -397,8 +406,14 @@ _hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb) else err = __i386_set_gdt (child, &sel, desc); - state->gs = sel; - return err; + if (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. */