From patchwork Fri Jun 18 19:29:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463078 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp174264jao; Fri, 18 Jun 2021 12:36:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtqfzSMqQcvL0mkE5FSJ71WcsCUCnJZyq7zv4xNgxOX0kCrm9HfXCevCCxLzGKVTPGfAws X-Received: by 2002:a6b:f618:: with SMTP id n24mr9366671ioh.174.1624044995515; Fri, 18 Jun 2021 12:36:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624044995; cv=none; d=google.com; s=arc-20160816; b=EdyEARmXE+Za/Sq3Bi4UK21UrhqP3Srwrd0iQGcDRUc4xfTl7yGx1XIag+ZJfQwi3+ 0Cy7TpBpfUv/Hsfxs02ic56Sl6QRz2CGfX1k+4T3Uqo2sDKKfB14pmpAzMiH66NcShke PaNM8S2CtTHmRne6bjqJSEgzIgr5iathcPteijhnjbwL4YGAyGgfIzLGOKe+wBwkfIzY rDUm725BuzXWLoEpsV+O7zu47WURaAs5+1k950zlhd3le5yVyvb2IAfQiO6o1ZuuhUCi wnzWI1d39ovFxS6bVBic3JLmHWIbhavxEQG5AIoKJLunn0r0uCuVAswk7tIOJvBUdQdv 34bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Kmu7xnRVWsU3eWGJbPPKgl5+mSDH//+NJHn4m15m2Pw=; b=yJcUawyaVEmUhbYipHYZ1JiYHa/P1ruQWUM23oSH0vBjEnT3Z2v9zFLrCDsGUaOimw cEJCWylTaBYc3Co40iPIxJrJ3dzFzuf2zLZOctBvujoVdK64OuemiN/74MNtdpq3HfIW LiBAxlaID567ATYLZFKurKBR0MzLxC3mgIGtBy2Ef9/OItLsCB2YqePy+JGLrdOdnmSx UNL4yKZK+8qW81S1/NmHxiNDROVfY1m7rmFjhbDhThm8GV2TtAOXKBgUf1WppGERcedI m6hThRYb2+hhqZPuN85DYfE8EH3edtjRmsjDdc+QYSZYQxdlUoj4XmxMfnZDY8a5Lu8V VkIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dxDQX56m; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z69si9780136iof.91.2021.06.18.12.36.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 12:36:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dxDQX56m; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luKI6-00068V-PR for patch@linaro.org; Fri, 18 Jun 2021 15:36:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luKBo-0001bU-Ua for qemu-devel@nongnu.org; Fri, 18 Jun 2021 15:30:05 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:37471) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luKBj-0001So-1j for qemu-devel@nongnu.org; Fri, 18 Jun 2021 15:30:04 -0400 Received: by mail-pf1-x42e.google.com with SMTP id y15so2618818pfl.4 for ; Fri, 18 Jun 2021 12:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Kmu7xnRVWsU3eWGJbPPKgl5+mSDH//+NJHn4m15m2Pw=; b=dxDQX56mM5aVhbrjiqVUUXkb6eNqKNlJBK+/HRkmsWFO8tLP4HuGULYH65nB79Z2De /0C7UlRBE6OeFS4XflOiOdklQKzTrH2l9AJslJU2MBN3g9qJ1gaZx3u9Lha4HoBKZ4f5 Qnm5mTXnSsZ3xNymQgkc7JtP5ZwZ7zhOl2cVaB34MkAjPfyJKTVtnvbrSi+aOWtcOzLx UjP4mejf9JeLreo+8DE/LgpKBjhYNiZUWa+wvpRy8Bo/gHrXjEUT+JumcGJ458n24SN+ IWFab3XYB+4ODWTXqYqPV/soF7SUAUEa/8cmO3YVugfrEk7P90oUDUk2duZel92j9910 vWqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kmu7xnRVWsU3eWGJbPPKgl5+mSDH//+NJHn4m15m2Pw=; b=elE4tsTopswm4euNgv30P73eESAfyHu8vTgLOBIm1/ZSUbunf38RDuLs+3Iltx+YhR 5drFneqdxjEGf9MWDg8TRTOPB3BZhBBxA6KTc9Yg3bRVstuCx9tR985AD7sAJSEkojpj CH8tkWjAIPwdfQfEmFquPLHfFf1NnUTIUQ+xP+1fbx0VYXEE0I2fa/wkxa+etSAZeGGQ 3ImTqIixiOkJ8q2MNmX9cv/sWDafBfyIi4HypRaLWcluMRA8qEMLFV7uXe74PthlJ0bq tXjmSR6JxNjB3BCtlE99R4SB5ll96zIsSnkWhGlgx+Bj6ACJgAEdxGwANKCYhtcjKKpb Tuiw== X-Gm-Message-State: AOAM5305+w2vAWVVe7yOwuEHEzAbagK7AU6yL15sJqehA0dMsL2ZLns/ PgDX4uSeBBwsenf2Zn8dz7UH6cxclh/gzA== X-Received: by 2002:a65:610c:: with SMTP id z12mr11670328pgu.453.1624044597869; Fri, 18 Jun 2021 12:29:57 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id 92sm11938234pjv.29.2021.06.18.12.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 12:29:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/23] linux-user/i386: Implement setup_sigtramp Date: Fri, 18 Jun 2021 12:29:38 -0700 Message-Id: <20210618192951.125651-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210618192951.125651-1-richard.henderson@linaro.org> References: <20210618192951.125651-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create and record the two signal trampolines. Use them when the guest does not use SA_RESTORER. Note that x86_64 does not use this code. Signed-off-by: Richard Henderson --- linux-user/i386/target_signal.h | 2 ++ linux-user/x86_64/target_signal.h | 3 +++ linux-user/i386/signal.c | 42 ++++++++++++++++++------------- 3 files changed, 29 insertions(+), 18 deletions(-) -- 2.25.1 diff --git a/linux-user/i386/target_signal.h b/linux-user/i386/target_signal.h index 50361af874..64d09f2e75 100644 --- a/linux-user/i386/target_signal.h +++ b/linux-user/i386/target_signal.h @@ -22,4 +22,6 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" #define TARGET_ARCH_HAS_SETUP_FRAME +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif /* I386_TARGET_SIGNAL_H */ diff --git a/linux-user/x86_64/target_signal.h b/linux-user/x86_64/target_signal.h index 4ea74f20dd..4673c5a886 100644 --- a/linux-user/x86_64/target_signal.h +++ b/linux-user/x86_64/target_signal.h @@ -21,4 +21,7 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" +/* For x86_64, use of SA_RESTORER is mandatory. */ +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0 + #endif /* X86_64_TARGET_SIGNAL_H */ diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 8701774e37..a83ecba54f 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -337,16 +337,7 @@ void setup_frame(int sig, struct target_sigaction *ka, if (ka->sa_flags & TARGET_SA_RESTORER) { __put_user(ka->sa_restorer, &frame->pretcode); } else { - uint16_t val16; - abi_ulong retcode_addr; - retcode_addr = frame_addr + offsetof(struct sigframe, retcode); - __put_user(retcode_addr, &frame->pretcode); - /* This is popl %eax ; movl $,%eax ; int $0x80 */ - val16 = 0xb858; - __put_user(val16, (uint16_t *)(frame->retcode+0)); - __put_user(TARGET_NR_sigreturn, (int *)(frame->retcode+2)); - val16 = 0x80cd; - __put_user(val16, (uint16_t *)(frame->retcode+6)); + __put_user(default_sigreturn, &frame->pretcode); } /* Set up registers for signal handler */ @@ -415,14 +406,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, if (ka->sa_flags & TARGET_SA_RESTORER) { __put_user(ka->sa_restorer, &frame->pretcode); } else { - uint16_t val16; - addr = frame_addr + offsetof(struct rt_sigframe, retcode); - __put_user(addr, &frame->pretcode); - /* This is movl $,%eax ; int $0x80 */ - __put_user(0xb8, (char *)(frame->retcode+0)); - __put_user(TARGET_NR_rt_sigreturn, (int *)(frame->retcode+1)); - val16 = 0x80cd; - __put_user(val16, (uint16_t *)(frame->retcode+5)); + __put_user(default_rt_sigreturn, &frame->pretcode); } #else /* XXX: Would be slightly better to return -EFAULT here if test fails @@ -591,3 +575,25 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +#ifndef TARGET_X86_64 +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint16_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 * 8, 0); + assert(tramp != NULL); + + default_sigreturn = sigtramp_page; + /* This is popl %eax ; movl $,%eax ; int $0x80 */ + __put_user(0xb858, (uint16_t *)(tramp + 0)); + __put_user(TARGET_NR_sigreturn, (int *)(tramp + 2)); + __put_user(0x80cd, (uint16_t *)(tramp + 6)); + + default_rt_sigreturn = sigtramp_page + 8; + /* This is movl $,%eax ; int $0x80 */ + __put_user(0xb8, (char *)(tramp + 8)); + __put_user(TARGET_NR_rt_sigreturn, (int *)(tramp + 9)); + __put_user(0x80cd, (uint16_t *)(tramp + 13)); + + unlock_user(tramp, sigtramp_page, 2 * 8); +} +#endif