From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id F41A83858C78 for ; Mon, 20 Feb 2023 10:32:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F41A83858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTtAo-000188-LR; Sun, 19 Feb 2023 18:32:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=In-Reply-To:MIME-Version:References:Subject:To:From: Date; bh=hnwOql5oEs90t9d78rL9ZA657ei5MhTEIlrFwFd6kEM=; b=SOB6Xswo9CWAVQHXVcZt sNqF64ym5srMBcLXKEj8cGvcSs79hPlCSq2SCgXWGjm8DlUG4CYR/36qJi98ZkujuhaP0tw/Sk2dF /aVZcgquVN3Ntoq4KuYJ17PNKV77sMUNl8HITiWxEID/sOUPCgH1BD0bPQ+8xiu6MWtzo1gohUd0T 0jLu8PIxvkmbNkKOo8Lvtsw/Mk53anuCXtbLBbpvFzWHb9DTmjmba8r+iVsH39U8adD9C41/aiBc8 4nzHSLow/MEiO0gGzwCP8Vf/q7WZ/cZKnHlDczZK+dFzHwrRkyAVCCp/owcdk4wv74rQjr5ihohjc OXeUhV5/z65qSQ==; Received: from lfbn-bor-1-1163-184.w92-158.abo.wanadoo.fr ([92.158.138.184] helo=begin) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTtAo-0006hK-4b; Sun, 19 Feb 2023 18:32:50 -0500 Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1pTtAk-0015BM-2c; Mon, 20 Feb 2023 00:32:46 +0100 Date: Mon, 20 Feb 2023 00:32:46 +0100 From: Samuel Thibault To: Sergey Bugaev Cc: bug-hurd@gnu.org, libc-alpha@sourceware.org, =?utf-8?Q?Fl=C3=A1vio?= Cruz Subject: Re: [RFC PATCH 1/9] hurd: Move thread state manipulation into _hurd_tls_new () Message-ID: <20230219233246.jhl4ohsescupm5ox@begin> Mail-Followup-To: Sergey Bugaev , bug-hurd@gnu.org, libc-alpha@sourceware.org, =?utf-8?Q?Fl=C3=A1vio?= Cruz References: <20230218203717.373211-1-bugaevc@gmail.com> <20230218203717.373211-2-bugaevc@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230218203717.373211-2-bugaevc@gmail.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Applied, thanks! Sergey Bugaev, le sam. 18 févr. 2023 23:37:09 +0300, a ecrit: > This is going to be done differently on x86_64. > > Signed-off-by: Sergey Bugaev > --- > 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 6ce5c13d..ae24a149 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 590abd47..0f8dd241 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. */ > -- > 2.39.2 > > -- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.