From patchwork Sat Feb 15 13:23:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1238526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-109803-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha1 header.s=default header.b=EDSsUXIC; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48KWD50Rrsz9sP7 for ; Sun, 16 Feb 2020 00:23:48 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; q=dns; s=default; b=lQo a1JB3HynK45jqmjtQg5cxYkKthnnYnuODgKqp4+Rj+0R6Dfk+bUqC7ElSheeCzdI UzFXqtpQFyvVYkvRASHpACP5+RZhnkpbVHutSqAGLUb4Tad2LNJf192EpQXm1pSY Aawa5f/Yx0IZQu8LJmNNhGHSS+ECaQHOtP6hAVys= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=default; bh=B9VJ5pLsI gj0xyFJNk43gkIML1g=; b=EDSsUXICaIUhSUQ/v5lLgrEL55OfZ1iCSyERVpZ0d qXyNXJaNK5Wv2eOk9a+cDI2ciEwzOQP9PZFAYHh+McNlgEUR5VXgWwNCa2UCzk2A BMpnnw8mWUP/gCh8b6oqdmQfvuo/I8ed2FsMD8kQO+8hpWsXFBPUgo6T+4K1NYTT uA= Received: (qmail 118411 invoked by alias); 15 Feb 2020 13:23:42 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 118400 invoked by uid 89); 15 Feb 2020 13:23:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.1 spammy=thread_setmem, THREAD_SETMEM, thread_getmem, THREAD_GETMEM X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited] hurd: Add THREAD_GET/SETMEM/_NC Date: Sat, 15 Feb 2020 05:23:27 -0800 Message-Id: <20200215132327.130884-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Store them in the TCB, and use them for accessing _hurd_sigstate. --- hurd/hurd/signal.h | 11 ++-- sysdeps/mach/hurd/i386/tls.h | 108 +++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 5 deletions(-) diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h index 6583dcb5b1..ef6a8e6687 100644 --- a/hurd/hurd/signal.h +++ b/hurd/hurd/signal.h @@ -164,9 +164,9 @@ extern void _hurd_sigstate_delete (thread_t thread); _HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate * _hurd_self_sigstate (void) { - if (THREAD_SELF->_hurd_sigstate == NULL) - THREAD_SELF->_hurd_sigstate = _hurd_thread_sigstate (__mach_thread_self ()); - return THREAD_SELF->_hurd_sigstate; + if (THREAD_GETMEM (THREAD_SELF, _hurd_sigstate) == NULL) + THREAD_SETMEM (THREAD_SELF, _hurd_sigstate, _hurd_thread_sigstate (__mach_thread_self ())); + return THREAD_GETMEM (THREAD_SELF, _hurd_sigstate); } # endif #endif @@ -210,14 +210,15 @@ _hurd_critical_section_lock (void) return NULL; #endif - ss = THREAD_SELF->_hurd_sigstate; + ss = THREAD_GETMEM (THREAD_SELF, _hurd_sigstate); if (ss == NULL) { /* The thread variable is unset; this must be the first time we've asked for it. In this case, the critical section flag cannot possible already be set. Look up our sigstate structure the slow way. */ - ss = THREAD_SELF->_hurd_sigstate = _hurd_thread_sigstate (__mach_thread_self ()); + ss = _hurd_thread_sigstate (__mach_thread_self ()); + THREAD_SETMEM(THREAD_SELF, _hurd_sigstate, ss); } if (! __spin_try_lock (&ss->critical_section_lock)) diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h index c0341ce2c9..7ec8c81a76 100644 --- a/sysdeps/mach/hurd/i386/tls.h +++ b/sysdeps/mach/hurd/i386/tls.h @@ -163,6 +163,114 @@ out: : "i" (offsetof (tcbhead_t, tcb))); \ __tcb;}) +/* Read member of the thread descriptor directly. */ +# define THREAD_GETMEM(descr, member) \ + ({ __typeof (descr->member) __value; \ + 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))); \ + else \ + { \ + if (sizeof (__value) != 8) \ + /* There should not be any value with a size other than 1, \ + 4 or 8. */ \ + abort (); \ + \ + 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; \ + 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)); \ + else \ + { \ + if (sizeof (__value) != 8) \ + /* There should not be any value with a size other than 1, \ + 4 or 8. */ \ + abort (); \ + \ + 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) \ + ({ if (sizeof (descr->member) == 1) \ + 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))); \ + else \ + { \ + if (sizeof (descr->member) != 8) \ + /* There should not be any value with a size other than 1, \ + 4 or 8. */ \ + abort (); \ + \ + 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) \ + ({ if (sizeof (descr->member[0]) == 1) \ + 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)); \ + else \ + { \ + if (sizeof (descr->member[0]) != 8) \ + /* There should not be any value with a size other than 1, \ + 4 or 8. */ \ + abort (); \ + \ + 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)); \ + }}) + /* Return the TCB address of a thread given its state. Note: this is expensive. */ # define THREAD_TCB(thread, thread_state) \