From patchwork Thu Aug 29 23:49:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1155567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104914-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.b="XhR707OI"; 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 46KK8c5Krdz9sDB for ; Fri, 30 Aug 2019 09:49:36 +1000 (AEST) 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=cEO 8H2TU+bQPbTW1snxezdSQC/znFM9/RM0IG/uqYdLuDbQOh/fVXeT8VRnDbv87lon OgoV9RiQQjlJXdiZUOANi9xGEPhvSbotZiPilK8BZWzSQo7VHKI7ymR2w5vdZPKl ca+2gwcn6aWjjDTe4xBeP73akJUXJgwbw8W2eMws= 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=Gm+8p75Ik rOV026/l7pJ4TV/Hm0=; b=XhR707OIynGT75IXM9LF4yLC+ba014+L8nt+DYukD HnBzrcyPG2qUMREdeU062eSITRtiBauPQUKn9R0g7RAsuhcbvOszW5hcDQOy1Ap3 4HBoQaj5NMSiCACswuGFPB91ZB79tt1yONzIFj3OoXqosTpvbkH608xzny+DYjLc 5s= Received: (qmail 44943 invoked by alias); 29 Aug 2019 23:49:30 -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 44848 invoked by uid 89); 29 Aug 2019 23:49:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.9 required=5.0 tests=AWL, 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=destroy X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited] hurd: Fix SS_ONSTACK support Date: Fri, 30 Aug 2019 01:49:13 +0200 Message-Id: <20190829234913.32035-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 * sysdeps/mach/hurd/i386/sigreturn.c (__sigreturn2): New function, unlocks SS and returns to the saved PC. (__sigreturn): Do not unlock SS, and "return" into __sigreturn2 on the thread stack instead of the saved PC. --- ChangeLog | 5 +++ sysdeps/mach/hurd/i386/sigreturn.c | 68 ++++++++++++++++++------------ 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98a86369d5..12d183dbc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,11 @@ * sysdeps/mach/hurd/mmap.c (__mmap): Remove optimizing anonymous maps as __vm_allocate. + * sysdeps/mach/hurd/i386/sigreturn.c (__sigreturn2): New function, + unlocks SS and returns to the saved PC. + (__sigreturn): Do not unlock SS, and "return" into __sigreturn2 on the + thread stack instead of the saved PC. + 2019-08-30 Richard Braun * hurd/hurdselect.c (_hurd_select): Always call __io_select with no diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c index be7153e202..c9eaf96f7d 100644 --- a/sysdeps/mach/hurd/i386/sigreturn.c +++ b/sysdeps/mach/hurd/i386/sigreturn.c @@ -24,6 +24,36 @@ register int *sp asm ("%esp"); #include #include +/* This is run on the thread stack after restoring it, to be able to + unlock SS off sigstack. */ +static void +__sigreturn2 (int *usp) +{ + struct hurd_sigstate *ss = _hurd_self_sigstate (); + __spin_unlock (ss); + + sp = usp; +#define A(line) asm volatile (#line) + /* The members in the sigcontext are arranged in this order + so we can pop them easily. */ + + /* Pop the segment registers (except %cs and %ss, done last). */ + A (popl %gs); + A (popl %fs); + A (popl %es); + A (popl %ds); + /* Pop the general registers. */ + A (popa); + /* Pop the processor flags. */ + A (popf); + /* Return to the saved PC. */ + A (ret); + + /* Firewall. */ + A (hlt); +#undef A +} + int __sigreturn (struct sigcontext *scp) { @@ -67,13 +97,7 @@ __sigreturn (struct sigcontext *scp) } if (scp->sc_onstack) - { - ss->sigaltstack.ss_flags &= ~SS_ONSTACK; - /* XXX cannot unlock until off sigstack */ - abort (); - } - else - __spin_unlock (&ss->lock); + ss->sigaltstack.ss_flags &= ~SS_ONSTACK; /* Destroy the MiG reply port used by the signal handler, and restore the reply port in use by the thread when interrupted. */ @@ -108,27 +132,19 @@ __sigreturn (struct sigcontext *scp) *--usp = scp->sc_efl; memcpy (usp -= 12, &scp->sc_i386_thread_state, 12 * sizeof (int)); - sp = usp; - -#define A(line) asm volatile (#line) - /* The members in the sigcontext are arranged in this order - so we can pop them easily. */ - - /* Pop the segment registers (except %cs and %ss, done last). */ - A (popl %gs); - A (popl %fs); - A (popl %es); - A (popl %ds); - /* Pop the general registers. */ - A (popa); - /* Pop the processor flags. */ - A (popf); - /* Return to the saved PC. */ - A (ret); + /* Pass usp to __sigreturn2 so it can unwind itself easily. */ + *(usp-1) = (int) usp; + --usp; + /* Bogus return address for __sigreturn2 */ + *--usp = 0; + *--usp = (int) __sigreturn2; + /* Restore thread stack */ + sp = usp; + /* Return into __sigreturn2. */ + asm volatile ("ret"); /* Firewall. */ - A (hlt); -#undef A + asm volatile ("hlt"); } /* NOTREACHED */