From patchwork Tue Jul 6 23:48:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470561 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5544862ejx; Tue, 6 Jul 2021 16:50:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGitWx6E1bM/nsnK0fOhsAEY8R3qdICcvzemRu+oVZ66fa+bAbH30NSQ6oaX1GD4mPF7dR X-Received: by 2002:a05:620a:1998:: with SMTP id bm24mr10148175qkb.422.1625615445665; Tue, 06 Jul 2021 16:50:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615445; cv=none; d=google.com; s=arc-20160816; b=wrqjWsE2wOdb4VSI4Yn9b5MEGVDaqsH2IxZ7XF4dv4fojbw+pDpBJ6IcYWW5FUIHKZ 36smMixciv1Rp2UVqjCwlZssOKP/876W12vczKSWbHgySCtKcLWZMR+wgV1AiNEgxW8Z K8B3dlfyNhHXrv4wPbOLQcrRADjGCDBfW/SxpQ6JqbhXxfd4M0VIvLz5hZO9qnNpPEsN SEdKWLNa3CgImE5lAMZ9oxrPQPbSg9pjWkGo1JNlE0JzPufJEKLDXfy3RPZFLmCM+395 OUwyh8bTovxn0zVvLmRJOOOyaeAzkT5uP3SHUGt8ImyneebD/bt88bUCl0D8u+kGRk88 mFjA== 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=yIyLE4ZuKOJBD86psPDmEqSsQf6PKknNWhMLksJinUE=; b=c1YeMAy/5/m2RF4PguSSSbvsNUhaBL3K+zN9ZUtKwoNby2ZgVdZy9JTKmbUXh0iLNg hIxo2rh0dsYPaBlEDxJ48DSUQazKkQa+QmOKRWKuSS3evKwikj2b4NV3QuSbz6/P+W2i X9ThZ3bgpgEaSGnSi/Hx6i9RsHgviwo7qmpnbLLmv7oxy0GTyDQ0pXfQxc0Z+r4+8RNN 3WjElGIOBvPjIPPOnws7jr1LiMI0v+OYQl+eMuGSc2eboJ3yzq3n6qvAz3lrsTsIg8eF wUkyOmTvbDCVGmbUagCjXR+1puERpCq68x90B6vkXCTqZzDPA6qf0hye1wtITnd4i3Ot qVrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=t4YmFwWT; 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 a23si6631012qtp.239.2021.07.06.16.50.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:50:45 -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=t4YmFwWT; 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]:35722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0upw-0000ik-TF for patch@linaro.org; Tue, 06 Jul 2021 19:50:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uor-0000gj-Eq for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:37 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:43897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uop-0006as-FH for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:37 -0400 Received: by mail-pg1-x529.google.com with SMTP id o18so383554pgu.10 for ; Tue, 06 Jul 2021 16:49:35 -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=yIyLE4ZuKOJBD86psPDmEqSsQf6PKknNWhMLksJinUE=; b=t4YmFwWTTdUDGGmvYJtNPTODBkCkCOlKY+HO+Fh5IPsJH4GdL4dH15/Sdi2Ty03pEq FNdB8u4toqY7SJAMq9vy+OQzx73Mn0xD27lKr9f1PiuUQOBilN97VQjZx4w/gWXl1RoX IQsumo7d2Kq9yPBfyaD8W3viSrdyWHMU/byZYqMqZO4bj5Ect46ZQ9VXAH9GU8uX/Vuw PfG35JsLCYIYFmuW0aqwl1nfrHMYxpzQ6gy4gNsIJBg5U1BJb4OVfG00SmSgafJkO0rx CTlXfgXcdsH2i7/CdNStit0jN6JigvpSj/JUfyK5M8eCRfQJ3FyqnNjNtqUo9KUjz1nF OvoQ== 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=yIyLE4ZuKOJBD86psPDmEqSsQf6PKknNWhMLksJinUE=; b=QfnvsBT2WA16c+dTH+4vdLZgFW50YsPOxIagSIDd9ItczeVMHW6FvfrI+rKNZOAhYx 8ZygqPXOq9prRp9vPbksW+JAWUpYRfNcLamtZBaSd2DV6BRfBkG3ipUQHnz5hGDHJCVd j1rTcr+kHu+sMlYaxLMmScTIJhwtJud+aKKcMg65hHHqKDC990GjSF9/WK7ChM7bZAJJ ah/XVMh0bWrDaC+Sd78QkokiR+sMwAPW5h7/1uiTjkpS8Kld8+K3U9NTS63ODJa9oVSf kFzGyriYTcFYfKADzzlLulVpiY8sHygagh/uFVFLlpQyAUIjuifvEj1Eq6DId/D9bF6Z 9v1g== X-Gm-Message-State: AOAM5303QgoR6l5EjoesHl24pOl30cYNf8UrGCbolh58Wqi3ESms6Im4 nG9ExFC2fHicliNBZISIwV+QqfMvopJoAg== X-Received: by 2002:a62:6c4:0:b029:324:8262:b3aa with SMTP id 187-20020a6206c40000b02903248262b3aamr3065112pfg.25.1625615374148; Tue, 06 Jul 2021 16:49:34 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 01/36] linux-user: Add infrastructure for a signal trampoline page Date: Tue, 6 Jul 2021 16:48:57 -0700 Message-Id: <20210706234932.356913-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.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: Peter Maydell , Max Filippov , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Allocate a page to hold the signal trampoline(s). Invoke a guest-specific hook to fill in the contents of the page before marking it read-execute again. Reviewed-by: Max Filippov Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/qemu.h | 7 +++++++ linux-user/elfload.c | 17 +++++++++++++++++ linux-user/signal.c | 3 +++ 3 files changed, 27 insertions(+) -- 2.25.1 diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 3b0b6b75fe..9e5e2aa499 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -437,6 +437,13 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, int do_sigprocmask(int how, const sigset_t *set, sigset_t *oldset); abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx, abi_ulong unew_ctx, abi_long ctx_size); + +/* Fallback addresses into sigtramp page. */ +extern abi_ulong default_sigreturn; +extern abi_ulong default_rt_sigreturn; + +void setup_sigtramp(abi_ulong tramp_page); + /** * block_signals: block all signals while handling this guest syscall * diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 598ab8aa13..9bec6613a2 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -14,6 +14,7 @@ #include "qemu/units.h" #include "qemu/selfmap.h" #include "qapi/error.h" +#include "target_signal.h" #ifdef _ARCH_PPC64 #undef ARCH_DLINFO @@ -25,6 +26,10 @@ #undef ELF_ARCH #endif +#ifndef TARGET_ARCH_HAS_SIGTRAMP_PAGE +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0 +#endif + #define ELF_OSABI ELFOSABI_SYSV /* from personality.h */ @@ -3233,6 +3238,18 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) #endif } + /* + * TODO: load a vdso, which would also contain the signal trampolines. + * Otherwise, allocate a private page to hold them. + */ + if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { + abi_ulong tramp_page = target_mmap(0, TARGET_PAGE_SIZE, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + setup_sigtramp(tramp_page); + target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC); + } + bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &elf_ex, info, (elf_interpreter ? &interp_info : NULL)); info->start_stack = bprm->p; diff --git a/linux-user/signal.c b/linux-user/signal.c index a8faea6f09..099374d456 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -30,6 +30,9 @@ static struct target_sigaction sigact_table[TARGET_NSIG]; static void host_signal_handler(int host_signum, siginfo_t *info, void *puc); +/* Fallback addresses into sigtramp page. */ +abi_ulong default_sigreturn; +abi_ulong default_rt_sigreturn; /* * System includes define _NSIG as SIGRTMAX + 1, From patchwork Tue Jul 6 23:48:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470493 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5544386ejx; Tue, 6 Jul 2021 16:49:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPmdOLdrWWgeL2oZrUvyGTq/YO96DT21/rAmrhprdGbwmsi8c+cGTSoJr+GMN+w1PhmVlN X-Received: by 2002:a02:9718:: with SMTP id x24mr19573560jai.7.1625615398504; Tue, 06 Jul 2021 16:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615398; cv=none; d=google.com; s=arc-20160816; b=KVgPkAGXzi62zKunahhtroIsKMt//PGe+iDxdYGRH41spxSeo8bY4u2cjctHtxkw9l r2Tp1GESBFPKhu4JxowDkwfTNegYiRUP7hlYjqVXO/LZMvZ+VG2OIDPEBzgqcXZQJ5zY S3eTCIZOLywgFQU6ByPYjrHe/1uGUZolYt0ijNAo4RhRW4yDZpcuQdLdyGwcff1RqUQF WkIYZISyb8MqiygfYghpcmz4wXN6++JxjV98JJkc9CMDSzXlGAyD40q71ccWHywijh6y jaWqseT0vvx6kBPaUlOFzdDeg/ZtHzcyLwRrEds59nqcC59zROphYmNRu6Kmi6d9Fmkn SZJQ== 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=X7mIiYUnLQpG7lF7E8+dxMfsx1Pwi8mqFmSQ1+Sw9cU=; b=XCmEK4n+vJr9R9W9dP1A0GOOd05XTGbKupcGc9KvUgFyhet9bi3PoROO2e7yZW7WBJ 04k3oeNnyrVsqwQeCxLUOyT88QMI/QaURZ1XBlTwiFXcx3t881BvDQK9tnw1AZQ4Va01 YWzia6qygz5fhvs4L1V+lBQ7fuiV3yXXd/qPe9t22/i97MxCfCGF3Lmxk7oDVtM/egRm 2763GP6aP75hTiRh8hqiZh6BLVHBoLWrzeBpxBXNGBq2taxp5WgGw/6LDBi4GcbGC1Pa 1UkiE4xaBslgWAStxzeKLXgWiNmdBlz1dAo1hXUbLvMDqSjWznw1vhUlKz60+R9pBQKz y6OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NSFKxcm1; 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 t16si17781351iom.8.2021.07.06.16.49.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:49:58 -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=NSFKxcm1; 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]:35850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0upB-0000om-TN for patch@linaro.org; Tue, 06 Jul 2021 19:49:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uot-0000jB-VW for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:39 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:44932) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uop-0006ay-Sn for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:39 -0400 Received: by mail-pg1-x536.google.com with SMTP id u14so381956pga.11 for ; Tue, 06 Jul 2021 16:49:35 -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=X7mIiYUnLQpG7lF7E8+dxMfsx1Pwi8mqFmSQ1+Sw9cU=; b=NSFKxcm16tB+WPC6uFupR7M8gdsPqL7G1ukdfyxZC+lXRCDVCWSvfpvwWVT81xMGQa 7q78Fl/zm9yp7gfAckG+j8M1HxVgWVh7wOVOlrOzfxYXjOvxK5BCz4JNF6PhA/0pV1nV VK1ncyYilD8Y2uUq9uRDOKriihna2VqWcz3m7dGII8vddOvq8Jz8bd2jQHxf5PieXl7B 8gNBnorX+OVHXqpyWbZ5oFmhGV2ESFMlqDhpldQJYx+tfhKW8/2mexe+le/H8s9qFaxH WHYlM1mJIWYjhc+/hujbYvKlm0WBYN1TWeHQqUF/vU64F5b8Wt9oDWrAh9cZSzJ3o5Pu E0YQ== 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=X7mIiYUnLQpG7lF7E8+dxMfsx1Pwi8mqFmSQ1+Sw9cU=; b=j02MbAdinsbeQiFsZ7R81mVZUhuWpJ8qeO2prxwbkK7yEICig6eWSyMJr/N3yZGcnA Tue8x7gsur8vdjs+We3fBrQP2oFNtMLsgsgmCuNpWRKpQ4ip0yGB/0F53DhgU0Y7A9T6 o0cGAkXTqah1srXSPb6BX5EBA3IF+fOxf/1PDkGPoIWaKZAE3wgXctCD9JvdqBX1H0lP 6g96vDaMlWY+Ab8p3Gdcafg+f9l4gFDIT/0XH4STpxuvMqSR8HhZ3do0tJiciSMaeEvi JRZuaJYzfFfWvnndTETpSK/EpRkMQjvLrGEfXNpRznvOrwhdNCiVjOR2GYhJ9dCdIsgv Hhqw== X-Gm-Message-State: AOAM531UceZPNczmaNNcJ922O1OeTRSUy+GUkxSrjM3Si2O1HuMhgkUD SFHYSRUUZe8XyBfa1gvANLAAPdLnMQ7KuQ== X-Received: by 2002:a63:d90b:: with SMTP id r11mr23272359pgg.81.1625615374633; Tue, 06 Jul 2021 16:49:34 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 02/36] linux-user: Fix style problems in linuxload.c Date: Tue, 6 Jul 2021 16:48:58 -0700 Message-Id: <20210706234932.356913-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.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, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/linuxload.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) -- 2.25.1 diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index a27e1d0d8b..9d4eb5e94b 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -1,59 +1,57 @@ /* Code for loading Linux executables. Mostly linux kernel code. */ #include "qemu/osdep.h" - #include "qemu.h" #define NGROUPS 32 /* ??? This should really be somewhere else. */ -abi_long memcpy_to_target(abi_ulong dest, const void *src, - unsigned long len) +abi_long memcpy_to_target(abi_ulong dest, const void *src, unsigned long len) { void *host_ptr; host_ptr = lock_user(VERIFY_WRITE, dest, len, 0); - if (!host_ptr) + if (!host_ptr) { return -TARGET_EFAULT; + } memcpy(host_ptr, src, len); unlock_user(host_ptr, dest, 1); return 0; } -static int count(char ** vec) +static int count(char **vec) { - int i; + int i; - for(i = 0; *vec; i++) { + for (i = 0; *vec; i++) { vec++; } - - return(i); + return i; } static int prepare_binprm(struct linux_binprm *bprm) { - struct stat st; + struct stat st; int mode; int retval; - if(fstat(bprm->fd, &st) < 0) { - return(-errno); + if (fstat(bprm->fd, &st) < 0) { + return -errno; } mode = st.st_mode; - if(!S_ISREG(mode)) { /* Must be regular file */ - return(-EACCES); + if (!S_ISREG(mode)) { /* Must be regular file */ + return -EACCES; } - if(!(mode & 0111)) { /* Must have at least one execute bit set */ - return(-EACCES); + if (!(mode & 0111)) { /* Must have at least one execute bit set */ + return -EACCES; } bprm->e_uid = geteuid(); bprm->e_gid = getegid(); /* Set-uid? */ - if(mode & S_ISUID) { + if (mode & S_ISUID) { bprm->e_uid = st.st_uid; } @@ -125,8 +123,8 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, } int loader_exec(int fdexec, const char *filename, char **argv, char **envp, - struct target_pt_regs * regs, struct image_info *infop, - struct linux_binprm *bprm) + struct target_pt_regs *regs, struct image_info *infop, + struct linux_binprm *bprm) { int retval; @@ -139,7 +137,7 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, retval = prepare_binprm(bprm); - if(retval>=0) { + if (retval >= 0) { if (bprm->buf[0] == 0x7f && bprm->buf[1] == 'E' && bprm->buf[2] == 'L' @@ -157,11 +155,11 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, } } - if(retval>=0) { + if (retval >= 0) { /* success. Initialize important registers */ do_init_thread(regs, infop); return retval; } - return(retval); + return retval; } From patchwork Tue Jul 6 23:48:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470596 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5548438ejx; Tue, 6 Jul 2021 16:57:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxetwR0h2ozZOqF+ZsXq5aBagllcODYZCCw92JxVQMrA3qPzcn1vhXALVewXYam041pX2xF X-Received: by 2002:ac8:4258:: with SMTP id r24mr1072471qtm.11.1625615857384; Tue, 06 Jul 2021 16:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615857; cv=none; d=google.com; s=arc-20160816; b=0HiYqK1KC7zW7aWDWA2iQMTdi4TDKkHEmmIAED9TD4NdWH42tWtkwv6jRGtqhaDBht 86lnp22zI9HvGCE89ZokecfSCTmQZ5qdrb3GDK2gjJQ1JcfA2WfwzGzBnPcFR+CTwWO8 YolwPaW8LidC2bZcg+MtAZ8QCc6xF2KIKDKt+uckWbzWm5Mn37efpVz/IrQmAfZfCrCI 9K12Ee9IH/N5Ar2isTDnCwI5WAm0ZKoKZfw+d9KX6BIOwA6kXQmoXPOmlrh0vqQYoZoF LdwqZCbnUeiSYKQFFwEMm82FutDhNWuVlOgP32UsB+Ju2FtIlrX+Ej5+46H5fnjmerJZ qEvw== 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=+OXX5KjIYz/ZS9gLgWEfQeUt72TgJXhxPXE04khIgeU=; b=sI1gb2RZ4LF5vZHmG5bQUBKdhL05N+vy/QQy5NL+Fw9Q+F40GXZB+0lHBwlaGn1GWf 6Pgsx8LkLmBTPKgCUaPuclsyH/oNdx/vnY951Hs+vLll2f5cOFXVXOIy3i88I5ZDLhym SoLG5+u52daBqeoXIh70FLWEMlmT+opTvwn2zWEyEl1CPvJaFyN/pRKdkWoGeYRxux1N oGQB1HjLzjsfCi9d3e7IK2Sh2VavczVE0n550Fvn4Em33RvznstGvsJH2sjdSSgQC5K+ tknAcxrBVl0dD967FLABrcbeaXLeR54nViZBhmmxTQTGlXiI3hw5djUtgiGW5Kk/gkES bfhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=YEhACm19; 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 o15si10242304qtv.261.2021.07.06.16.57.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:57:37 -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=YEhACm19; 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]:33168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uwa-0000fN-L1 for patch@linaro.org; Tue, 06 Jul 2021 19:57:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uou-0000lW-Pc for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:40 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:37715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uoq-0006b5-IG for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:40 -0400 Received: by mail-pg1-x52f.google.com with SMTP id t9so411063pgn.4 for ; Tue, 06 Jul 2021 16:49:36 -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=+OXX5KjIYz/ZS9gLgWEfQeUt72TgJXhxPXE04khIgeU=; b=YEhACm19xCJeHS8mYi60ZnutuviMKuddF9tGq7NpARJetL0j+iIbFDKxcxRL49NfnW YGEVe0ObyBlvpeAKRjNGQ19wm02CFo8sfFJ0BDCi2KvXZZ0u8qp5g81xA18V8F3WKvOO I7Z+j6y3rxdiBihUu4q84Oye3wYm4UEgwRpRdnnwfmqIt+8q+Tfub+xRAIQDnTSV8HW1 1fF45x0Km+bEeFG3nULFe8nR15PgWqiX81IXGVliq4Wf82fZ93KK/bpIaKqgyG+ogb3X I5vD0EI6J90BvY7ZxB76WjNWvTAtr10kgQDn8HsD7qmsetMGXGalHckAYybQZMc7gckc KU1w== 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=+OXX5KjIYz/ZS9gLgWEfQeUt72TgJXhxPXE04khIgeU=; b=XmXISCASqOCxLR4A8C2X2hNnoNM0hL1YoBSkKJyEyITIJZYtzewGPYP4XtPCL0/NDc kCPClFpNUTVzKBnzyIEHEbc+8eB+m3wqZVh1mriLWQp7Ffu4G1cdLNuPulbu8MnLk6F9 Wi9kCi4sGeZw8bSx4i1huRoNqNCfO0OKFBfMZu5tIstpNDp75/IfxB2oiffbZEWABcBE M+oPJF9plyMtwTWtKO59pBKj+RHeBSgF3ekqw7IGAJVehF/9GOFmeaoDV0kiMpSTz+WE xSifhs5a1SY04TMEQl4y1AjFqmSEatYEaRgYUgGwz1BO4ENARhbSl9LXGINOfS3klYGX rRkw== X-Gm-Message-State: AOAM532nlHHf5YITF6Z7UrAYmTaZUOeBRj8t5DX5mnoKcQ6Uoeqj/OAc 2tIX3h2TjLFMKa+fS+BJoIoS+Rp5BugPZw== X-Received: by 2002:a63:1c20:: with SMTP id c32mr23124348pgc.41.1625615375305; Tue, 06 Jul 2021 16:49:35 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 03/36] linux-user: Introduce imgsrc_read, imgsrc_read_alloc Date: Tue, 6 Jul 2021 16:48:59 -0700 Message-Id: <20210706234932.356913-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.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" Introduced and initialized, but not yet really used. These will tidy the current tests vs BPRM_BUF_SIZE. Signed-off-by: Richard Henderson --- linux-user/qemu.h | 50 ++++++++++++++++++++++++++++++++++-------- linux-user/linuxload.c | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 9 deletions(-) -- 2.25.1 diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 9e5e2aa499..f4cdfb16b3 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -168,6 +168,37 @@ extern unsigned long mmap_min_addr; /* ??? See if we can avoid exposing so much of the loader internals. */ +typedef struct { + const void *cache; + unsigned int cache_size; + int fd; +} ImageSource; + +/** + * imgsrc_read: Read from ImageSource + * @dst: destination for read + * @offset: offset within file for read + * @len: size of the read + * @img: ImageSource to read from + * @errp: Error details. + * + * Read into @dst, using the cache when possible. + */ +bool imgsrc_read(void *dst, off_t offset, size_t len, + const ImageSource *img, Error **errp); + +/** + * imgsrc_read_alloc: Read from ImageSource + * @offset: offset within file for read + * @size: size of the read + * @img: ImageSource to read from + * @errp: Error details. + * + * Read into newly allocated memory, using the cache when possible. + */ +void *imgsrc_read_alloc(off_t offset, size_t len, + const ImageSource *img, Error **errp); + /* Read a good amount of data initially, to hopefully get all the program headers loaded. */ #define BPRM_BUF_SIZE 1024 @@ -177,15 +208,16 @@ extern unsigned long mmap_min_addr; * used when loading binaries. */ struct linux_binprm { - char buf[BPRM_BUF_SIZE] __attribute__((aligned)); - abi_ulong p; - int fd; - int e_uid, e_gid; - int argc, envc; - char **argv; - char **envp; - char * filename; /* Name of binary */ - int (*core_dump)(int, const CPUArchState *); /* coredump routine */ + char buf[BPRM_BUF_SIZE] __attribute__((aligned)); + ImageSource src; + abi_ulong p; + int fd; + int e_uid, e_gid; + int argc, envc; + char **argv; + char **envp; + char *filename; /* Name of binary */ + int (*core_dump)(int, const CPUArchState *); /* coredump routine */ }; typedef struct IOCTLEntry IOCTLEntry; diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 9d4eb5e94b..3b0bafc490 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -2,6 +2,7 @@ #include "qemu/osdep.h" #include "qemu.h" +#include "qapi/error.h" #define NGROUPS 32 @@ -74,6 +75,10 @@ static int prepare_binprm(struct linux_binprm *bprm) /* Make sure the rest of the loader won't read garbage. */ memset(bprm->buf + retval, 0, BPRM_BUF_SIZE - retval); } + + bprm->src.cache = bprm->buf; + bprm->src.cache_size = retval; + return retval; } @@ -129,6 +134,7 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, int retval; bprm->fd = fdexec; + bprm->src.fd = fdexec; bprm->filename = (char *)filename; bprm->argc = count(argv); bprm->argv = argv; @@ -163,3 +169,43 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, return retval; } + +bool imgsrc_read(void *dst, off_t offset, size_t len, + const ImageSource *img, Error **errp) +{ + ssize_t ret; + + if (offset + len <= img->cache_size) { + memcpy(dst, img->cache + offset, len); + return true; + } + + if (img->fd < 0) { + error_setg(errp, "read past end of buffer"); + return false; + } + + ret = pread(img->fd, dst, len, offset); + if (ret == len) { + return true; + } + if (ret < 0) { + error_setg_errno(errp, errno, "Error reading file header"); + } else { + error_setg(errp, "Incomplete read of file header"); + } + return false; +} + +void *imgsrc_read_alloc(off_t offset, size_t len, + const ImageSource *img, Error **errp) +{ + void *alloc = g_malloc(len); + bool ok = imgsrc_read(alloc, offset, len, img, errp); + + if (!ok) { + g_free(alloc); + alloc = NULL; + } + return alloc; +} From patchwork Tue Jul 6 23:49:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470568 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5546277ejx; Tue, 6 Jul 2021 16:53:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8+kSsd89CqBD7LRpkbGVtNtXzIp8j58kZ7T8sDUTkJmhlIARNruK8X5eT+lO9mBuSL/MH X-Received: by 2002:ac8:5806:: with SMTP id g6mr19633781qtg.112.1625615601626; Tue, 06 Jul 2021 16:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615601; cv=none; d=google.com; s=arc-20160816; b=c3ZnK51HdQQqeLn++i8AoJt+jpkcfMz+Y6VyMkDI7grM0lccfhP8JohaA9VcqD29CE wZRtgi7wJKBuS9R1/UqlJrsc5EMwTQap9ObemQX+TM+gluHDU1B3iKvIpprndB/PQhgp gnEPzw8Or+afy2QRBYUGHOM7yJFIN+mkhc8Qk8V8LJHcNcMjY66A6Wq6Bzi3Q+a7MQ+v Py2mYxeVQKArBOTUkjbK6BQu64uBizP+vWgk4FMn8oWVFzQRACNUeF7RCQZoVZKIcjmJ Z114yHUzLsFO5ADAU8JSYKTmUNfQ587ov1o3v0775CF++WUzvvZMCydIUUFcqkrLd3+l NSIA== 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=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=wioVJQ/qJN1JlStivyXRtbsJrj3TcKHRu6e6gkEsf2amZdUt4ChEuAzqh9JO23J1Pq 7BG142JMSE5AhnI7BCrgG72K5PeG4Tlj41hb9BKRfu8JHAqA7A8iZ7FI8IgYRqWYprte KKl0bMTAbN6VL+xKo1V68zl7dZVTlStwOvb8FVK/279+aHXpiUxgO44iJs7MFKct3qj5 EO2FpqGzLKCGZxleMWkv3gi5rZntVwngx7/OkgSIJFdc3h7W3OMYxgN5+OMBhKa9IK3w /gSNMfq2441ZkmmmFaesqJJujn2CryxQl7XB6/PskjaiohU4KHdKBwDqsBnO1poxYdOC 5Wxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WpSFoxlf; 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 p23si7353386qtn.52.2021.07.06.16.53.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:53:21 -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=WpSFoxlf; 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]:44406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0usS-0006TP-UM for patch@linaro.org; Tue, 06 Jul 2021 19:53:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uot-0000iK-5F for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:39 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:39927) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uor-0006b9-DT for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:38 -0400 Received: by mail-pg1-x52e.google.com with SMTP id a2so402734pgi.6 for ; Tue, 06 Jul 2021 16:49:37 -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=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=WpSFoxlfzzIrc6qgT2OGQuRqAfSdzz4uAIuOgSIFmrguCwTGC+5rTefv5ailwYid2e OnW0G0HvJJ3+cbewcNf9P1+uAE/K6Kv7aOgEsOqROShxIMghCZyKdo103D9izV/bFSZz 6aYZ5NHDmNUd3TZLZ5qJ2MkQt0SjQe33g5dtF7uIrSWTCwiGWCOrp1YUuXI5QCnsl8D5 gtpPGB1v1S6u82HEW85+aALz7r34ACUJ5RkA2HbJqwWNbseNsiHQ7x8JSgcvuQfe83k+ feVbf5/N0FlJg4CcdYJ9mjKYGu4MNJn+WGqm+44APrq/eiTgA0J4emzY5aGrxNWLKyaC MQ8g== 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=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=cDm2A1qCT2fFfjp+Fuq3+AvTcCqUS3c/9Sd37WSBsp66rKau5LDSSK4Z7zrQ+t0arf AAQVgjvjcJ2zVOH5vyUk8jX05/Fmas0auKditPXf74/s/Dy71mbnrCv4AOUDSImxul9r jYzHBqMoWzOss9Quc7TGHcGoKdLsTQyUUGVchSOSreiH+fBMkGhKpi62LMg7Ucg5OJAZ s+XYJdl2jLODTTA+qUcMphlosY5O6ryev/1Yxrmo+apzXAn/dpsirtw+DrM8PkNz1yH4 0ojn+U4yDi9QmAIIoP55IChQxhCwOJGVVzousEiyqAiFJXOIVabWThTxS+LZQjYFsVvu gIBw== X-Gm-Message-State: AOAM533xqRsLZeFqyPrNS6doF1/e3XGvtc0BJDzmBmqXlN61uq43jc9R dkHFlnBnm9/Zo00BnwWuNiFVREgfNwjQUw== X-Received: by 2002:a63:d612:: with SMTP id q18mr23365770pgg.77.1625615375948; Tue, 06 Jul 2021 16:49:35 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/36] linux-user: Tidy loader_exec Date: Tue, 6 Jul 2021 16:49:00 -0700 Message-Id: <20210706234932.356913-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.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" Reorg the if cases to reduce indentation. Test for 4 bytes in the file before checking the signatures. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/linuxload.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) -- 2.25.1 diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 3b0bafc490..8b93b9704c 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -143,31 +143,31 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, retval = prepare_binprm(bprm); - if (retval >= 0) { - if (bprm->buf[0] == 0x7f - && bprm->buf[1] == 'E' - && bprm->buf[2] == 'L' - && bprm->buf[3] == 'F') { - retval = load_elf_binary(bprm, infop); -#if defined(TARGET_HAS_BFLT) - } else if (bprm->buf[0] == 'b' - && bprm->buf[1] == 'F' - && bprm->buf[2] == 'L' - && bprm->buf[3] == 'T') { - retval = load_flt_binary(bprm, infop); -#endif - } else { - return -ENOEXEC; - } + if (retval < 4) { + return -ENOEXEC; } - - if (retval >= 0) { - /* success. Initialize important registers */ - do_init_thread(regs, infop); + if (bprm->buf[0] == 0x7f + && bprm->buf[1] == 'E' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'F') { + retval = load_elf_binary(bprm, infop); +#if defined(TARGET_HAS_BFLT) + } else if (bprm->buf[0] == 'b' + && bprm->buf[1] == 'F' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'T') { + retval = load_flt_binary(bprm, infop); +#endif + } else { + return -ENOEXEC; + } + if (retval < 0) { return retval; } - return retval; + /* Success. Initialize important registers. */ + do_init_thread(regs, infop); + return 0; } bool imgsrc_read(void *dst, off_t offset, size_t len, From patchwork Tue Jul 6 23:49:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470589 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5547151ejx; Tue, 6 Jul 2021 16:55:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBi9tfwzprnjmgZgffnS+kt2Y1BMxSGOIWVko9mgdUMczF9RZhZp/cpAsuN5ER8Cf6CHVe X-Received: by 2002:ac8:4241:: with SMTP id r1mr19744412qtm.121.1625615714433; Tue, 06 Jul 2021 16:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615714; cv=none; d=google.com; s=arc-20160816; b=buC2YkGDqaSVae/PuYD+e3fyoGwTLUYyX/S84ExbcV04ETi2mO8s5VPZc5/0z1OopZ 70/rgZCUC5GKnXLKSDzka5lTMv4k1vEco+MmUtaIN8W0pf1gCOtE3q+JlTBhMZxZgrSa /0APfHyvItaQVXAa2wGQuZKw4Pcou10UEHoiC6MUNlBiZpCzvvi3eJdu/2RcgVMGMJm9 UTKzVGf8pq3UIEy1aoNaynTVC845mhLUrwPz+wchVRHOMtnWrNlqdr8t6FoPEeXf+iN/ 9bQn/6MfpQq4eNLdfmX84srlxF7hNT1qvPyJpM7kgnB7FXC7Mstac2boyJHy7ZXCno71 Va4w== 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=esOfXUyRVMGOg67ITfNoE/UDJ8GPb3XxBVP+gF1D6+o=; b=IQrEezupSGWUSGuaBsfJPK5zGHhV7nB7hjmywyy/v0cQWf+7h2FW6+SmnjGEXscn4P jPMcQ4LEenMU7YiHuh6t/UHbChsN+M1DMm5AEJYFBU4bl9I9wlObzIMEzwGCKBpCIPmx q94vDg4Tdzly3mVa357pyy7hsAfMFNvcj6VQObgY7FwI90TKvWyCpNIXNh8TEmA8DAst Mn9PoJROA4dJtQrIhtvdzlx9cemcHrywPXwQluPd2xQ4ZB5Xj9GiGBRfjVaqKYqkxmMH cUluKN91NwJV6TQRiGHuH82von67kQdcTRu+17rFFrxhnPRJx8FUXzaZr949KfAT7hm/ p/8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VVf2Pq8B; 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 x29si13107533qtm.307.2021.07.06.16.55.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:55:14 -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=VVf2Pq8B; 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]:52934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uuH-0003ah-J6 for patch@linaro.org; Tue, 06 Jul 2021 19:55:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uou-0000k4-AL for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:40 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:41510) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uos-0006bQ-2w for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:40 -0400 Received: by mail-pf1-x42d.google.com with SMTP id f17so525544pfj.8 for ; Tue, 06 Jul 2021 16:49:37 -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=esOfXUyRVMGOg67ITfNoE/UDJ8GPb3XxBVP+gF1D6+o=; b=VVf2Pq8BmS8ZvyhYQmyNzP99jtiF+PmLeKqh7SS5g3MRhxUiuTh7IdFQNCPiFCN7iS RWD9kc3dzuo2QKcL3IM6VfT6+3cww1YSKqj/zQrMRrQG7hbr3cVJx7fPx0e3Swa1zm2V H93GKOaTswHPbJ4CytIJXw87gnt3YOtJ5Ha0t0IC2uBDRTgUPb+G8ESnfV8JU0i8xf38 wvNgreUl3UOOacRKpeVjnzKN0pMX4/C4m+mVXMcsRPOYUtWU4NAKU5McL5G6Zla+87se qQbzhAYEykSCitjUi6Hz38VgZvfyq0HJicC9fc+1xRPGJcd/DnWtPyJBjosgx/0z3zl3 qxNQ== 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=esOfXUyRVMGOg67ITfNoE/UDJ8GPb3XxBVP+gF1D6+o=; b=bPU0Yi38QDpMxzAmmp7BYNhyV7fjZ3I2ZzOAdhhTi9s/YsI27LZpVBGYxjRXl+tcK+ /Z0AcXtqjLIwQLmmSPqxvQ92ae/KzpXywGdzIzF0DxPVh2EXaj4OqqqDvjBzOXtSmRL1 etjAUM72F7gVDiUpKqAC0WYaY89mQVcZmPzJlBFT1ELpCSYJOfhdeT6PTCbJQpj6tPML gqfR8mUGMt2Jav2YJzX0Z6Forb9L8F5KMli7FB3ff0baPB0YJ3SlzpM08b7Dflczbgb7 QIpG5UtFRQ/K7yNRxpucty5SBRd0tz3DKl6HGqGmpNvJyf1N7rqqsaljcc5Xot0utMPY BzXg== X-Gm-Message-State: AOAM530jlyet+joM37PiyLa1vjCvLsaQbMQ9jLdzU6BsDIEEqFSl3WQf nqRVzAYwnXbwMnMdxBJmXhPdVghkynRz+Q== X-Received: by 2002:a63:7d8:: with SMTP id 207mr20633541pgh.267.1625615376626; Tue, 06 Jul 2021 16:49:36 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 05/36] linux-user: Do not clobber bprm_buf swapping ehdr Date: Tue, 6 Jul 2021 16:49:01 -0700 Message-Id: <20210706234932.356913-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rearrange the allocation of storage for ehdr between load_elf_image and load_elf_binary. The same set of copies are done, but we don't modify bprm_buf, which will be important later. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 9bec6613a2..d1278c2d29 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2627,16 +2627,17 @@ static bool parse_elf_properties(int image_fd, On return: INFO values will be filled in, as necessary or available. */ static void load_elf_image(const char *image_name, int image_fd, - struct image_info *info, char **pinterp_name, + struct image_info *info, struct elfhdr *ehdr, + char **pinterp_name, char bprm_buf[BPRM_BUF_SIZE]) { - struct elfhdr *ehdr = (struct elfhdr *)bprm_buf; struct elf_phdr *phdr; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; int i, retval, prot_exec; Error *err = NULL; /* First of all, some simple consistency checks */ + memcpy(ehdr, bprm_buf, sizeof(*ehdr)); if (!elf_check_ident(ehdr)) { error_setg(&err, "Invalid ELF image for this architecture"); goto exit_errmsg; @@ -2949,6 +2950,7 @@ static void load_elf_image(const char *image_name, int image_fd, static void load_elf_interp(const char *filename, struct image_info *info, char bprm_buf[BPRM_BUF_SIZE]) { + struct elfhdr ehdr; int fd, retval; Error *err = NULL; @@ -2970,7 +2972,7 @@ static void load_elf_interp(const char *filename, struct image_info *info, memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); } - load_elf_image(filename, fd, info, NULL, bprm_buf); + load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf); } static int symfind(const void *s0, const void *s1) @@ -3162,8 +3164,14 @@ uint32_t get_elf_eflags(int fd) int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) { + /* + * We need a copy of the elf header for passing to create_elf_tables. + * We will have overwritten the original when we re-use bprm->buf + * while loading the interpreter. Allocate the storage for this now + * and let elf_load_image do any swapping that may be required. + */ + struct elfhdr ehdr; struct image_info interp_info; - struct elfhdr elf_ex; char *elf_interpreter = NULL; char *scratch; @@ -3175,12 +3183,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) info->start_mmap = (abi_ulong)ELF_START_MMAP; load_elf_image(bprm->filename, bprm->fd, info, - &elf_interpreter, bprm->buf); - - /* ??? We need a copy of the elf header for passing to create_elf_tables. - If we do nothing, we'll have overwritten this when we re-use bprm->buf - when we load the interpreter. */ - elf_ex = *(struct elfhdr *)bprm->buf; + &ehdr, &elf_interpreter, bprm->buf); /* Do this so that we can load the interpreter, if need be. We will change some of these later */ @@ -3250,7 +3253,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC); } - bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &elf_ex, + bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, info, (elf_interpreter ? &interp_info : NULL)); info->start_stack = bprm->p; From patchwork Tue Jul 6 23:49:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470580 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5546905ejx; Tue, 6 Jul 2021 16:54:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0OFS5DZSrstkDHf+6/QW5maKwxEbMLGAkw+T/lmhc9FQoy0Js71iXgDRcJPD6+rfRbnB5 X-Received: by 2002:a05:622a:48a:: with SMTP id p10mr4573990qtx.385.1625615686527; Tue, 06 Jul 2021 16:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615686; cv=none; d=google.com; s=arc-20160816; b=KdrzU429lOoN2RtW3Ah27gMuUaw9Q5Uf0Tr6ml8pTR7/nqy0gOhtm7ftDowOf40cz7 uuUY3DhUOeeJ6RlfqkXbEDOXY5bwvWcz13mfXLAN1kHlp75Sl1LT50OttRYhSNDWvCc2 VKRZLHHETF3tqSaCKLBMNZlMBDVZQ3XSicdQ5SWoXymgn0SeFRUfCJWQMHDyn1TM/oIx dbLUT6syquGcDwU7/pNcj4nrkFogWNrDXpUvPMrtAGnxZYRXDNWCSWaKgncRpFbUvSEd Bhew5bNrFbgFPNGlWjDzTDH3uBADz33RoroVwfVPx/0DtwCC7veRUE+q+eqHsFMn7F/d WTxA== 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=VISwacrGgGbOWnBpiQJcNPBiBKqXw/P+V8RdFMkfOQg=; b=lyCjLFE4iKPRk4atnO4KL6OkxsRBFrCYGlpNcjIg0T4XCQIuQhBlklHw7wH+NM+RI1 pEbMvY9vgIuYhQ1sMI340ya8aCIiEwsHzESC21Ssk81s9xacAeZMaeyG3hl5LWNGojTO PCvfiTRkULX5PG+5Es4exgfN5DctGcr/+qcCNQoRWmc2Hj1iOMye3pkpkUmLiF14UnQx 338pWWQFsMyfyWibntEJZYU5wde2pgs1H3sDhyFuLBS/eHVpKkskWchY+e8hndnD4DUq LiR6W+Y3Uki/61Jxk1dmd/xcNcGa8ACVbTynlYEwZoWfhSYMdv3RxoTYfB1eXfK7wDgs 3oRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Rt26Tpjg; 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 e9si12300055qki.171.2021.07.06.16.54.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:54:46 -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=Rt26Tpjg; 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]:53102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0utp-0003hL-RF for patch@linaro.org; Tue, 06 Jul 2021 19:54:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uow-0000qJ-Cb for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:42 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:37759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uos-0006bV-LF for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:42 -0400 Received: by mail-pf1-x436.google.com with SMTP id 17so547112pfz.4 for ; Tue, 06 Jul 2021 16:49:38 -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=VISwacrGgGbOWnBpiQJcNPBiBKqXw/P+V8RdFMkfOQg=; b=Rt26TpjgEzcf6YNhaAjOb3NqFq7WoADgLBCxA6qj97rRaw1pakmpDtUcFofdqb6u30 Wp9XBeYbwfKnxcQ55NPZ+DNSxOC4P+SOjY+WLVHMeAconTf7+XqQv2jQkjii3Ur9oSEg Y7D5e+RbrcpOpUuGqh8bxaSsukJfdjFSoceslNkz0bU3MW476oqAM0qa5LuSNz2UA+0w Dfd/nVOi/CpIT/EZ/5GZALezH+ERBt/tGfXrs/iGRYt4y52dTn13XGZ1X+nvDzyA0GAc X30EPjv62ZJpgi8QSCx8K6gNSq+4rfzYTUz9/IE0Byhpe6Oy0tgzabd3VdyCh+mPNupE fUmA== 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=VISwacrGgGbOWnBpiQJcNPBiBKqXw/P+V8RdFMkfOQg=; b=SPZwqgcByK3YEhv22UMy3AXV2p3CbyjOLQ2dQ8diOif4/A1MYUWHG2gzaWUhY63qr5 6U853cbuFxTkKvYA4VtX2OnQRxZ/qWHvF7Lq0/7Jj2NYgt8cXQZYmi8yxXTdx8DArgFq HmQVo21qFQ/+pYZXXSOjsF0cVPG+PHQu0mATN9iLkbLX7W+7M3MaguaUKTVwhSVXrQiv bLCBUtwqcKpgajQgEIilKYLNnO+WiJvegIB0jXikI+ZA1zJaQ7hTCh5ZiAFmLqyS11ez Ry4ZifmLso43OKRj1Xvnm03gOFnXQdQoj52VrGuUwc6OzmMM09SqOneF3q6bUrI9FNd+ XHSg== X-Gm-Message-State: AOAM533KLnxHDRTi96DlyzwBGFkeArWQr5U8agE6Myg0fe8FZrySfvjB MBKNkKGMUIb2uvNI3RAgZnyojhNSTaSPBA== X-Received: by 2002:a62:7e42:0:b029:325:6b42:609f with SMTP id z63-20020a627e420000b02903256b42609fmr1104719pfc.37.1625615377383; Tue, 06 Jul 2021 16:49:37 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 06/36] linux-user: Use ImageSource in load_elf_image Date: Tue, 6 Jul 2021 16:49:02 -0700 Message-Id: <20210706234932.356913-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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" Change parse_elf_properties as well, as the bprm_buf argument ties the two functions closely. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 124 ++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 77 deletions(-) -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d1278c2d29..9113bf82f1 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2530,10 +2530,9 @@ static bool parse_elf_property(const uint32_t *data, int *off, int datasz, } /* Process NT_GNU_PROPERTY_TYPE_0. */ -static bool parse_elf_properties(int image_fd, +static bool parse_elf_properties(const ImageSource *src, struct image_info *info, const struct elf_phdr *phdr, - char bprm_buf[BPRM_BUF_SIZE], Error **errp) { union { @@ -2561,14 +2560,8 @@ static bool parse_elf_properties(int image_fd, return false; } - if (phdr->p_offset + n <= BPRM_BUF_SIZE) { - memcpy(¬e, bprm_buf + phdr->p_offset, n); - } else { - ssize_t len = pread(image_fd, ¬e, n, phdr->p_offset); - if (len != n) { - error_setg_errno(errp, errno, "Error reading file header"); - return false; - } + if (!imgsrc_read(¬e, phdr->p_offset, n, src, errp)) { + return false; } /* @@ -2614,30 +2607,34 @@ static bool parse_elf_properties(int image_fd, } } -/* Load an ELF image into the address space. +/** + * load_elf_image: Load an ELF image into the address space. + * @image_name: the filename of the image, to use in error messages. + * @src: the ImageSource from which to read. + * @info: info collected from the loaded image. + * @ehdr: the ELF header, not yet bswapped. + * @pinterp_name: record any PT_INTERP string found. + * + * On return: @info values will be filled in, as necessary or available. + */ - IMAGE_NAME is the filename of the image, to use in error messages. - IMAGE_FD is the open file descriptor for the image. - - BPRM_BUF is a copy of the beginning of the file; this of course - contains the elf file header at offset 0. It is assumed that this - buffer is sufficiently aligned to present no problems to the host - in accessing data at aligned offsets within the buffer. - - On return: INFO values will be filled in, as necessary or available. */ - -static void load_elf_image(const char *image_name, int image_fd, +static void load_elf_image(const char *image_name, const ImageSource *src, struct image_info *info, struct elfhdr *ehdr, - char **pinterp_name, - char bprm_buf[BPRM_BUF_SIZE]) + char **pinterp_name) { - struct elf_phdr *phdr; + g_autofree struct elf_phdr *phdr = NULL; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; - int i, retval, prot_exec; + int i, prot_exec; Error *err = NULL; - /* First of all, some simple consistency checks */ - memcpy(ehdr, bprm_buf, sizeof(*ehdr)); + /* + * First of all, some simple consistency checks. + * Note that we rely on the bswapped ehdr staying in bprm_buf, + * for later use by load_elf_binary and create_elf_tables. + */ + if (!imgsrc_read(ehdr, 0, sizeof(*ehdr), src, &err)) { + goto exit_errmsg; + } if (!elf_check_ident(ehdr)) { error_setg(&err, "Invalid ELF image for this architecture"); goto exit_errmsg; @@ -2648,15 +2645,11 @@ static void load_elf_image(const char *image_name, int image_fd, goto exit_errmsg; } - i = ehdr->e_phnum * sizeof(struct elf_phdr); - if (ehdr->e_phoff + i <= BPRM_BUF_SIZE) { - phdr = (struct elf_phdr *)(bprm_buf + ehdr->e_phoff); - } else { - phdr = (struct elf_phdr *) alloca(i); - retval = pread(image_fd, phdr, i, ehdr->e_phoff); - if (retval != i) { - goto exit_read; - } + phdr = imgsrc_read_alloc(ehdr->e_phoff, + ehdr->e_phnum * sizeof(struct elf_phdr), + src, &err); + if (phdr == NULL) { + goto exit_errmsg; } bswap_phdr(phdr, ehdr->e_phnum); @@ -2692,17 +2685,10 @@ static void load_elf_image(const char *image_name, int image_fd, goto exit_errmsg; } - interp_name = g_malloc(eppnt->p_filesz); - - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { - memcpy(interp_name, bprm_buf + eppnt->p_offset, - eppnt->p_filesz); - } else { - retval = pread(image_fd, interp_name, eppnt->p_filesz, - eppnt->p_offset); - if (retval != eppnt->p_filesz) { - goto exit_read; - } + interp_name = imgsrc_read_alloc(eppnt->p_offset, eppnt->p_filesz, + src, &err); + if (interp_name == NULL) { + goto exit_errmsg; } if (interp_name[eppnt->p_filesz - 1] != 0) { error_setg(&err, "Invalid PT_INTERP entry"); @@ -2710,7 +2696,7 @@ static void load_elf_image(const char *image_name, int image_fd, } *pinterp_name = g_steal_pointer(&interp_name); } else if (eppnt->p_type == PT_GNU_PROPERTY) { - if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) { + if (!parse_elf_properties(src, info, eppnt, &err)) { goto exit_errmsg; } } @@ -2852,7 +2838,7 @@ static void load_elf_image(const char *image_name, int image_fd, vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po); error = target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED, - image_fd, eppnt->p_offset - vaddr_po); + src->fd, eppnt->p_offset - vaddr_po); if (error == -1) { goto exit_mmap; @@ -2898,20 +2884,11 @@ static void load_elf_image(const char *image_name, int image_fd, #ifdef TARGET_MIPS } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; - if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) { - error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry"); + + if (!imgsrc_read(&abiflags, eppnt->p_offset, sizeof(abiflags), + src, &err)) { goto exit_errmsg; } - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { - memcpy(&abiflags, bprm_buf + eppnt->p_offset, - sizeof(Mips_elf_abiflags_v0)); - } else { - retval = pread(image_fd, &abiflags, sizeof(Mips_elf_abiflags_v0), - eppnt->p_offset); - if (retval != sizeof(Mips_elf_abiflags_v0)) { - goto exit_read; - } - } bswap_mips_abiflags(&abiflags); info->fp_abi = abiflags.fp_abi; #endif @@ -2924,21 +2901,14 @@ static void load_elf_image(const char *image_name, int image_fd, } if (qemu_log_enabled()) { - load_symbols(ehdr, image_fd, load_bias); + load_symbols(ehdr, src->fd, load_bias); } mmap_unlock(); - close(image_fd); + close(src->fd); return; - exit_read: - if (retval >= 0) { - error_setg(&err, "Incomplete read of file header"); - } else { - error_setg_errno(&err, errno, "Error reading file header"); - } - goto exit_errmsg; exit_mmap: error_setg_errno(&err, errno, "Error mapping file"); goto exit_errmsg; @@ -2951,6 +2921,7 @@ static void load_elf_interp(const char *filename, struct image_info *info, char bprm_buf[BPRM_BUF_SIZE]) { struct elfhdr ehdr; + ImageSource src; int fd, retval; Error *err = NULL; @@ -2968,11 +2939,11 @@ static void load_elf_interp(const char *filename, struct image_info *info, exit(-1); } - if (retval < BPRM_BUF_SIZE) { - memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); - } + src.fd = fd; + src.cache = bprm_buf; + src.cache_size = retval; - load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf); + load_elf_image(filename, &src, info, &ehdr, NULL); } static int symfind(const void *s0, const void *s1) @@ -3182,8 +3153,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) info->start_mmap = (abi_ulong)ELF_START_MMAP; - load_elf_image(bprm->filename, bprm->fd, info, - &ehdr, &elf_interpreter, bprm->buf); + load_elf_image(bprm->filename, &bprm->src, info, &ehdr, &elf_interpreter); /* Do this so that we can load the interpreter, if need be. We will change some of these later */ From patchwork Tue Jul 6 23:49:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470574 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5546291ejx; Tue, 6 Jul 2021 16:53:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxjUSC2jmjVJifJsakuKZbkX2ubFQ56DqU+tBPE9GU7FA4P/Ce/mkysdSJJ3Ex0MqU0+9D X-Received: by 2002:a92:a005:: with SMTP id e5mr15854792ili.22.1625615602834; Tue, 06 Jul 2021 16:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615602; cv=none; d=google.com; s=arc-20160816; b=rDWXyiQnMg3Bkk97TWyeCyb7AMRQP9UFVhVZ02cus6dyYKBxxv8L+Dzvxlqq1yW40p c0mkSgNRexRmkXbnfn0+C/DL/ZmORFyiOaLMioxS9x/Rm7r9iCvegp4fHre1h5rd85Vm TQVx2wf4XcefLjwxX6oPo9r+1jGdUfZl6lWFiP+BgzqW6rxI5SzK/bbMUClJHiVrwZTd 0B3OUUAKWT4qbirshKo9kJVqPdFxU2ZI9G/UODR+jcsGMYSp/q4GGB6tErleKhZZOi7a Bb5/FwQlEHjy6xhoDjShlGVfzRl0wOIN1fvaxum8ctx7M/BytqfGmkMCEt1KLxQ7HCWD ytuw== 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=9RcoFmxGQXgPRY+jmXRZEPO1LtZWOQX+pDz9H/4119E=; b=rWDY6sB4fMQcRqk3T8bC1t0Duh3SwnGgtFo6v7EmmdT8CizYM3WUBoWEH/FiR42Hlq Zr0EuZUBNcYiUEBbF9jc0YBwYRShM1OV/FsJnWRiaTi5R/v0H/g2sOWcQl+h/A6cQeyA x3GZV6z1gpUR/dXyy6m+IQjW0yuIW8zaamtnWPmhW/HkFIj94Ld6PbEBsZessZVhriFf EOe8u65XaB8Y4xy2vPINS4lOnsTGyCjRv5XYS6B3b0do8kwR67NEDXmgwAi3Gr055W8X OHKh9lcGjFTE1n1+n2qULsdEH7tIWsRP1aojn8yxlYOqk+kTLzN4CPGrDpKKMK6ExART 1/vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R7sZRA70; 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 f3si18340678ilq.115.2021.07.06.16.53.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:53:22 -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=R7sZRA70; 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]:44472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0usU-0006Vi-4I for patch@linaro.org; Tue, 06 Jul 2021 19:53:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uov-0000or-TW for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:41 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:38782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uot-0006bf-AN for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:41 -0400 Received: by mail-pg1-x52c.google.com with SMTP id h4so407826pgp.5 for ; Tue, 06 Jul 2021 16:49:38 -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=9RcoFmxGQXgPRY+jmXRZEPO1LtZWOQX+pDz9H/4119E=; b=R7sZRA70v7H1x5y9EUN8f/2nDivfeG6gN+hH8Jj0y7JHd0hgMKyTUX7SIHS96aIqmI 5umG1S84pOBlYh4ofSX6lGZy9VSh/JiY/K5b81qpSfw73o7nwlM8hhYwdEEFjQuerOYK Zp45NEqds390dVkQ04Q6gvrHcz9HbSjE581Wivi1EJFTf1RckAO7FECgRkpUdu+kZJVh gpFCKZQkPUU5J9Zjb0aQc4EnapRTp4KO6Mp+Rg5+PEvIfNJ1EXNRMFN8Sa6au0Gxpj4T N7Fxb/xhgn8oyj/7dkGshdZgGZ6nhWCGBTfvGP/jzPwdxGKTc28sG9448ogXJJGYBHXn Yzfw== 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=9RcoFmxGQXgPRY+jmXRZEPO1LtZWOQX+pDz9H/4119E=; b=V3aoI2c+qXOMf5B9plLN8limPfmPGDmn5hc+O0MoZOKNmoM+Gk6XFS5mgEd/B/DA/U kTktWfeaTTNnjkaXEiDhKq4IG/y6QBhF+FIbePQfq6IkVMfc7Gxcekq6nFTHquTfIZG8 l94bnYl14b4An+hHYfwVXDfFUSUOIcSULtQvfMeKHNelbfdFLVFSPdjJ4nLAUu8sAWFo 5zF/WQ8DQqN2FwbZ6UOtXgQh0r05UC555gEwfdmzOZvE/RmJbcYWnyOatI8bmQz4aqm1 5UuUZWOX8dzjgHiSLTSVJthZ1FOs+xLFwH9goAOgldNkMjNo/JKlmuJPEorQACW8/Ehk QOkg== X-Gm-Message-State: AOAM533hGYLbXgigENiBTuf6QqGuE9U4BUkqiYHzLBcI7PN1w5cn7CY9 3isNT1NMZReJv3g7iJhGqP5NO3dgBefHWQ== X-Received: by 2002:a63:303:: with SMTP id 3mr22609238pgd.111.1625615377979; Tue, 06 Jul 2021 16:49:37 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 07/36] linux-user: Use ImageSource in load_symbols Date: Tue, 6 Jul 2021 16:49:03 -0700 Message-Id: <20210706234932.356913-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.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" Aside from the section headers, we're unlikely to hit the ImageSource cache on guest executables. But the interface for imgsrc_read_* is better. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 87 ++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 39 deletions(-) -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 9113bf82f1..490b374d13 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1734,7 +1734,8 @@ static inline void bswap_mips_abiflags(Mips_elf_abiflags_v0 *abiflags) { } #ifdef USE_ELF_CORE_DUMP static int elf_core_dump(int, const CPUArchState *); #endif /* USE_ELF_CORE_DUMP */ -static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias); +static void load_symbols(struct elfhdr *hdr, const ImageSource *src, + abi_ulong load_bias); /* Verify the portions of EHDR within E_IDENT for the target. This can be performed before bswapping the entire header. */ @@ -2901,7 +2902,7 @@ static void load_elf_image(const char *image_name, const ImageSource *src, } if (qemu_log_enabled()) { - load_symbols(ehdr, src->fd, load_bias); + load_symbols(ehdr, src, load_bias); } mmap_unlock(); @@ -2989,19 +2990,20 @@ static int symcmp(const void *s0, const void *s1) } /* Best attempt to load symbols from this ELF object. */ -static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) +static void load_symbols(struct elfhdr *hdr, const ImageSource *src, + abi_ulong load_bias) { int i, shnum, nsyms, sym_idx = 0, str_idx = 0; - uint64_t segsz; - struct elf_shdr *shdr; + g_autofree struct elf_shdr *shdr = NULL; char *strings = NULL; - struct syminfo *s = NULL; - struct elf_sym *new_syms, *syms = NULL; + struct elf_sym *syms = NULL; + struct elf_sym *new_syms; + uint64_t segsz; shnum = hdr->e_shnum; - i = shnum * sizeof(struct elf_shdr); - shdr = (struct elf_shdr *)alloca(i); - if (pread(fd, shdr, i, hdr->e_shoff) != i) { + shdr = imgsrc_read_alloc(hdr->e_shoff, shnum * sizeof(struct elf_shdr), + src, NULL); + if (shdr == NULL) { return; } @@ -3019,31 +3021,33 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) found: /* Now know where the strtab and symtab are. Snarf them. */ - s = g_try_new(struct syminfo, 1); - if (!s) { - goto give_up; - } segsz = shdr[str_idx].sh_size; - s->disas_strtab = strings = g_try_malloc(segsz); - if (!strings || - pread(fd, strings, segsz, shdr[str_idx].sh_offset) != segsz) { + strings = g_try_malloc(segsz); + if (!strings) { + goto give_up; + } + if (!imgsrc_read(strings, shdr[str_idx].sh_offset, segsz, src, NULL)) { goto give_up; } segsz = shdr[sym_idx].sh_size; - syms = g_try_malloc(segsz); - if (!syms || pread(fd, syms, segsz, shdr[sym_idx].sh_offset) != segsz) { - goto give_up; - } - if (segsz / sizeof(struct elf_sym) > INT_MAX) { - /* Implausibly large symbol table: give up rather than ploughing - * on with the number of symbols calculation overflowing + /* + * Implausibly large symbol table: give up rather than ploughing + * on with the number of symbols calculation overflowing. */ goto give_up; } nsyms = segsz / sizeof(struct elf_sym); + syms = g_try_malloc(segsz); + if (!syms) { + goto give_up; + } + if (!imgsrc_read(syms, shdr[sym_idx].sh_offset, segsz, src, NULL)) { + goto give_up; + } + for (i = 0; i < nsyms; ) { bswap_sym(syms + i); /* Throw away entries which we do not need. */ @@ -3068,10 +3072,12 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) goto give_up; } - /* Attempt to free the storage associated with the local symbols - that we threw away. Whether or not this has any effect on the - memory allocation depends on the malloc implementation and how - many symbols we managed to discard. */ + /* + * Attempt to free the storage associated with the local symbols + * that we threw away. Whether or not this has any effect on the + * memory allocation depends on the malloc implementation and how + * many symbols we managed to discard. + */ new_syms = g_try_renew(struct elf_sym, syms, nsyms); if (new_syms == NULL) { goto give_up; @@ -3080,20 +3086,23 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) qsort(syms, nsyms, sizeof(*syms), symcmp); - s->disas_num_syms = nsyms; -#if ELF_CLASS == ELFCLASS32 - s->disas_symtab.elf32 = syms; -#else - s->disas_symtab.elf64 = syms; -#endif - s->lookup_symbol = lookup_symbolxx; - s->next = syminfos; - syminfos = s; + { + struct syminfo *s = g_new(struct syminfo, 1); + s->disas_strtab = strings; + s->disas_num_syms = nsyms; +#if ELF_CLASS == ELFCLASS32 + s->disas_symtab.elf32 = syms; +#else + s->disas_symtab.elf64 = syms; +#endif + s->lookup_symbol = lookup_symbolxx; + s->next = syminfos; + syminfos = s; + } return; -give_up: - g_free(s); + give_up: g_free(strings); g_free(syms); } From patchwork Tue Jul 6 23:49:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470607 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5549398ejx; Tue, 6 Jul 2021 16:59:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlYZ/owRmX+v+UUFPAgJiRf0uYyYAt4lgOapSjKFHUUE8bBNfippYDkrswg7/fUcN6aOFm X-Received: by 2002:a0c:fc0d:: with SMTP id z13mr20997242qvo.1.1625615975907; Tue, 06 Jul 2021 16:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615975; cv=none; d=google.com; s=arc-20160816; b=COsDkEu8iCcokbnjwxx6YZ3nxQKlPR0THk2jXenuMo+24/8mEf/15/2BkEYaFXofSk bdxZuWHrLXT/igBHUb7g4PuT5g0cJN9lVJJe2jf8wkEt0VV1l2Uj8YLnIln2KKeOWvCt 4xLhLl7UNT0N0wLhyrPNh7tJJ1AYIe+N2AnrXyCCP13820sf6MNWEVTlnSW4F2811wOu kXWrBcJr20x4jSOGphB96SnuRRUD2CfBLZfoDOApmCarvlQaCpqLV7iBdiS42QMU+67w mYSWOUSqJgRkMEeI61TJI7LGT4p875dlUD+GBA2G7gVFeYpAolXqqu3tWcTrikmk7oTG tO8Q== 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=jaeBKd2588gwtTJA1dNcYNPRKjLEqNsjOOLvdzic+bk=; b=IWx5uzECM8V38zDm76LdssWv6F+5jGcT/9WqOg8xoChZgB81JG1ftfL/s1mr81aZOy kjyo7Nd4ucxytHY3z6foI1d6ZnL7a86lryut7ETgAo/yQwXNWpOw2h8Tja6lrt2BhG7g YCo33pYBhQFIYfaWoTfEqncyTbaUFSx1p8VYRHyRgcPaSYDuUwlhRxmgG0/qOdHeuBv/ 6bbWWSUZ7iN7V9wz32rg6ubqwjZRWA2hiJitnzO0mq3fJJhFMDchIVedRYQ8ibeFsbwE ixJXSwtcC6bq0j5osA/3HJzG4gfpGLmxlP/YUnJiqNe4EKAQTI6MOzbJG5jH8aeVOpg9 l85g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZjuhVCKk; 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 j11si12198218qta.291.2021.07.06.16.59.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:59: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=ZjuhVCKk; 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]:41742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uyV-0006LB-AO for patch@linaro.org; Tue, 06 Jul 2021 19:59:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uox-0000sg-9E for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:43 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:43653) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uou-0006bx-HP for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:43 -0400 Received: by mail-pl1-x62d.google.com with SMTP id i13so46243plb.10 for ; Tue, 06 Jul 2021 16:49:40 -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=jaeBKd2588gwtTJA1dNcYNPRKjLEqNsjOOLvdzic+bk=; b=ZjuhVCKkQfznQsgOgmFV77pmONWIQPaYd813tDpYCQaQg1LgaK3tcI8svsP+SocvEA PQaifbNeDES7uvA4/2lNed65J7kFLqAivYt+39P6N+dpxH35wcJmjEEuZKkZje90CqTS 9uxE5XrrG+wYLl9xxl2Z9H2GMypkNtGGy9tfGXrwmWo2dI/A/HtJLbmNqoY0luqlJtVp G6tav5BjqlI/Vg9CRFaGmoTT9/5H4E71TIsGiVApwigtkpyIsyeitm7hC1Y1XRGyZ0GY 3n5ZGCVi6XNJ2eaI+S5H/1ZwXg2A5HJ5zC7t2ZIt1djPMtIlYAUHQfZuTntqAK2e/SyG y4yQ== 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=jaeBKd2588gwtTJA1dNcYNPRKjLEqNsjOOLvdzic+bk=; b=AFk7qO/STZET+maYl/aKD4SiwUqZkfBDzq7QUwaGWeamcrvo8w5/qNec5mCNFJh8+9 HvPBpCurgFt7yUVy/N5C0AlHsE+FB+AZrsLNvHcIIW6b2/JJ/aJkauSS/lS2e0MQ8o3/ UnzFXNHJXl5wSynWOxYoJaRS9YIQxwwgOh9JXukdsv6Y6dcp2hyCfwTuRj4Dwpu6jIm6 2faSnQG6Ym77HHoeDKOCFk+a2AkaIlsbVZoDu48TkiMT0k+PEs+m9ezSLO8mkFCbBJiE bf4bbkxXYw06lvjhPnQF83YhOzHMq3kX0ViSXuvORjmjqfZsOT0vGDvQmwBOEhUo3IFT QphA== X-Gm-Message-State: AOAM530WC48HDER5ahVA1kQTnMheBqeifM2FD1eQ93ktrZaxd8sJkaSS QIePD6xG6oTLRmEY9HaBhXlu6jGL6MpJ0w== X-Received: by 2002:a17:90a:8417:: with SMTP id j23mr18325344pjn.168.1625615379216; Tue, 06 Jul 2021 16:49:39 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/36] linux-user: Replace bprm->fd with bprm->src.fd Date: Tue, 6 Jul 2021 16:49:04 -0700 Message-Id: <20210706234932.356913-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There are only a couple of uses of bprm->fd remaining. Migrate to the other field. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/qemu.h | 1 - linux-user/flatload.c | 8 ++++---- linux-user/linuxload.c | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/linux-user/qemu.h b/linux-user/qemu.h index f4cdfb16b3..dafaae6293 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -211,7 +211,6 @@ struct linux_binprm { char buf[BPRM_BUF_SIZE] __attribute__((aligned)); ImageSource src; abi_ulong p; - int fd; int e_uid, e_gid; int argc, envc; char **argv; diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 3e5594cf89..58d0d9352c 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -460,7 +460,7 @@ static int load_flat_file(struct linux_binprm * bprm, DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n"); textpos = target_mmap(0, text_len, PROT_READ|PROT_EXEC, - MAP_PRIVATE, bprm->fd, 0); + MAP_PRIVATE, bprm->src.fd, 0); if (textpos == -1) { fprintf(stderr, "Unable to mmap process text\n"); return -1; @@ -487,7 +487,7 @@ static int load_flat_file(struct linux_binprm * bprm, } else #endif { - result = target_pread(bprm->fd, datapos, + result = target_pread(bprm->src.fd, datapos, data_len + (relocs * sizeof(abi_ulong)), fpos); } @@ -537,10 +537,10 @@ static int load_flat_file(struct linux_binprm * bprm, else #endif { - result = target_pread(bprm->fd, textpos, + result = target_pread(bprm->src.fd, textpos, text_len, 0); if (result >= 0) { - result = target_pread(bprm->fd, datapos, + result = target_pread(bprm->src.fd, datapos, data_len + (relocs * sizeof(abi_ulong)), ntohl(hdr->data_start)); } diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 8b93b9704c..d0d3f2ed0e 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -36,7 +36,7 @@ static int prepare_binprm(struct linux_binprm *bprm) int mode; int retval; - if (fstat(bprm->fd, &st) < 0) { + if (fstat(bprm->src.fd, &st) < 0) { return -errno; } @@ -66,7 +66,7 @@ static int prepare_binprm(struct linux_binprm *bprm) bprm->e_gid = st.st_gid; } - retval = read(bprm->fd, bprm->buf, BPRM_BUF_SIZE); + retval = read(bprm->src.fd, bprm->buf, BPRM_BUF_SIZE); if (retval < 0) { perror("prepare_binprm"); exit(-1); @@ -133,7 +133,6 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, { int retval; - bprm->fd = fdexec; bprm->src.fd = fdexec; bprm->filename = (char *)filename; bprm->argc = count(argv); From patchwork Tue Jul 6 23:49:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470565 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5545690ejx; Tue, 6 Jul 2021 16:52:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSB20vl4SD9FDeLJIh8PKeGjhfydZEhZbYk1StM1du8AQ9a+uoCZk8ShNX+xK572k0tUr1 X-Received: by 2002:a05:6e02:1ba5:: with SMTP id n5mr5380932ili.9.1625615533549; Tue, 06 Jul 2021 16:52:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615533; cv=none; d=google.com; s=arc-20160816; b=xxEmu3YgleQoCrdQptrUPVnSE7a/j7VIPfrYbRYzCMWkj4c3tfQA+x6cwUeA2tKBU8 NISiqSEAlhLTXzeLZdIbNFRxfmjqJitmLPoAPh8pubF6ASS+E8fAV7naLyibYMnmjYxu vIF7NGYbJNOVBJxbuc73dPqN9eqpgnOVnN2cCiTXW0kym+OeXnmOlKyqv9PIFNXvO9O0 hqzKivZ3bzxZ80JPDg85DCPBVAAcdx+Uw5WveizQ91ZEVWD87NYwXXYuL9SD9qkSrGSf oZh0Y6mDSby0drI8YYVnhDqkwTKKqk28WPZk0bW9tPCN+klXG8kToqjNmEHTEvR5ZCeL 1h4A== 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=VyCrJ1NajI+6XPdRKaz4cUDALrALvSj8LgDRn36KsCA=; b=UZ3K8LWJJ7C7RJR02DnO9GYhwr4VL8B6y+AzwTDJl0vxJb6ZVai74CDYG9VuJqMTgJ GGu1GzDh1sIn33G4cR3Ei+jnvynbrNDnkikFfGy3gGAuLxjZ49Ek+sGCW42JVMJPXRI+ tezshDqYBajdBXnVktlX3dHRJUxKeza6K/+A2fKY8pXD66OHt13Z2E23k4e6Mphvf8a9 ip7O1f2gSD0e6sP9zn9O9gL/JDT2h2/zd1rP7nNPb9f9KlA1ap3+QPe5xXyayu072Aqp rlYmAhNb654vNq9VgO18Ne70Vae1qjHmZ2iOkp7gb0TBCenSGZcBcxMYOoOkxVY3gBDe GXSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=e75WIOqi; 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 12si12086573ilz.15.2021.07.06.16.52.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:52:13 -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=e75WIOqi; 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]:44194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0urM-0006LF-S5 for patch@linaro.org; Tue, 06 Jul 2021 19:52:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uow-0000rj-R8 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:42 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:36486) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uov-0006cK-1U for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:42 -0400 Received: by mail-pl1-x629.google.com with SMTP id u19so62086plc.3 for ; Tue, 06 Jul 2021 16:49:40 -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=VyCrJ1NajI+6XPdRKaz4cUDALrALvSj8LgDRn36KsCA=; b=e75WIOqizxDggPB8V7ozizTlxn9hyjg0LF+clVFcY+Cax7cC6TK/DlECCqNv5iRF+q dxzi70UPNGr/RilaixTzHExfnn9oEa7T7/ucK8wFE3qn+yl5+J4xFF00oJo36h62AVkM OWABSjzQzv85YNvklICjbW9MAzq8QFB2nij8kPGeZw4l4CS5H5ztgCJ/yL5PRLkrccO9 cK8nC5kuh5/xRuaycyTk8GiMOBaEwSO3idbkuS15Zg0mGPIygXXGZdqGR5oOxI2vPBIt JH7AwXcLZXyOhXXUcb/HBybqCsAwu9KnpUS4lDrCnXezekFcXgm+uiAF8YICYxGZdGFE pX/Q== 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=VyCrJ1NajI+6XPdRKaz4cUDALrALvSj8LgDRn36KsCA=; b=ZQivgJWrrBDeI5tgY3WPEjmB6L0sazZCJupcD4h74lFbYd5zxGMUenY/VjkXblsKyC fj3xOijWUMPfXxHTrXRLgddvBFmMv3FHoFOAgB8IKR+LXveKI1hMCjigKiVUPP+g9A5b 3LOvcYq99we2plD0B2UboF42bJ5raMFr6Job93G40H3RfKPnuNLrxZMOK/B73E99BW0J Qy1nnPOL8UZkYrZRWe43a8Vyl8CDeZAE8GWyr/cOcG4tEmG9NKEOufI99A9F97ZX0RVO o1xDdNYV0J7CX6Xm8tK3HChuhsTzAlJuvsnUblz+IFpU5w9Rtgq7jenCdmbuCBiWYtHh TbfQ== X-Gm-Message-State: AOAM533frfxE9cOujZyO81AFM/jp1HEyLoyFXFTpTgdZVgNhnj6YtS7g urd+0MbE1pQFMS3PsO+urxl2RnrdMYcarw== X-Received: by 2002:a17:90b:e05:: with SMTP id ge5mr2865876pjb.93.1625615379797; Tue, 06 Jul 2021 16:49:39 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 09/36] linux-user: Introduce imgsrc_mmap Date: Tue, 6 Jul 2021 16:49:05 -0700 Message-Id: <20210706234932.356913-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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" Signed-off-by: Richard Henderson --- linux-user/qemu.h | 11 +++++++++++ linux-user/elfload.c | 4 ++-- linux-user/linuxload.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/linux-user/qemu.h b/linux-user/qemu.h index dafaae6293..255182e133 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -199,6 +199,17 @@ bool imgsrc_read(void *dst, off_t offset, size_t len, void *imgsrc_read_alloc(off_t offset, size_t len, const ImageSource *img, Error **errp); +/** + * imgsrc_mmap: Map from ImageSource + * + * If @src has a file descriptor, pass on to target_mmap. Otherwise, + * this is "mapping" from a host buffer, which resolves to memcpy. + * Therefore, flags must be MAP_PRIVATE | MAP_FIXED; the argument is + * retained for clarity. + */ +abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot, + int flags, const ImageSource *src, abi_ulong offset); + /* Read a good amount of data initially, to hopefully get all the program headers loaded. */ #define BPRM_BUF_SIZE 1024 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 490b374d13..ec4b5f9d54 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2837,9 +2837,9 @@ static void load_elf_image(const char *image_name, const ImageSource *src, */ if (eppnt->p_filesz != 0) { vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po); - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, + error = imgsrc_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED, - src->fd, eppnt->p_offset - vaddr_po); + src, eppnt->p_offset - vaddr_po); if (error == -1) { goto exit_mmap; diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index d0d3f2ed0e..a437a22b49 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -208,3 +208,47 @@ void *imgsrc_read_alloc(off_t offset, size_t len, } return alloc; } + +abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot, + int flags, const ImageSource *src, abi_ulong offset) +{ + abi_long ret; + int prot_write; + void *haddr; + + assert(flags == (MAP_PRIVATE | MAP_FIXED)); + + if (src->fd >= 0) { + return target_mmap(start, len, prot, flags, src->fd, offset); + } + + /* + * This case is for the vdso; we don't expect bad images. + * The mmap may extend beyond the end of the image, especially + * to the end of the page. Zero fill. + */ + assert(offset < src->cache_size); + + prot_write = prot | PROT_WRITE; + ret = target_mmap(start, len, prot_write, flags | MAP_ANON, -1, 0); + if (ret == -1) { + return ret; + } + + haddr = lock_user(VERIFY_WRITE, start, len, 0); + assert(haddr != NULL); + if (offset + len < src->cache_size) { + memcpy(haddr, src->cache + offset, len); + } else { + size_t rest = src->cache_size - offset; + memcpy(haddr, src->cache + offset, rest); + memset(haddr + rest, 0, len - rest); + } + unlock_user(haddr, start, len); + + if (prot != prot_write) { + target_mprotect(start, len, prot); + } + + return ret; +} From patchwork Tue Jul 6 23:49:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470614 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5551957ejx; Tue, 6 Jul 2021 17:03:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwk3+82nhoMtJe9WIIr64NdzBmHczP6uTbJFWmPDuRR1SxKJQcgVXGyEu2UDUEZVU5L7/mA X-Received: by 2002:aa7:c1c7:: with SMTP id d7mr26465408edp.183.1625616191200; Tue, 06 Jul 2021 17:03:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616191; cv=none; d=google.com; s=arc-20160816; b=OsK/Buqi71INvKaXBpHcEsjC2PmrQekdYqfivFk44kxsHxoAto0COTm3U+Ngo80JYB YNkkUih4WOOln2+BHR146Fti007q5CKDW+qOz0JFvGgQ50MOsHgV/hj42lbkXKo1Ssei gbLUIs0cxO6QJP0llrqkC4r14S8P/mue1cIdfduzYpqeDxmudTcibSjJeiItbE9lIxwI IwvgnIjUXmtls0cWEXFTg0NaYkBL31xlV5ghOR5yHp6MC5YOVcW10CdJrnU4QDvwHG9A 4oB7nF7YR1o72K+s3E32PLyNugDPAmLVXpz/u8TWPquPSFrEsM/LsgPDFKoQud8FMBde GKwg== 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=tFcDGdeVO1+L5j0MeCoRvjHxmx8xNNu9D1iWMQlVWww=; b=cY6RUau8fj+yvY1ucRlN9Q3v3bZSO3HqBkFEaeRG4Vwaj6DwAZSgXEUngdmPUiBUsI KQtWBYTQ7KzgTeg9KFPAcDIwk9j0wVxy2et4t1vTh1tL7XF54FRw3kbbga+NKCn0gLhp 4LhhfSh6F5sQns4+5mR5XYwtvXGAFAYWlZthgqyipdWHMNCifOxqJvWKf2hm4u4t2dty LbyxYS30+HOwuGvMjJGt0BMX1qY9+vkN8Yo9WdPdySQYEqBuJY/NFYNhwdDanjx7uRkx Q/rT1K45BXcTk0CoTdDErKC8aT/h+1PNkHDQ5E44fw+n7yP1OHwxwO+ONKiBpeKeRpU0 NGkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kPFvBsX4; 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 r21si18983751ejo.665.2021.07.06.17.03.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:03:11 -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=kPFvBsX4; 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]:50462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v1y-0003yj-4G for patch@linaro.org; Tue, 06 Jul 2021 20:03:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uox-0000tz-ML for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:43 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:39933) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uov-0006ca-KW for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:43 -0400 Received: by mail-pg1-x534.google.com with SMTP id a2so402871pgi.6 for ; Tue, 06 Jul 2021 16:49:41 -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=tFcDGdeVO1+L5j0MeCoRvjHxmx8xNNu9D1iWMQlVWww=; b=kPFvBsX4P4djFhjN+9L3FbeHGQaxNd7Q2ogpgUdUoPht39Yg38NMmCCRT9B8Yh1Bfh sy9Q1PhWwF4nOQUOPQBgryZ5aY+G6Le249ytuaauDfU5t2aDa/YxHOWGy3atgSH8fLv+ iesp/LvqHxsrSUF6uKbfBYVcYrgmIDiqysnJGcTardUHztkwNalZ56WhG6XL0g6+A2Al NIQz2HB8hH90mbr6PVD1nS2y+88WiAw88rat05Xu+h3B0/O57TNZJTkwBpf127C5FcLw 3Qaao70vQZbvJR1QOhKqMQsxA51Cw8lOtTAHc/TU4NxornpIK2loLRi6bZmHQyCqUNtp dYMA== 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=tFcDGdeVO1+L5j0MeCoRvjHxmx8xNNu9D1iWMQlVWww=; b=PzSRnQY6NNt41G/JRv41kvOO1HQOvcuYgrXWQM9ThXMFU7Ym0Uy1GUt0gHGYiT7nCM za9l5Re2ysUCbM4VYst9ywsfexO9Zzi4mDtjX2aDvQUVyYcasxMpZoK3tk3wmUTPqT8S N/yXrgd0Hb7YAHwNLR8HUrfEKcMpcyloU9A4Hx2gjYzGwg7/JjjpZAt3K4WXYzE6D9kS U76vDDq5Nux+qxoe907iHH9yp59sSWR+q4FbO5MGbVO7zBqiOKKtad4U7xfyfqXBUsT0 f0MCiisHlS0K2A84LvJP7zU4ebupmhvWLJGViBRRIh/Ul2+y1xGHUNMrRwq5nZeCXVNE fzoQ== X-Gm-Message-State: AOAM532cA5a77srbkmt4GqcWhl1geMfFMJQZ+DQR9ePmZIJKo1tUqCkx 7pRhh9pPP6/9LT9e2VTp7pfM+66+3gdHuw== X-Received: by 2002:a62:3344:0:b029:24c:735c:4546 with SMTP id z65-20020a6233440000b029024c735c4546mr22734657pfz.1.1625615380380; Tue, 06 Jul 2021 16:49:40 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/36] linux-user: Load vdso image if available Date: Tue, 6 Jul 2021 16:49:06 -0700 Message-Id: <20210706234932.356913-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.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" The vdso image will be pre-processed into a C data array, with a simple list of relocations to perform, and identifying the location of signal trampolines. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 80 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ec4b5f9d54..f76281fe40 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -30,6 +30,15 @@ #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0 #endif +typedef struct { + const uint8_t *image; + const uint32_t *relocs; + unsigned image_size; + unsigned reloc_count; + unsigned sigreturn_ofs; + unsigned rt_sigreturn_ofs; +} VdsoImageInfo; + #define ELF_OSABI ELFOSABI_SYSV /* from personality.h */ @@ -1971,7 +1980,8 @@ static abi_ulong loader_build_fdpic_loadmap(struct image_info *info, abi_ulong s static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, struct elfhdr *exec, struct image_info *info, - struct image_info *interp_info) + struct image_info *interp_info, + struct image_info *vdso_info) { abi_ulong sp; abi_ulong u_argc, u_argv, u_envp, u_auxv; @@ -2043,8 +2053,12 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } size = (DLINFO_ITEMS + 1) * 2; - if (k_platform) + if (k_platform) { size += 2; + } + if (vdso_info) { + size += 2; + } #ifdef DLINFO_ARCH_ITEMS size += DLINFO_ARCH_ITEMS * 2; #endif @@ -2121,6 +2135,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, if (u_platform) { NEW_AUX_ENT(AT_PLATFORM, u_platform); } + if (vdso_info) { + NEW_AUX_ENT(AT_SYSINFO_EHDR, vdso_info->load_addr); + } NEW_AUX_ENT (AT_NULL, 0); #undef NEW_AUX_ENT @@ -2947,6 +2964,49 @@ static void load_elf_interp(const char *filename, struct image_info *info, load_elf_image(filename, &src, info, &ehdr, NULL); } +#ifndef vdso_image_info +#define vdso_image_info() NULL +#endif + +static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vdso) +{ + ImageSource src; + struct elfhdr ehdr; + abi_ulong load_bias, load_addr; + + src.fd = -1; + src.cache = vdso->image; + src.cache_size = vdso->image_size; + + load_elf_image("", &src, info, &ehdr, NULL); + load_addr = info->load_addr; + load_bias = info->load_bias; + + /* + * We need to relocate the VDSO image. The one built into the kernel + * is built for a fixed address. The one built for QEMU is not, since + * that requires close control of the guest address space. + * We pre-processed the image to locate all of the addresses that need + * to be updated. + */ + for (unsigned i = 0, n = vdso->reloc_count; i < n; i++) { + abi_ulong *addr = g2h_untagged(load_addr + vdso->relocs[i]); + *addr = tswapal(tswapal(*addr) + load_bias); + } + + /* Install signal trampolines, if present. */ + if (vdso->sigreturn_ofs) { + default_sigreturn = load_addr + vdso->sigreturn_ofs; + } + if (vdso->rt_sigreturn_ofs) { + default_rt_sigreturn = load_addr + vdso->rt_sigreturn_ofs; + } + + /* Mark the VDSO writable segment read-only. */ + target_mprotect(info->start_data, info->end_data - info->start_data, + PROT_READ); +} + static int symfind(const void *s0, const void *s1) { target_ulong addr = *(target_ulong *)s0; @@ -3151,7 +3211,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) * and let elf_load_image do any swapping that may be required. */ struct elfhdr ehdr; - struct image_info interp_info; + struct image_info interp_info, vdso_info; char *elf_interpreter = NULL; char *scratch; @@ -3221,10 +3281,13 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) } /* - * TODO: load a vdso, which would also contain the signal trampolines. - * Otherwise, allocate a private page to hold them. + * Load a vdso if available, which will amongst other things contain the + * signal trampolines. Otherwise, allocate a separate page for them. */ - if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { + const VdsoImageInfo *vdso = vdso_image_info(); + if (vdso) { + load_elf_vdso(&vdso_info, vdso); + } else if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { abi_ulong tramp_page = target_mmap(0, TARGET_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); @@ -3232,8 +3295,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC); } - bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, - info, (elf_interpreter ? &interp_info : NULL)); + bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, info, + elf_interpreter ? &interp_info : NULL, + vdso ? &vdso_info : NULL); info->start_stack = bprm->p; /* If we have an interpreter, set that as the program's entry point. From patchwork Tue Jul 6 23:49:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470562 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5545070ejx; Tue, 6 Jul 2021 16:51:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCycVPBRE8oT0NvOchpJy3hujY9PuNLr4JWIY5t0eHHSBZAz7NWV7EG5MQ+Wj58yYxCpBK X-Received: by 2002:ac8:4cdb:: with SMTP id l27mr101469qtv.350.1625615466343; Tue, 06 Jul 2021 16:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615466; cv=none; d=google.com; s=arc-20160816; b=LhXfTqNvBlJDNToq+ApBtFQeQS4mQ6c3oapRx7Mka4mflXM0H9i67Fb7jfLMkdZ3xZ 48PCLRrnLXya53+KH6TRz5pwlnWPVEQ+XlR97hSXpR37ZTN50iGu+Hwl0G9JEwiqu1zU gtMfWQjRy4u+FG1kYREjAUWuIdmkuDXhKiS2FzHxjqgQAH5YMKEYhlanoyIoyF8PwRIT L3a4/s4srMtE4r/E+e9Ey48VFs1tIsxJNgo5xp/975UQbG+BOxV60Lckgp2XJ/snUwVG +ubRvvMusPnlz/2E8ucHbofqip3Ncy1//yG+PBWJ0WeyDQqBb2AGvP2pQAkSmbSBpT/U OA+w== 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=eJcHVEtHAhsxfnKBSR30fwhWS+sM2DalBDLd0EcPGWk=; b=BXePFsNgVemLw0OuG96Q6oKoov/v0Vw9eg7d7Szbr8p80IczN/Z/piimS2+Cc2iuZ8 cEjt+U0oR/xPXwOduuva2AQjVArYKRGvctrRqtDC8Wn2hg+7X/6WbfKzlT5tQkPRB/aY Xf2DeOpnViNUbSbUjAfDSq6HVUZlKzzPXN5cgfSbkrDqg5Uad2Ig6uS2jHTkC0gpw34U pS/0Qte8vGhOipflT/LSZwab4Dc7UIGxAvjLEoKgl8/xBuduKRAv7omEWQFcZ77z9z1R 5ATSoONuYWC9A5JH8jn6MJOyvkXSdq32syorLMJ79jFyxa1ZgGru9nPoBJuB8wGuI7L0 3MMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DPZUCmmt; 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 a23si12968121qkn.257.2021.07.06.16.51.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:51:06 -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=DPZUCmmt; 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]:36310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uqH-00017x-Iq for patch@linaro.org; Tue, 06 Jul 2021 19:51:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uoz-0000zR-OF for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:45 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:46690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uow-0006cv-I3 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:45 -0400 Received: by mail-pj1-x1029.google.com with SMTP id b5-20020a17090a9905b029016fc06f6c5bso466429pjp.5 for ; Tue, 06 Jul 2021 16:49:42 -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=eJcHVEtHAhsxfnKBSR30fwhWS+sM2DalBDLd0EcPGWk=; b=DPZUCmmt5QLmZG/PL+jS3HSa6BuW4Z5jAwCdJITzTlt8TLX3n0rQwLw7nIdkgC347J yZ0ViSQd+7ucb4tBlUlQbXiAHVzXJUBFS7qt7rEB17X0FfoE74a5wfhYGlC60NU11QUp DWCYjcZrxSlA7EOAiGMEz7xolywKd1CVHyxd6LOzo4o15lHcw1EP2pedobGEmzIjFMDJ Jl3PyPb3Y94CUe2w6mNFttx6J3ChZgBsl57OZgs26IqEonH3zogCw711CATXaUrGgc47 nLL/X6Zl34vd58BE4iSicp9yEk0Xmob17pZ/Vs/K63gOK0376aq3TiEuVSvbgi26R5Ok jyQg== 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=eJcHVEtHAhsxfnKBSR30fwhWS+sM2DalBDLd0EcPGWk=; b=DXl2Ad71aZn8GGV4gsxxgOfh/cGS2MIRGOf1F4d/m5BOtWMgCPUYLRRr4IhvH/VtjI gGn5vq9yQIU2SdvyiIJm7ov2bwYo07/+LoSvlqW54URIDvpKXF+19PKF3oHcAGiJYT4y l5B2vsLGewZTM8ASrQKI4etwmJw1FU4YepP6h5XNuNuF4RxnbEMtNlayZy10nLLRpTvq w60qBgBt/NO6FomIzfzo848veJ0trYJAr6VkBEuwpC6CBJxGeHmv0rFYHt9gpHYuW/tb itTk83NBLtPAyWXC1tq76DMYH3mGBT0b97iw+32vuxw+HaAxV93JhuZO54q43S+fswka kNFA== X-Gm-Message-State: AOAM531MrDqRAdPKpcOadYVO/+oa+F/gzIqK5VJ5WL/egewGUbYasCEL 3iUJTpCaqzaPqU6QLwgjDxGpy357YMJWaQ== X-Received: by 2002:a17:90a:928c:: with SMTP id n12mr22612678pjo.30.1625615381089; Tue, 06 Jul 2021 16:49:41 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 11/36] linux-user: Add gen-vdso tool Date: Tue, 6 Jul 2021 16:49:07 -0700 Message-Id: <20210706234932.356913-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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" This tool will be used for post-processing the linked vdso image, turning it into something that is easy to include into elfload.c. Signed-off-by: Richard Henderson --- linux-user/gen-vdso.c | 223 ++++++++++++++++++++++++ linux-user/gen-vdso-elfn.c.inc | 306 +++++++++++++++++++++++++++++++++ linux-user/meson.build | 6 +- 3 files changed, 534 insertions(+), 1 deletion(-) create mode 100644 linux-user/gen-vdso.c create mode 100644 linux-user/gen-vdso-elfn.c.inc -- 2.25.1 diff --git a/linux-user/gen-vdso.c b/linux-user/gen-vdso.c new file mode 100644 index 0000000000..494b9a7e7a --- /dev/null +++ b/linux-user/gen-vdso.c @@ -0,0 +1,223 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "elf.h" + + +#define bswap_(p) _Generic(*(p), \ + uint16_t: __builtin_bswap16, \ + uint32_t: __builtin_bswap32, \ + uint64_t: __builtin_bswap64, \ + int16_t: __builtin_bswap16, \ + int32_t: __builtin_bswap32, \ + int64_t: __builtin_bswap64) +#define bswaps(p) (*(p) = bswap_(p)(*(p))) + +static void output_reloc(FILE *outf, void *buf, void *loc) +{ + fprintf(outf, " 0x%08lx,\n", loc - buf); +} + +static const char *sigreturn_sym; +static const char *rt_sigreturn_sym; + +static unsigned sigreturn_addr; +static unsigned rt_sigreturn_addr; + +#define N 32 +#define elfN(x) elf32_##x +#define ElfN(x) Elf32_##x +#include "gen-vdso-elfn.c.inc" +#undef N +#undef elfN +#undef ElfN + +#define N 64 +#define elfN(x) elf64_##x +#define ElfN(x) Elf64_##x +#include "gen-vdso-elfn.c.inc" +#undef N +#undef elfN +#undef ElfN + + +int main(int argc, char **argv) +{ + FILE *inf, *outf; + long total_len; + const char *prefix = "vdso"; + const char *inf_name; + const char *outf_name = NULL; + unsigned char *buf; + bool need_bswap; + + while (1) { + int opt = getopt(argc, argv, "o:p:r:s:"); + if (opt < 0) { + break; + } + switch (opt) { + case 'o': + outf_name = optarg; + break; + case 'p': + prefix = optarg; + break; + case 'r': + rt_sigreturn_sym = optarg; + break; + case 's': + sigreturn_sym = optarg; + break; + default: + usage: + fprintf(stderr, "usage: [-p prefix] [-r rt-sigreturn-name] " + "[-s sigreturn-name] -o output-file input-file\n"); + return EXIT_FAILURE; + } + } + + if (optind >= argc || outf_name == NULL) { + goto usage; + } + inf_name = argv[optind]; + + /* + * Open the input and output files. + */ + inf = fopen(inf_name, "rb"); + if (inf == NULL) { + goto perror_inf; + } + outf = fopen(outf_name, "w"); + if (outf == NULL) { + goto perror_outf; + } + + /* + * Read the input file into a buffer. + * We expect the vdso to be small, on the order of one page, + * therefore we do not expect a partial read. + */ + fseek(inf, 0, SEEK_END); + total_len = ftell(inf); + fseek(inf, 0, SEEK_SET); + + buf = malloc(total_len); + if (buf == NULL) { + goto perror_inf; + } + + errno = 0; + if (fread(buf, 1, total_len, inf) != total_len) { + if (errno) { + goto perror_inf; + } + fprintf(stderr, "%s: incomplete read\n", inf_name); + return EXIT_FAILURE; + } + fclose(inf); + + /* + * Write out the vdso image now, before we make local changes. + */ + + fprintf(outf, + "/* Automatically generated from linux-user/gen-vdso.c. */\n" + "\n" + "static const uint8_t %s_image[] = {", + prefix); + for (long i = 0; i < total_len; ++i) { + if (i % 12 == 0) { + fputs("\n ", outf); + } + fprintf(outf, " 0x%02x,", buf[i]); + } + fprintf(outf, "\n};\n\n"); + + /* + * Identify which elf flavor we're processing. + * The first 16 bytes of the file are e_ident. + */ + + if (buf[EI_MAG0] != ELFMAG0 || buf[EI_MAG1] != ELFMAG1 || + buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3) { + fprintf(stderr, "%s: not an elf file\n", inf_name); + return EXIT_FAILURE; + } + switch (buf[EI_DATA]) { + case ELFDATA2LSB: + need_bswap = BYTE_ORDER != LITTLE_ENDIAN; + break; + case ELFDATA2MSB: + need_bswap = BYTE_ORDER != BIG_ENDIAN; + break; + default: + fprintf(stderr, "%s: invalid elf EI_DATA (%u)\n", + inf_name, buf[EI_DATA]); + return EXIT_FAILURE; + } + + /* + * We need to relocate the VDSO image. The one built into the kernel + * is built for a fixed address. The one we built for QEMU is not, + * since that requires close control of the guest address space. + * + * Output relocation addresses as we go. + */ + + fprintf(outf, "static const unsigned %s_relocs[] = {\n", prefix); + + switch (buf[EI_CLASS]) { + case ELFCLASS32: + elf32_process(outf, buf, need_bswap); + break; + case ELFCLASS64: + elf64_process(outf, buf, need_bswap); + break; + default: + fprintf(stderr, "%s: invalid elf EI_CLASS (%u)\n", + inf_name, buf[EI_CLASS]); + return EXIT_FAILURE; + } + + fprintf(outf, "};\n\n"); /* end vdso_relocs. */ + + fprintf(outf, "static const VdsoImageInfo %s_image_info = {\n", prefix); + fprintf(outf, " .image = %s_image,\n", prefix); + fprintf(outf, " .relocs = %s_relocs,\n", prefix); + fprintf(outf, " .image_size = sizeof(%s_image),\n", prefix); + fprintf(outf, " .reloc_count = ARRAY_SIZE(%s_relocs),\n", prefix); + fprintf(outf, " .sigreturn_ofs = 0x%x,\n", sigreturn_addr); + fprintf(outf, " .rt_sigreturn_ofs = 0x%x,\n", rt_sigreturn_addr); + fprintf(outf, "};\n"); + + /* + * Everything should have gone well. + */ + if (fclose(outf)) { + goto perror_outf; + } + return EXIT_SUCCESS; + + perror_inf: + perror(inf_name); + return EXIT_FAILURE; + + perror_outf: + perror(outf_name); + return EXIT_FAILURE; +} diff --git a/linux-user/gen-vdso-elfn.c.inc b/linux-user/gen-vdso-elfn.c.inc new file mode 100644 index 0000000000..d1db9cbf49 --- /dev/null +++ b/linux-user/gen-vdso-elfn.c.inc @@ -0,0 +1,306 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * Elf size specialization. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +static void elfN(bswap_ehdr)(ElfN(Ehdr) *ehdr) +{ + bswaps(&ehdr->e_type); /* Object file type */ + bswaps(&ehdr->e_machine); /* Architecture */ + bswaps(&ehdr->e_version); /* Object file version */ + bswaps(&ehdr->e_entry); /* Entry point virtual address */ + bswaps(&ehdr->e_phoff); /* Program header table file offset */ + bswaps(&ehdr->e_shoff); /* Section header table file offset */ + bswaps(&ehdr->e_flags); /* Processor-specific flags */ + bswaps(&ehdr->e_ehsize); /* ELF header size in bytes */ + bswaps(&ehdr->e_phentsize); /* Program header table entry size */ + bswaps(&ehdr->e_phnum); /* Program header table entry count */ + bswaps(&ehdr->e_shentsize); /* Section header table entry size */ + bswaps(&ehdr->e_shnum); /* Section header table entry count */ + bswaps(&ehdr->e_shstrndx); /* Section header string table index */ +} + +static void elfN(bswap_phdr)(ElfN(Phdr) *phdr) +{ + bswaps(&phdr->p_type); /* Segment type */ + bswaps(&phdr->p_flags); /* Segment flags */ + bswaps(&phdr->p_offset); /* Segment file offset */ + bswaps(&phdr->p_vaddr); /* Segment virtual address */ + bswaps(&phdr->p_paddr); /* Segment physical address */ + bswaps(&phdr->p_filesz); /* Segment size in file */ + bswaps(&phdr->p_memsz); /* Segment size in memory */ + bswaps(&phdr->p_align); /* Segment alignment */ +} + +static void elfN(bswap_shdr)(ElfN(Shdr) *shdr) +{ + bswaps(&shdr->sh_name); + bswaps(&shdr->sh_type); + bswaps(&shdr->sh_flags); + bswaps(&shdr->sh_addr); + bswaps(&shdr->sh_offset); + bswaps(&shdr->sh_size); + bswaps(&shdr->sh_link); + bswaps(&shdr->sh_info); + bswaps(&shdr->sh_addralign); + bswaps(&shdr->sh_entsize); +} + +static void elfN(bswap_sym)(ElfN(Sym) *sym) +{ + bswaps(&sym->st_name); + bswaps(&sym->st_value); + bswaps(&sym->st_size); + bswaps(&sym->st_shndx); +} + +static void elfN(bswap_dyn)(ElfN(Dyn) *dyn) +{ + bswaps(&dyn->d_tag); /* Dynamic type tag */ + bswaps(&dyn->d_un.d_ptr); /* Dynamic ptr or val, in union */ +} + +static void elfN(search_symtab)(ElfN(Shdr) *shdr, unsigned sym_idx, + void *buf, bool need_bswap) +{ + unsigned str_idx = shdr[sym_idx].sh_link; + ElfN(Sym) *sym = buf + shdr[sym_idx].sh_offset; + unsigned sym_n = shdr[sym_idx].sh_size / sizeof(*sym); + const char *str = buf + shdr[str_idx].sh_offset; + + for (unsigned i = 0; i < sym_n; ++i) { + const char *name; + + if (need_bswap) { + elfN(bswap_sym)(sym + i); + } + name = str + sym[i].st_name; + + if (sigreturn_sym && strcmp(sigreturn_sym, name) == 0) { + sigreturn_addr = sym[i].st_value; + } + if (rt_sigreturn_sym && strcmp(rt_sigreturn_sym, name) == 0) { + rt_sigreturn_addr = sym[i].st_value; + } + } +} + +static void elfN(process)(FILE *outf, void *buf, bool need_bswap) +{ + ElfN(Ehdr) *ehdr = buf; + ElfN(Phdr) *phdr; + ElfN(Shdr) *shdr; + unsigned phnum, shnum; + unsigned dynamic_ofs = 0; + unsigned dynamic_addr = 0; + unsigned symtab_idx = 0; + unsigned dynsym_idx = 0; + unsigned first_segsz = 0; + int errors = 0; + + if (need_bswap) { + elfN(bswap_ehdr)(ehdr); + } + + phnum = ehdr->e_phnum; + phdr = buf + ehdr->e_phoff; + if (need_bswap) { + for (unsigned i = 0; i < phnum; ++i) { + elfN(bswap_phdr)(phdr + i); + } + } + + shnum = ehdr->e_shnum; + shdr = buf + ehdr->e_shoff; + if (need_bswap) { + for (unsigned i = 0; i < shnum; ++i) { + elfN(bswap_shdr)(shdr + i); + } + } + for (unsigned i = 0; i < shnum; ++i) { + switch (shdr[i].sh_type) { + case SHT_SYMTAB: + symtab_idx = i; + break; + case SHT_DYNSYM: + dynsym_idx = i; + break; + } + } + + /* + * Validate the VDSO is created as we expect: that PT_PHDR, + * PT_DYNAMIC, and PT_NOTE located in a writable data segment. + * PHDR and DYNAMIC require relocation, and NOTE will get the + * linux version number. + */ + for (unsigned i = 0; i < phnum; ++i) { + if (phdr[i].p_type == PT_LOAD && phdr[i].p_vaddr == 0) { + if (first_segsz != 0) { + fprintf(stderr, "Multiple load segments covering EHDR\n"); + errors++; + } + if (phdr[i].p_offset != 0) { + fprintf(stderr, "First vdso segment does not cover EHDR\n"); + errors++; + } + if (phdr[i].p_vaddr != 0) { + fprintf(stderr, "First vdso segment not loaded at address 0\n"); + errors++; + } + if ((phdr[i].p_flags & (PF_R | PF_W)) != (PF_R | PF_W)) { + fprintf(stderr, "First vdso segment is not read-write\n"); + errors++; + } + first_segsz = phdr[i].p_filesz; + if (first_segsz < ehdr->e_phoff + phnum * sizeof(*phdr)) { + fprintf(stderr, "First vdso segment does not cover PHDRs\n"); + errors++; + } + } + } + for (unsigned i = 0; i < phnum; ++i) { + const char *which; + + switch (phdr[i].p_type) { + case PT_PHDR: + which = "PT_PHDR"; + break; + case PT_NOTE: + which = "PT_NOTE"; + break; + case PT_DYNAMIC: + dynamic_ofs = phdr[i].p_offset; + dynamic_addr = phdr[i].p_vaddr; + which = "PT_DYNAMIC"; + break; + default: + continue; + } + if (first_segsz < phdr[i].p_vaddr + phdr[i].p_filesz) { + fprintf(stderr, "First vdso segment does not cover %s\n", which); + errors++; + } + } + if (errors) { + exit(EXIT_FAILURE); + } + + /* Relocate the program headers. */ + for (unsigned i = 0; i < phnum; ++i) { + output_reloc(outf, buf, &phdr[i].p_vaddr); + output_reloc(outf, buf, &phdr[i].p_paddr); + } + + /* Relocate the DYNAMIC entries. */ + if (dynamic_addr) { + ElfN(Dyn) *dyn = buf + dynamic_ofs; + __typeof(dyn->d_tag) tag; + + do { + + if (need_bswap) { + elfN(bswap_dyn)(dyn); + } + tag = dyn->d_tag; + + switch (tag) { + case DT_HASH: + case DT_SYMTAB: + case DT_STRTAB: + case DT_VERDEF: + case DT_VERSYM: + case DT_PLTGOT: + case DT_ADDRRNGLO ... DT_ADDRRNGHI: + /* These entries store an address in the entry. */ + output_reloc(outf, buf, &dyn->d_un.d_val); + break; + + case DT_NULL: + case DT_STRSZ: + case DT_SONAME: + case DT_DEBUG: + case DT_FLAGS: + case DT_FLAGS_1: + case DT_SYMBOLIC: + case DT_BIND_NOW: + case DT_VERDEFNUM: + case DT_VALRNGLO ... DT_VALRNGHI: + /* These entries store an integer in the entry. */ + break; + + case DT_SYMENT: + if (dyn->d_un.d_val != sizeof(ElfN(Sym))) { + fprintf(stderr, "VDSO has incorrect dynamic symbol size\n"); + errors++; + } + break; + + case DT_REL: + case DT_RELSZ: + case DT_RELA: + case DT_RELASZ: + /* + * These entries indicate that the VDSO was built incorrectly. + * It should not have any real relocations. + * ??? The RISC-V toolchain will emit these even when there + * are no relocations. Validate zeros. + */ + if (dyn->d_un.d_val != 0) { + fprintf(stderr, "VDSO has dynamic relocations\n"); + errors++; + } + break; + case DT_RELENT: + case DT_RELAENT: + case DT_TEXTREL: + /* These entries store an integer in the entry. */ + /* Should not be required; see above. */ + break; + + case DT_NEEDED: + case DT_VERNEED: + case DT_PLTREL: + case DT_JMPREL: + case DT_RPATH: + case DT_RUNPATH: + fprintf(stderr, "VDSO has external dependencies\n"); + errors++; + break; + + default: + /* This is probably something target specific. */ + fprintf(stderr, "VDSO has unknown DYNAMIC entry (%lx)\n", + (unsigned long)tag); + errors++; + break; + } + dyn++; + } while (tag != DT_NULL); + if (errors) { + exit(EXIT_FAILURE); + } + } + + /* Relocate the dynamic symbol table. */ + if (dynsym_idx) { + ElfN(Sym) *sym = buf + shdr[dynsym_idx].sh_offset; + unsigned sym_n = shdr[dynsym_idx].sh_size / sizeof(*sym); + + for (unsigned i = 0; i < sym_n; ++i) { + output_reloc(outf, buf, &sym[i].st_value); + } + } + + /* Search both dynsym and symtab for the signal return symbols. */ + if (dynsym_idx) { + elfN(search_symtab)(shdr, dynsym_idx, buf, need_bswap); + } + if (symtab_idx) { + elfN(search_symtab)(shdr, symtab_idx, buf, need_bswap); + } +} diff --git a/linux-user/meson.build b/linux-user/meson.build index 9549f81682..94556f9198 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -18,9 +18,13 @@ linux_user_ss.add(when: 'TARGET_HAS_BFLT', if_true: files('flatload.c')) linux_user_ss.add(when: 'TARGET_I386', if_true: files('vm86.c')) linux_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', if_true: files('semihost.c')) - syscall_nr_generators = {} +gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c', + native: true, build_by_default: false) +gen_vdso = generator(gen_vdso_exe, output: '@BASENAME@.c.inc', + arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@']) + subdir('alpha') subdir('arm') subdir('hppa') From patchwork Tue Jul 6 23:49:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470591 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5547346ejx; Tue, 6 Jul 2021 16:55:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2+l/3u8zfWDYIK7qLgLsgAwoikt6D9w0vUjkPNlvi8JLI86qfTHx3HIcMF77U4jQtXIO6 X-Received: by 2002:a0c:bf4b:: with SMTP id b11mr21427979qvj.11.1625615738028; Tue, 06 Jul 2021 16:55:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615738; cv=none; d=google.com; s=arc-20160816; b=L9VpeQBmPaOIA/2kji3s6e3odgKAvMTDA8fPD2dLsfQoEih1vVS2xYslLqfPbakjLW icbvpZyHX5rXmM+isNh/vI29xnjHKPEtzfjYGxt5pNKbbs4wVNm8RBrL5zh7DyKDHNX8 sae/kxYyOS3cWjiUX7Pq6QyzZKGLzhLDK1OSMjmiJ/iqXAwYi3Hs5Twg+cB6Evka46h9 /yg4zG+o8z5JZUbAzO/I9gOspebuQOYJbUuwk+fNmfjdXSHbHLuo8ocrMO0R2NOnx8gf RryYtHqc7L0k68xDz9AZfep4Po8phA1nVXWYCYYy68+CJTcIL3LtuXg+xWO5IuslGXeV 9HXg== 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=as6QYixij3GVNX+QNmzUQ2z0584ShJs8rodcwnIeWNE=; b=HzQg4ExY5PG4TBMwLPNsGyLkWBkrkuH0zcNMYxTn8Qp1lTW5XZVX2u6a8dDuPbLXj4 X5i89h0UHTYRSJhFik6Hg+WcuV3tN/ZV6qEwfEhMiVCWyFXiMNSJ4GWYwB75EtEdJ3Wt mvJhlkRKX8aEnZhFqXHfwt+UYqIYVlppYstETLm6HBrMTgnekIap78ZJbiid7xQaMqqj ZYdil4Yv3WTDktu0dVwn6lwVJuxtVFMFkEUTMOgxLMLX1ewejQ02lN1Pr/24N5yexdSd /IMEylfl+XoQF9iA82xN0x83g0raF4VwFS+yvGcbGV7CYw3dM95MbMERrh1H2xjLXNl0 pmuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=G3JF8P7x; 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 gu15si1917382qvb.102.2021.07.06.16.55.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:55:38 -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=G3JF8P7x; 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]:54036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uuf-0004Ij-AQ for patch@linaro.org; Tue, 06 Jul 2021 19:55:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0up0-000130-V5 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:46 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:33572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uox-0006d5-2H for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:46 -0400 Received: by mail-pl1-x633.google.com with SMTP id f11so78625plg.0 for ; Tue, 06 Jul 2021 16:49:42 -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=as6QYixij3GVNX+QNmzUQ2z0584ShJs8rodcwnIeWNE=; b=G3JF8P7xmgZxKH/kAVaPMzN1XUGYIkiSKpLirgqSktNynYqCs4ANolSfmoWpVGd17w ZK6Ox3Hmzqv79a2DkfgSptgKRNONTBm9WdBVbEajSHZ4P3J6h4nPc6SDzcFNQEBS00T1 5ayWAuZA23tAwQrlRgDfZi4u1X2g2mEuF7gQINt26eC+flo4/BySn74IoKnshxsGzZj1 9z5bWtInq6JEYUhFoTHZ577tje6gA7MOkF6xLIDUWN6WUA+jtP03VEO8mfWIXneKf9Ta LzchHaZtWqlGK4ktxsoqbfqCWo7OK0td9qyDHxsHfSXW8b79fZikliEOvnTlS+3Wx6S4 31DQ== 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=as6QYixij3GVNX+QNmzUQ2z0584ShJs8rodcwnIeWNE=; b=AOFxI+MtL3LJuYhzNz2FgTyZMKonE1VsJetA8IiqlSxa/F35ppHB/BGe3LIpl9uj4+ Iev8cssAZIenlhHDTPsRNC6huxQBlOHgeGQN397jbsouianNdCmxAQqIUAEaMB9nNZ8W ifwdQjQ9p4N2ID1TrterVzIMGC0+e4gHatF/vDYVRofhjTpYTB3Bym7qF6N6Bk3XkJI3 B/7pDhq85MVys4gj+vgbLX+EqGZoGxC7J6MQY6JE/nO7mzr60obe5++MOktonI+NYIp/ fUqyoz9LXivx/fqRFwPzBiUVMDy4mKES0bI+1IZroZWsWspwhWy6sKnQym8QB031qMTD IS5g== X-Gm-Message-State: AOAM530w6XySCMerot2OLmBqBGVoqCv6VwWE+YgWXxLjhfrA1FtjyDW9 rsEEvwI8Ki3NMtiYhgGLMZP4FFkOAOw3Bw== X-Received: by 2002:a17:902:f682:b029:128:e54c:f58a with SMTP id l2-20020a170902f682b0290128e54cf58amr18861749plg.13.1625615381694; Tue, 06 Jul 2021 16:49:41 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 12/36] linux-user/aarch64: Add vdso and use it for rt_sigreturn Date: Tue, 6 Jul 2021 16:49:08 -0700 Message-Id: <20210706234932.356913-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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: qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Building of the vdsos are not actually wired up to anything, since we require a cross-compiler. Just check in the files for now. Cc: qemu-arm@nongnu.org Signed-off-by: Richard Henderson --- linux-user/aarch64/signal.c | 17 ++----- linux-user/elfload.c | 4 ++ linux-user/aarch64/Makefile.vdso | 11 +++++ linux-user/aarch64/meson.build | 11 +++++ linux-user/aarch64/vdso-be.so | Bin 0 -> 6000 bytes linux-user/aarch64/vdso-le.so | Bin 0 -> 6000 bytes linux-user/aarch64/vdso.S | 77 +++++++++++++++++++++++++++++++ linux-user/aarch64/vdso.ld | 74 +++++++++++++++++++++++++++++ linux-user/meson.build | 1 + 9 files changed, 182 insertions(+), 13 deletions(-) create mode 100644 linux-user/aarch64/Makefile.vdso create mode 100644 linux-user/aarch64/meson.build create mode 100755 linux-user/aarch64/vdso-be.so create mode 100755 linux-user/aarch64/vdso-le.so create mode 100644 linux-user/aarch64/vdso.S create mode 100644 linux-user/aarch64/vdso.ld -- 2.25.1 diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index 662bcd1c4e..f4fd2cfd62 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -108,7 +108,6 @@ struct target_rt_sigframe { struct target_rt_frame_record { uint64_t fp; uint64_t lr; - uint32_t tramp[2]; }; static void target_setup_general_frame(struct target_rt_sigframe *sf, @@ -460,9 +459,9 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, layout.total_size = MAX(layout.total_size, sizeof(struct target_rt_sigframe)); - /* Reserve space for the return code. On a real system this would - * be within the VDSO. So, despite the name this is not a "real" - * record within the frame. + /* + * Reserve space for the standard frame unwind pair: fp, lr. + * Despite the name this is not a "real" record within the frame. */ fr_ofs = layout.total_size; layout.total_size += sizeof(struct target_rt_frame_record); @@ -495,15 +494,7 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, if (ka->sa_flags & TARGET_SA_RESTORER) { return_addr = ka->sa_restorer; } else { - /* - * mov x8,#__NR_rt_sigreturn; svc #0 - * Since these are instructions they need to be put as little-endian - * regardless of target default or current CPU endianness. - */ - __put_user_e(0xd2801168, &fr->tramp[0], le); - __put_user_e(0xd4000001, &fr->tramp[1], le); - return_addr = frame_addr + fr_ofs - + offsetof(struct target_rt_frame_record, tramp); + return_addr = default_rt_sigreturn; } env->xregs[0] = usig; env->xregs[29] = frame_addr + fr_ofs; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index f76281fe40..8088828f5f 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -525,10 +525,14 @@ static const char *get_elf_platform(void) #define ELF_CLASS ELFCLASS64 #ifdef TARGET_WORDS_BIGENDIAN # define ELF_PLATFORM "aarch64_be" +# include "vdso-be.c.inc" #else # define ELF_PLATFORM "aarch64" +# include "vdso-le.c.inc" #endif +#define vdso_image_info() &vdso_image_info + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/aarch64/Makefile.vdso b/linux-user/aarch64/Makefile.vdso new file mode 100644 index 0000000000..97ede674e5 --- /dev/null +++ b/linux-user/aarch64/Makefile.vdso @@ -0,0 +1,11 @@ +CROSS_CC ?= aarch64-linux-gnu-gcc +LDFLAGS := -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=sysv -Wl,--build-id=sha1 + +all: vdso-le.so vdso-be.so + +vdso-le.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mlittle-endian vdso.S -o $@ + +vdso-be.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mbig-endian vdso.S -o $@ diff --git a/linux-user/aarch64/meson.build b/linux-user/aarch64/meson.build new file mode 100644 index 0000000000..0b1b3a5560 --- /dev/null +++ b/linux-user/aarch64/meson.build @@ -0,0 +1,11 @@ +# ??? There does not seem to be a way to do +# when: ['TARGET_AARCH64', !'TARGET_WORDS_BIGENDIAN'] +# so we'd need to add TARGET_WORDS_LITTLEENDIAN. +# In the meantime, build both files for aarch64 and aarch64_be. + +gen = [ + gen_vdso.process('vdso-be.so', extra_args: ['-r', '__kernel_rt_sigreturn']), + gen_vdso.process('vdso-le.so', extra_args: ['-r', '__kernel_rt_sigreturn']) +] + +linux_user_ss.add(when: 'TARGET_AARCH64', if_true: gen) diff --git a/linux-user/aarch64/vdso-be.so b/linux-user/aarch64/vdso-be.so new file mode 100755 index 0000000000000000000000000000000000000000..b0f4a83e32f300dd41110740a78f3172efbe9d1d GIT binary patch literal 6000 zcmeHLJ!~9B6n=ZVBmpPk9D{;nL=NNvA+ip!fbb){pLa8( zym`M|trQ9#*y6)C*k+7dv&h9-2TnG_s*S9+B=h`Fa4$XQ@LV5=ILKznd9Vt z$TG*f@FmNSF}}+~Ck!T4RbK*#w}}Mx1oxwn|df zZ>=YBx|wu`?0TH0txnv#)~Ia_*?PNI-%zX@Lnm<`+O6*9;P}l(zZc@am!P`5a^aFX z8NL$Ey{6|;z+ck*d3YZ2@6ey$e~ud3e@|mI`-)~?0B^tg@nhB@z;*g~)BYO>wC`~( z6F(uoiTFF>D&k$l239IMX5Ote2nNr1(+7_UhkI?}Q_(ZNh}=gRE<%p>vF-;kFL?y= z2;>pSBalZRk3b%QJOX(H@(4U+1e%lEKjVMze>qn2cc`ivf9Lrp4flhue%12fQF+Oc zA2b{$1e7^ok-XPP$m{$OdCtQvPx%lQo1bb4$v`*2KV^_5`wn39U9so9%jUhp?`O}E zd=>lG`7I8^X#0QEv?SlRJm<|p(=e8oeAA`9V0?Z`dHgtg%Dtrj_uP*5=;x?s`yYvC z34O=Se{N{+V~%Fa@*a8gMJN9~!Pb<6wH;nMq4<5^@RF+$e&+Bcb|}JZ+PN`XuMaj} zE_W}7J(wB5Oas*7<(2s}%Wq>|i?1N6yre2?^JmIxX>kqI>FU{q`KmfwshlgHSLf#! zs%15r+S-KLCdrfyTlU|l*%0=(I%(}HVwxCiN~_yTV+b2t-CCzr*A28qtfe&wo3(z^ zaA^YJdUrFt87KW#uR9{B283}_T}x`6ST!4HDH4QfJV-fe{|%RrZ~rem@f%a*}gJ```tv^3KHffSh+hp!twL-yhbW-la}DJdZE; zf*_R8#w{{FA>ASTE+*@j`$G`${XxIYNFU-)ad^wo@%-hU5d?Wp6MtC;$rXGz+hv9L z^L=FB(GH@X*QPDmPS5vT_8o3`Z`u2c)=2RaKbb#ub``74hxI{33hXD+VBT}MslomI zZy=NPZyIBJAFjI2*mlRi<@nPavCy`lA_$QdhaamzipG|84J~x57#X5KcnIqhRw^<+ k?H{@m-Pn?z%aLtvd?gH{td~T(xA*X$nq~WKMgi;p4~13}umAu6 literal 0 HcmV?d00001 diff --git a/linux-user/aarch64/vdso-le.so b/linux-user/aarch64/vdso-le.so new file mode 100755 index 0000000000000000000000000000000000000000..975d203e6b999e01221a40fb4d2d1a5dc83d3294 GIT binary patch literal 6000 zcmeHLL1+|L82&etniw@2TTzJA74}f1PTB~v#Uc}%T@%>EC2G+kJl5SYyEVHjvlE+$ zU=R-#6uh|6BZA1GB5mONRvKm`>gUVRZWF6|XyBlZ6IycLWOrpy zHXwzo3hp0?L$A+7M|^BfaF<)SfIe=?kazWZOk9;vHXznn{mX9z&!^Yp7+46?2&mn` zT++U!=Q9!Uzm^$>}&wI~*xieq9dRe9%mK)o5Aq4YD z^OPjA1vO&4ru(S%Z&C=hp%CZ?jhi&?()e<1tt-tzy|90EU#HWm?!VOI>$LwJzULW7 z=$|!n;z=g9($nTb^Hr}k@45b>*P)1=cYVLrcDv^qwdL1reW6=Fue2|P_S_yVv^tAR`!6Ni z)H+mPlxKO!W&N7*8Do`km9fDn7S;dK9Q7}Knj77`C*Wki-FW>v0`7C>el$3Txoa_w zyP0Jb$SROkAge%Dfvf^q1+ofc704>^o)u`0tUTiX-#^}yx1PwQ3f7a)c7)smOFa$x z!^!?stpB#@EY=Lrz417U)dX}>lD7!@G|BfQB+9BSGr=_)uRB(dCr!)5a0qn&a`!dgg=i*RTJ8 zj;|W^oMt{vM}NzFnvP!3JcJ!|^i|E9I{IhL=S>|w=C?15)$6@-w>Um&cd4*Mg$Aj~ z)3XyZ)8DYJzM6#&i zi2ZPxO?Gd&?bpsS`d)}lv^rhiCA+cQskK}6puw?>HNQr7v({^dobQo6-&wRTx?Zo< z?Ib#?LAKje=e%0mRm}!RqDQvxF8N%<|7fF}Kfo8xaq#;Dik6R?xefQSQ_eN8eX#F< zt2!BHAJ`Yr|NGd_yFQv9zjxrRSibyrkdJezapr`_{P->a^X!Wo@_|Km%2^DaAKwq4 zoIQwPeB_}HhqVv+I9~(eJS`Z6Z?e|7mASLVXJ^RA_XxOI2V;K30gtm^&f?I=`5aK5 zPfY4BF<8HFVrTi1H6b70H{iS8{{f w2|7B^(GRwTIXSY%{MbJmnL};48QIGAu=#t$gbnlk$#**~e@vf`ue>Aw6>MP?*#H0l literal 0 HcmV?d00001 diff --git a/linux-user/aarch64/vdso.S b/linux-user/aarch64/vdso.S new file mode 100644 index 0000000000..41cda7eb24 --- /dev/null +++ b/linux-user/aarch64/vdso.S @@ -0,0 +1,77 @@ +/* + * aarch64 linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + +/* ??? These are in include/elf.h, which is not ready for inclusion in asm. */ +#define NT_GNU_PROPERTY_TYPE_0 5 +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1) + +#define GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT \ + (GNU_PROPERTY_AARCH64_FEATURE_1_BTI | GNU_PROPERTY_AARCH64_FEATURE_1_PAC) + + .text + +/* + * TODO: The kernel makes a big deal of turning off the .cfi directives, + * because they cause libgcc to crash, but that's because they're wrong. + * + * For now, elide the unwind info for __kernel_rt_sigreturn and rely on + * the libgcc fallback routine as we have always done. This requires + * that the code sequence used be exact. + */ + .align 4 +__kernel_rt_sigreturn: + /* No BTI C insn here -- we arrive via RET. */ + mov x8, #__NR_rt_sigreturn + svc #0 + + .globl __kernel_rt_sigreturn + .type __kernel_rt_sigreturn, %function + .size __kernel_rt_sigreturn, . - __kernel_rt_sigreturn + + .align 4 +__kernel_gettimeofday: + .cfi_startproc + bti c + mov x8, #__NR_gettimeofday + svc #0 + ret + .cfi_endproc + + .globl __kernel_gettimeofday + .type __kernel_gettimeofday, %function + .size __kernel_gettimeofday, . - __kernel_gettimeofday + + .align 4 +__kernel_clock_gettime: + .cfi_startproc + bti c + mov x8, #__NR_clock_gettime + svc #0 + ret + .cfi_endproc + + .globl __kernel_clock_gettime + .type __kernel_clock_gettime, %function + .size __kernel_clock_gettime, . - __kernel_clock_gettime + + .align 4 +__kernel_clock_getres: + .cfi_startproc + bti c + mov x8, #__NR_clock_getres + svc #0 + ret + .cfi_endproc + + .globl __kernel_clock_getres + .type __kernel_clock_getres, %function + .size __kernel_clock_getres, . - __kernel_clock_getres diff --git a/linux-user/aarch64/vdso.ld b/linux-user/aarch64/vdso.ld new file mode 100644 index 0000000000..579d27638f --- /dev/null +++ b/linux-user/aarch64/vdso.ld @@ -0,0 +1,74 @@ +/* + * Linker script for linux aarch64 replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6.39 { + global: + __kernel_rt_sigreturn; + __kernel_gettimeofday; + __kernel_clock_gettime; + __kernel_clock_getres; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* + * We can't prelink to any address without knowing something about + * the virtual memory space of the host, since that leaks over into + * the available memory space of the guest. + */ + . = SIZEOF_HEADERS; + + /* + * The following, including the FILEHDRS and PHDRS, are modified + * when we relocate the binary. We want them to be initially + * writable for the relocation; we'll force them read-only after. + */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + .data : { + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text =0xd503201f +} diff --git a/linux-user/meson.build b/linux-user/meson.build index 94556f9198..8021044053 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -25,6 +25,7 @@ gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c', gen_vdso = generator(gen_vdso_exe, output: '@BASENAME@.c.inc', arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@']) +subdir('aarch64') subdir('alpha') subdir('arm') subdir('hppa') From patchwork Tue Jul 6 23:49:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470594 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5548027ejx; Tue, 6 Jul 2021 16:56:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeU2d1cX3K7vx4ZYH1VBKfNCngp6LPK6NQxFle4iUsYE4pZsL/UutEHq8lwzOiC2Sx0F3O X-Received: by 2002:a37:4096:: with SMTP id n144mr22106246qka.271.1625615806928; Tue, 06 Jul 2021 16:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615806; cv=none; d=google.com; s=arc-20160816; b=l/bNnOL93Nh9yOp/5o23sAgBMQEKq6WKWm9o7k6WMakryzSQjsGhiq0OZsBatqeHAq eOK3MS5m9DHcejxja7cQm3iEky51cPzWaiCqhZK9dCDHl06j7zqWb6EiT0DEgOr4ER5P DA0LoMf/W/AqyPjMApaL9t2hrGrS9IBec6eLHnXV8uLIpZPosBKVuk5gGtgbByNofy4v T0a2FYoYnbtjfiOdRz9QtSgZXfNbkiItNm0vlUiM1VTgyoCTRe+1ggRZZEesHt/rGg2l SQcT3B/bo76FZaKkbZyTF1KaqjFWhL4zhb7bCu5KiZtc7jZuoZucTA2wOW2jM1813jNV a0xg== 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=hwVQg6JfrKcWBzKjLQvWYej+HfhSntpRLUvINIA96YI=; b=03dZdowP0aPd0cACtcmlZMzSE3rWlldYPAoyketVovPRF+KS+bZS2PD9PJBldGYMxu 3GmmnXk1+KqLLgA/s49fW1uk18pVaxLxWPA9pT0d4StGUSosSw3awsPB7d0nhij4DWK3 XuaAJ7P7C+BywQ6LwfHNDSWKMvornrEBWfriq5lCQrivXOoDzEwIRwIgv5t+vVkUQ+Z6 zOzzSfcCsVcAi+wzx1w+/pGtWsybfsjrfFzYnzzfMK/0OAexWECuK7nJJRNf+GdeYdL0 XHyA4IwgThEE4m8i+x6qE1iAuPouyOmC/mqn7bRiVsNND/IkVZDHfob17kX9IGuNvfPM nojA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CG31aZ1Q; 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 188si4888438qkm.125.2021.07.06.16.56.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:56:46 -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=CG31aZ1Q; 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]:33518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uvm-0000tL-83 for patch@linaro.org; Tue, 06 Jul 2021 19:56:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0up0-00010j-8k for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:46 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:43841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uox-0006dN-Jj for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:45 -0400 Received: by mail-pf1-x42d.google.com with SMTP id a127so517403pfa.10 for ; Tue, 06 Jul 2021 16:49:43 -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=hwVQg6JfrKcWBzKjLQvWYej+HfhSntpRLUvINIA96YI=; b=CG31aZ1Q1UoD/nk2lA8WNWHRZAyBMyGxO4pTT318c6mRXTbOBGpkdQi+WyIPCezNrB AXny0prqngMOX18DMhr5xMHaSv2L7ht+hfTujQi60LxDdJRv+9IxoGzbjJjoO+BF354p 1OF0RYLKoXkwTlxEX4BmlN73QMPHaDLYrZ3w8HfjFx1oh5MWfTwbCxhsdIpAohQ4F5Bu +v8g5bCHqXtvx+FzjNfFa6zlEzdyetG+PMedG5WKj4SzXaq89YORXuP1IBHNtMEHnUtA a4YqFUVmJOBBFeeWlej54nLiogkYPoubnhLGhjOWcoT0YUJdPUPf+gQbqt3ECyDeTAuy nn8Q== 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=hwVQg6JfrKcWBzKjLQvWYej+HfhSntpRLUvINIA96YI=; b=IOk3beLRt1WlyyW73Nk591rJRssZUSnusGvqDgWSdImBShV+r6kllvRUH59kQ6jnCF tiUVoFV+YK5S5FcT5PmPg3o6TqcsZuxa6aQxBCD+lKDKNCbyrBJbo3xijnL+HGKKjtl+ Dc5km5Yd/iyL1l0Hd/B5Ofh8WMJqyIWtPQg4tbf5ObWdgUdX8ZiFd8e8HS0Rf/q2OJvy 0MWigYjxRe4USg5ce8VhOWgbD85RGJGT8xJ0B3uTvqynAk4mCDYyChE+ADFYRrcB9+tO tys9DBJX8VisqHIY2ql7faMggvCXT6kC2JhxQz9D3xyc9zt0VKs1VXtKNjWNBwrFjtuf ifTQ== X-Gm-Message-State: AOAM533Vsu/14fGm3Zga0J4j6WrkB2L9QydSWeaTHC2E68DSpm/MyGVX 4hAHuiW0obI+FRF4GNsrcXviW+31DXcrgw== X-Received: by 2002:aa7:828f:0:b029:200:6e27:8c8f with SMTP id s15-20020aa7828f0000b02902006e278c8fmr22828734pfm.44.1625615382299; Tue, 06 Jul 2021 16:49:42 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 13/36] linux-user/arm: Drop v1 signal frames Date: Tue, 6 Jul 2021 16:49:09 -0700 Message-Id: <20210706234932.356913-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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: Peter Maydell , qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Version 2 signal frames are used from 2.6.12. Since cbc14e6f286, we have set UNAME_MINIMUM_RELEASE to 2.6.32, which means that version 1 signal frames are never used. Cc: qemu-arm@nongnu.org Suggested-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/arm/signal.c | 220 +--------------------------------------- 1 file changed, 4 insertions(+), 216 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c index 32b68ee302..f8288ab51c 100644 --- a/linux-user/arm/signal.c +++ b/linux-user/arm/signal.c @@ -45,14 +45,6 @@ struct target_sigcontext { abi_ulong fault_address; }; -struct target_ucontext_v1 { - abi_ulong tuc_flags; - abi_ulong tuc_link; - target_stack_t tuc_stack; - struct target_sigcontext tuc_mcontext; - target_sigset_t tuc_sigmask; /* mask last for extensibility */ -}; - struct target_ucontext_v2 { abi_ulong tuc_flags; abi_ulong tuc_link; @@ -97,28 +89,12 @@ struct target_iwmmxt_sigframe { #define TARGET_VFP_MAGIC 0x56465001 #define TARGET_IWMMXT_MAGIC 0x12ef842a -struct sigframe_v1 -{ - struct target_sigcontext sc; - abi_ulong extramask[TARGET_NSIG_WORDS-1]; - abi_ulong retcode[4]; -}; - struct sigframe_v2 { struct target_ucontext_v2 uc; abi_ulong retcode[4]; }; -struct rt_sigframe_v1 -{ - abi_ulong pinfo; - abi_ulong puc; - struct target_siginfo info; - struct target_ucontext_v1 uc; - abi_ulong retcode[4]; -}; - struct rt_sigframe_v2 { struct target_siginfo info; @@ -363,37 +339,6 @@ static void setup_sigframe_v2(struct target_ucontext_v2 *uc, } } -/* compare linux/arch/arm/kernel/signal.c:setup_frame() */ -static void setup_frame_v1(int usig, struct target_sigaction *ka, - target_sigset_t *set, CPUARMState *regs) -{ - struct sigframe_v1 *frame; - abi_ulong frame_addr = get_sigframe(ka, regs, sizeof(*frame)); - int i; - - trace_user_setup_frame(regs, frame_addr); - if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { - goto sigsegv; - } - - setup_sigcontext(&frame->sc, regs, set->sig[0]); - - for(i = 1; i < TARGET_NSIG_WORDS; i++) { - __put_user(set->sig[i], &frame->extramask[i - 1]); - } - - if (setup_return(regs, ka, frame->retcode, frame_addr, usig, - frame_addr + offsetof(struct sigframe_v1, retcode))) { - goto sigsegv; - } - - unlock_user_struct(frame, frame_addr, 1); - return; -sigsegv: - unlock_user_struct(frame, frame_addr, 1); - force_sigsegv(usig); -} - static void setup_frame_v2(int usig, struct target_sigaction *ka, target_sigset_t *set, CPUARMState *regs) { @@ -422,60 +367,7 @@ sigsegv: void setup_frame(int usig, struct target_sigaction *ka, target_sigset_t *set, CPUARMState *regs) { - if (get_osversion() >= 0x020612) { - setup_frame_v2(usig, ka, set, regs); - } else { - setup_frame_v1(usig, ka, set, regs); - } -} - -/* compare linux/arch/arm/kernel/signal.c:setup_rt_frame() */ -static void setup_rt_frame_v1(int usig, struct target_sigaction *ka, - target_siginfo_t *info, - target_sigset_t *set, CPUARMState *env) -{ - struct rt_sigframe_v1 *frame; - abi_ulong frame_addr = get_sigframe(ka, env, sizeof(*frame)); - struct target_sigaltstack stack; - int i; - abi_ulong info_addr, uc_addr; - - trace_user_setup_rt_frame(env, frame_addr); - if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { - goto sigsegv; - } - - info_addr = frame_addr + offsetof(struct rt_sigframe_v1, info); - __put_user(info_addr, &frame->pinfo); - uc_addr = frame_addr + offsetof(struct rt_sigframe_v1, uc); - __put_user(uc_addr, &frame->puc); - tswap_siginfo(&frame->info, info); - - /* Clear all the bits of the ucontext we don't use. */ - memset(&frame->uc, 0, offsetof(struct target_ucontext_v1, tuc_mcontext)); - - memset(&stack, 0, sizeof(stack)); - target_save_altstack(&stack, env); - memcpy(&frame->uc.tuc_stack, &stack, sizeof(stack)); - - setup_sigcontext(&frame->uc.tuc_mcontext, env, set->sig[0]); - for(i = 0; i < TARGET_NSIG_WORDS; i++) { - __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]); - } - - if (setup_return(env, ka, frame->retcode, frame_addr, usig, - frame_addr + offsetof(struct rt_sigframe_v1, retcode))) { - goto sigsegv; - } - - env->regs[1] = info_addr; - env->regs[2] = uc_addr; - - unlock_user_struct(frame, frame_addr, 1); - return; -sigsegv: - unlock_user_struct(frame, frame_addr, 1); - force_sigsegv(usig); + setup_frame_v2(usig, ka, set, regs); } static void setup_rt_frame_v2(int usig, struct target_sigaction *ka, @@ -516,11 +408,7 @@ void setup_rt_frame(int usig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUARMState *env) { - if (get_osversion() >= 0x020612) { - setup_rt_frame_v2(usig, ka, info, set, env); - } else { - setup_rt_frame_v1(usig, ka, info, set, env); - } + setup_rt_frame_v2(usig, ka, info, set, env); } static int @@ -554,54 +442,6 @@ restore_sigcontext(CPUARMState *env, struct target_sigcontext *sc) return err; } -static long do_sigreturn_v1(CPUARMState *env) -{ - abi_ulong frame_addr; - struct sigframe_v1 *frame = NULL; - target_sigset_t set; - sigset_t host_set; - int i; - - /* - * Since we stacked the signal on a 64-bit boundary, - * then 'sp' should be word aligned here. If it's - * not, then the user is trying to mess with us. - */ - frame_addr = env->regs[13]; - trace_user_do_sigreturn(env, frame_addr); - if (frame_addr & 7) { - goto badframe; - } - - if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) { - goto badframe; - } - - __get_user(set.sig[0], &frame->sc.oldmask); - for(i = 1; i < TARGET_NSIG_WORDS; i++) { - __get_user(set.sig[i], &frame->extramask[i - 1]); - } - - target_to_host_sigset_internal(&host_set, &set); - set_sigmask(&host_set); - - if (restore_sigcontext(env, &frame->sc)) { - goto badframe; - } - -#if 0 - /* Send SIGTRAP if we're single-stepping */ - if (ptrace_cancel_bpt(current)) - send_sig(SIGTRAP, current, 1); -#endif - unlock_user_struct(frame, frame_addr, 0); - return -TARGET_QEMU_ESIGRETURN; - -badframe: - force_sig(TARGET_SIGSEGV); - return -TARGET_QEMU_ESIGRETURN; -} - static abi_ulong *restore_sigframe_v2_vfp(CPUARMState *env, abi_ulong *regspace) { int i; @@ -734,55 +574,7 @@ badframe: long do_sigreturn(CPUARMState *env) { - if (get_osversion() >= 0x020612) { - return do_sigreturn_v2(env); - } else { - return do_sigreturn_v1(env); - } -} - -static long do_rt_sigreturn_v1(CPUARMState *env) -{ - abi_ulong frame_addr; - struct rt_sigframe_v1 *frame = NULL; - sigset_t host_set; - - /* - * Since we stacked the signal on a 64-bit boundary, - * then 'sp' should be word aligned here. If it's - * not, then the user is trying to mess with us. - */ - frame_addr = env->regs[13]; - trace_user_do_rt_sigreturn(env, frame_addr); - if (frame_addr & 7) { - goto badframe; - } - - if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) { - goto badframe; - } - - target_to_host_sigset(&host_set, &frame->uc.tuc_sigmask); - set_sigmask(&host_set); - - if (restore_sigcontext(env, &frame->uc.tuc_mcontext)) { - goto badframe; - } - - target_restore_altstack(&frame->uc.tuc_stack, env); - -#if 0 - /* Send SIGTRAP if we're single-stepping */ - if (ptrace_cancel_bpt(current)) - send_sig(SIGTRAP, current, 1); -#endif - unlock_user_struct(frame, frame_addr, 0); - return -TARGET_QEMU_ESIGRETURN; - -badframe: - unlock_user_struct(frame, frame_addr, 0); - force_sig(TARGET_SIGSEGV); - return -TARGET_QEMU_ESIGRETURN; + return do_sigreturn_v2(env); } static long do_rt_sigreturn_v2(CPUARMState *env) @@ -823,9 +615,5 @@ badframe: long do_rt_sigreturn(CPUARMState *env) { - if (get_osversion() >= 0x020612) { - return do_rt_sigreturn_v2(env); - } else { - return do_rt_sigreturn_v1(env); - } + return do_rt_sigreturn_v2(env); } From patchwork Tue Jul 6 23:49:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470606 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5549114ejx; Tue, 6 Jul 2021 16:59:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmA7zrhIfTFHmO4i3Wt8ZTzKNcFlB/Vugxq+kLGrWo44fUb+Q1EPOB9ESIMoRU1WwBR8JC X-Received: by 2002:a37:9a57:: with SMTP id c84mr19018918qke.291.1625615942360; Tue, 06 Jul 2021 16:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615942; cv=none; d=google.com; s=arc-20160816; b=emv81yuwAHlggYdQO6tyCI9wzrYANueOuWnEUe6BHaRGPO9oOwGobS1yXYgWk7ghLQ ll0rv5IBlpKxXSKkFfXoKxopU3hBjMkwVEPEpyq8Jn8/7fnCceM9+57fRZmnhATtR3p5 7Tnjrh7BSpg5NJPSGWNFBbcsGFuI3pw+L38Y8QCOtZ8/UBHCcWo47uu+JSa5HlSmVdH7 TR/VH4Qhc45rJbTCC5FHluylhD4Y8DILiX2rmBH/njrVZNSnzghwbfrH8Qvm4PLt3gP9 oKes9syhimYrosDNKLrj+EgEHSNi+1UfjhXoPYSyvGz0i3QXUQWHfeGh+ewskkV/k4uK hUkw== 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=cRDw+Y7ng9rnW9jKgJgd95eUlQ5ZwfKVhmGuJw/jHZk=; b=SlXInELv7WeT1vg8RFiRdheP+oomYo+HQVZgsypixK3vcYzfxEGPRJLKYvH+tqIMAi uMWFAC+RA/EslWSTvCrSfLQRSryBXIm3Q2mGeWQn9DmimiNdc7E8Jzgct5KcuZIcgce4 SDLXGJJ0+Ma9n/1AZlGbqAiu1uwZPPtzF3tp6gIJwUsax1ph6E5etqA61lLOE0B5304E Ww7rOqiTMeB1Qj+WDIwJdy36ptVepwEF2YRSanQ2hWrufOUM1gi2PJWS8C5JzWo+zY8a EMLnAZ0AOd8jlYQRM3qujjULJFtmLeFwBUNkgPlQENk/CZ+vXAMJS38r6DX/otMoghZs SAtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XZRjOKS9; 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 b13si12817639qka.324.2021.07.06.16.59.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:59:02 -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=XZRjOKS9; 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]:37802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uxx-0003lq-Kp for patch@linaro.org; Tue, 06 Jul 2021 19:59:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0up1-000160-So for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:47 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:46947) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uoy-0006dd-8j for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:47 -0400 Received: by mail-pl1-x636.google.com with SMTP id c15so38964pls.13 for ; Tue, 06 Jul 2021 16:49:43 -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=cRDw+Y7ng9rnW9jKgJgd95eUlQ5ZwfKVhmGuJw/jHZk=; b=XZRjOKS92Qw//rm7bXrkNM4ULqY56rWlSmaBRqjn66mejJicpbn0KOwSnzNRC4qOa/ f8K1QfkTuOtQALixIkYtu/Ggo+X/Jw39oDGu9dh2rtvteGWmqQgDV3FOtzGO5fQBiX/d ujqRcGw+QOdl1LuMX68y7CxZIeQ/jZoSjz2qpN59MtJeF5DWeGkSBEWHxjqZshFcNQGH DmgqLInh3ZGbNfnGA6BiO+GFtviViHFhuF+sGQI0+a4NOIwWggmOLf4ERyJ1+Nb01BDk XPfvHcJkwSPcrFqF3qo4k3Tx5JbCI8/67GhdyYanayP5y1MOjWlofqmsWElhMW7g4hA1 OWTA== 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=cRDw+Y7ng9rnW9jKgJgd95eUlQ5ZwfKVhmGuJw/jHZk=; b=mjXsHVImyALpyLPg58KjbPNA7fj7zv0aZippe9ZHjU4Z7oeW581yWhagI8RqNZQ0Oe YCgrpkBcnr0CRYjKINNOeKdkjeNFxuD+Ad0FiTUCH+ok52bRQgYey7zxSaoIfe2BlzKH aORowpU99fsgdYTPQ2m+2BZKapMOZydbyALzQGFTqZQFGW4CUy9JbbD3Tk4GsbX7bPAw xpAc5kuQBJw/rrAqVrCc0dfoou34SmUvlBAppWmG2BIt2v4LsJkVNAUAVj+NcJE9sSCE kZYXwSUTBFjUxJZdXUw9zjajDyiBY3xyW9BTmbHgrsRCPTVab11+PqX8vTxaqgIOPqdU m4Sw== X-Gm-Message-State: AOAM531joIVmfUErTxk23MBQcX4luAVzjJZ7+sJKxjMnNjA/DGxNumqq 2roJHPe4CM4FYEzjXwaWhnFEHoqHTIlQSw== X-Received: by 2002:a17:90a:2dce:: with SMTP id q14mr206529pjm.42.1625615382949; Tue, 06 Jul 2021 16:49:42 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 14/36] linux-user/arm: Drop "_v2" from symbols in signal.c Date: Tue, 6 Jul 2021 16:49:10 -0700 Message-Id: <20210706234932.356913-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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: qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Since we no longer support "v1", there's no need to distinguish "v2". Cc: qemu-arm@nongnu.org Signed-off-by: Richard Henderson --- linux-user/arm/signal.c | 155 +++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 90 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c index f8288ab51c..565a355fc4 100644 --- a/linux-user/arm/signal.c +++ b/linux-user/arm/signal.c @@ -45,7 +45,7 @@ struct target_sigcontext { abi_ulong fault_address; }; -struct target_ucontext_v2 { +struct target_ucontext { abi_ulong tuc_flags; abi_ulong tuc_link; target_stack_t tuc_stack; @@ -89,16 +89,16 @@ struct target_iwmmxt_sigframe { #define TARGET_VFP_MAGIC 0x56465001 #define TARGET_IWMMXT_MAGIC 0x12ef842a -struct sigframe_v2 +struct sigframe { - struct target_ucontext_v2 uc; + struct target_ucontext uc; abi_ulong retcode[4]; }; -struct rt_sigframe_v2 +struct rt_sigframe { struct target_siginfo info; - struct target_ucontext_v2 uc; + struct target_ucontext uc; abi_ulong retcode[4]; }; @@ -270,7 +270,7 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, return 0; } -static abi_ulong *setup_sigframe_v2_vfp(abi_ulong *regspace, CPUARMState *env) +static abi_ulong *setup_sigframe_vfp(abi_ulong *regspace, CPUARMState *env) { int i; struct target_vfp_sigframe *vfpframe; @@ -287,8 +287,7 @@ static abi_ulong *setup_sigframe_v2_vfp(abi_ulong *regspace, CPUARMState *env) return (abi_ulong*)(vfpframe+1); } -static abi_ulong *setup_sigframe_v2_iwmmxt(abi_ulong *regspace, - CPUARMState *env) +static abi_ulong *setup_sigframe_iwmmxt(abi_ulong *regspace, CPUARMState *env) { int i; struct target_iwmmxt_sigframe *iwmmxtframe; @@ -307,15 +306,15 @@ static abi_ulong *setup_sigframe_v2_iwmmxt(abi_ulong *regspace, return (abi_ulong*)(iwmmxtframe+1); } -static void setup_sigframe_v2(struct target_ucontext_v2 *uc, - target_sigset_t *set, CPUARMState *env) +static void setup_sigframe(struct target_ucontext *uc, + target_sigset_t *set, CPUARMState *env) { struct target_sigaltstack stack; int i; abi_ulong *regspace; /* Clear all the bits of the ucontext we don't use. */ - memset(uc, 0, offsetof(struct target_ucontext_v2, tuc_mcontext)); + memset(uc, 0, offsetof(struct target_ucontext, tuc_mcontext)); memset(&stack, 0, sizeof(stack)); target_save_altstack(&stack, env); @@ -325,10 +324,10 @@ static void setup_sigframe_v2(struct target_ucontext_v2 *uc, /* Save coprocessor signal frame. */ regspace = uc->tuc_regspace; if (cpu_isar_feature(aa32_vfp_simd, env_archcpu(env))) { - regspace = setup_sigframe_v2_vfp(regspace, env); + regspace = setup_sigframe_vfp(regspace, env); } if (arm_feature(env, ARM_FEATURE_IWMMXT)) { - regspace = setup_sigframe_v2_iwmmxt(regspace, env); + regspace = setup_sigframe_iwmmxt(regspace, env); } /* Write terminating magic word */ @@ -339,10 +338,10 @@ static void setup_sigframe_v2(struct target_ucontext_v2 *uc, } } -static void setup_frame_v2(int usig, struct target_sigaction *ka, - target_sigset_t *set, CPUARMState *regs) +void setup_frame(int usig, struct target_sigaction *ka, + target_sigset_t *set, CPUARMState *regs) { - struct sigframe_v2 *frame; + struct sigframe *frame; abi_ulong frame_addr = get_sigframe(ka, regs, sizeof(*frame)); trace_user_setup_frame(regs, frame_addr); @@ -350,10 +349,10 @@ static void setup_frame_v2(int usig, struct target_sigaction *ka, goto sigsegv; } - setup_sigframe_v2(&frame->uc, set, regs); + setup_sigframe(&frame->uc, set, regs); if (setup_return(regs, ka, frame->retcode, frame_addr, usig, - frame_addr + offsetof(struct sigframe_v2, retcode))) { + frame_addr + offsetof(struct sigframe, retcode))) { goto sigsegv; } @@ -364,51 +363,38 @@ sigsegv: force_sigsegv(usig); } -void setup_frame(int usig, struct target_sigaction *ka, - target_sigset_t *set, CPUARMState *regs) -{ - setup_frame_v2(usig, ka, set, regs); -} - -static void setup_rt_frame_v2(int usig, struct target_sigaction *ka, - target_siginfo_t *info, - target_sigset_t *set, CPUARMState *env) -{ - struct rt_sigframe_v2 *frame; - abi_ulong frame_addr = get_sigframe(ka, env, sizeof(*frame)); - abi_ulong info_addr, uc_addr; - - trace_user_setup_rt_frame(env, frame_addr); - if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { - goto sigsegv; - } - - info_addr = frame_addr + offsetof(struct rt_sigframe_v2, info); - uc_addr = frame_addr + offsetof(struct rt_sigframe_v2, uc); - tswap_siginfo(&frame->info, info); - - setup_sigframe_v2(&frame->uc, set, env); - - if (setup_return(env, ka, frame->retcode, frame_addr, usig, - frame_addr + offsetof(struct rt_sigframe_v2, retcode))) { - goto sigsegv; - } - - env->regs[1] = info_addr; - env->regs[2] = uc_addr; - - unlock_user_struct(frame, frame_addr, 1); - return; -sigsegv: - unlock_user_struct(frame, frame_addr, 1); - force_sigsegv(usig); -} - void setup_rt_frame(int usig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUARMState *env) { - setup_rt_frame_v2(usig, ka, info, set, env); + struct rt_sigframe *frame; + abi_ulong frame_addr = get_sigframe(ka, env, sizeof(*frame)); + abi_ulong info_addr, uc_addr; + + trace_user_setup_rt_frame(env, frame_addr); + if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { + goto sigsegv; + } + + info_addr = frame_addr + offsetof(struct rt_sigframe, info); + uc_addr = frame_addr + offsetof(struct rt_sigframe, uc); + tswap_siginfo(&frame->info, info); + + setup_sigframe(&frame->uc, set, env); + + if (setup_return(env, ka, frame->retcode, frame_addr, usig, + frame_addr + offsetof(struct rt_sigframe, retcode))) { + goto sigsegv; + } + + env->regs[1] = info_addr; + env->regs[2] = uc_addr; + + unlock_user_struct(frame, frame_addr, 1); + return; +sigsegv: + unlock_user_struct(frame, frame_addr, 1); + force_sigsegv(usig); } static int @@ -442,7 +428,7 @@ restore_sigcontext(CPUARMState *env, struct target_sigcontext *sc) return err; } -static abi_ulong *restore_sigframe_v2_vfp(CPUARMState *env, abi_ulong *regspace) +static abi_ulong *restore_sigframe_vfp(CPUARMState *env, abi_ulong *regspace) { int i; abi_ulong magic, sz; @@ -472,8 +458,8 @@ static abi_ulong *restore_sigframe_v2_vfp(CPUARMState *env, abi_ulong *regspace) return (abi_ulong*)(vfpframe + 1); } -static abi_ulong *restore_sigframe_v2_iwmmxt(CPUARMState *env, - abi_ulong *regspace) +static abi_ulong *restore_sigframe_iwmmxt(CPUARMState *env, + abi_ulong *regspace) { int i; abi_ulong magic, sz; @@ -497,9 +483,9 @@ static abi_ulong *restore_sigframe_v2_iwmmxt(CPUARMState *env, return (abi_ulong*)(iwmmxtframe + 1); } -static int do_sigframe_return_v2(CPUARMState *env, - target_ulong context_addr, - struct target_ucontext_v2 *uc) +static int do_sigframe_return(CPUARMState *env, + target_ulong context_addr, + struct target_ucontext *uc) { sigset_t host_set; abi_ulong *regspace; @@ -507,19 +493,20 @@ static int do_sigframe_return_v2(CPUARMState *env, target_to_host_sigset(&host_set, &uc->tuc_sigmask); set_sigmask(&host_set); - if (restore_sigcontext(env, &uc->tuc_mcontext)) + if (restore_sigcontext(env, &uc->tuc_mcontext)) { return 1; + } /* Restore coprocessor signal frame */ regspace = uc->tuc_regspace; if (cpu_isar_feature(aa32_vfp_simd, env_archcpu(env))) { - regspace = restore_sigframe_v2_vfp(env, regspace); + regspace = restore_sigframe_vfp(env, regspace); if (!regspace) { return 1; } } if (arm_feature(env, ARM_FEATURE_IWMMXT)) { - regspace = restore_sigframe_v2_iwmmxt(env, regspace); + regspace = restore_sigframe_iwmmxt(env, regspace); if (!regspace) { return 1; } @@ -536,10 +523,10 @@ static int do_sigframe_return_v2(CPUARMState *env, return 0; } -static long do_sigreturn_v2(CPUARMState *env) +long do_sigreturn(CPUARMState *env) { abi_ulong frame_addr; - struct sigframe_v2 *frame = NULL; + struct sigframe *frame = NULL; /* * Since we stacked the signal on a 64-bit boundary, @@ -556,10 +543,9 @@ static long do_sigreturn_v2(CPUARMState *env) goto badframe; } - if (do_sigframe_return_v2(env, - frame_addr - + offsetof(struct sigframe_v2, uc), - &frame->uc)) { + if (do_sigframe_return(env, + frame_addr + offsetof(struct sigframe, uc), + &frame->uc)) { goto badframe; } @@ -572,15 +558,10 @@ badframe: return -TARGET_QEMU_ESIGRETURN; } -long do_sigreturn(CPUARMState *env) -{ - return do_sigreturn_v2(env); -} - -static long do_rt_sigreturn_v2(CPUARMState *env) +long do_rt_sigreturn(CPUARMState *env) { abi_ulong frame_addr; - struct rt_sigframe_v2 *frame = NULL; + struct rt_sigframe *frame = NULL; /* * Since we stacked the signal on a 64-bit boundary, @@ -597,10 +578,9 @@ static long do_rt_sigreturn_v2(CPUARMState *env) goto badframe; } - if (do_sigframe_return_v2(env, - frame_addr - + offsetof(struct rt_sigframe_v2, uc), - &frame->uc)) { + if (do_sigframe_return(env, + frame_addr + offsetof(struct rt_sigframe, uc), + &frame->uc)) { goto badframe; } @@ -612,8 +592,3 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } - -long do_rt_sigreturn(CPUARMState *env) -{ - return do_rt_sigreturn_v2(env); -} From patchwork Tue Jul 6 23:49:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470609 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5550514ejx; Tue, 6 Jul 2021 17:01:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbh4gUrgq7p0xzPn6ru8oVvn379KKGZ76QiLoJ+UwqspzN6SoQjMFDtcXak0EWq29IF7e4 X-Received: by 2002:ab0:6797:: with SMTP id v23mr19079423uar.71.1625616072488; Tue, 06 Jul 2021 17:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616072; cv=none; d=google.com; s=arc-20160816; b=x1ijFLZgM1YPCCHHr6T6OFfHe6NZbB9brKuD9/KtOGAXPz47txKaQ9Q3ZzCY21gNiS gDriCTwF6T2IBO5eJtb+svDftexedvs4iWG0ILASJupTGv5+TwBNq7JguwvRg92yKICK ci/jkQEEZG8gLoduHenXlHbI8N8eVHgA2ohWK0QCpOjA3WM/YPRGqU5tztA96gTRsLU5 RrbUOG3RhrLHZ7R7c25wRpf8CgN4uYXmYtXdqW0DVsQypbKRr8otd/F3U70eckmBXR9L hbClY3oij783twqhYUJ13MiQysraJYToxxExR8OlNyh8e7mMw4IKYtVtn5DXfYnPRHy6 /ayw== 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=uYCxAUoRWyRn/9euH4vCsN2ms/pTKei5OwvPABaSm8o=; b=dPbl85SyP2TdwZr9q8yM5P7Tp96NxHnS2IuR5/vXTYYHD/4YKYrJbQXtFrW0XP9He3 TWtRTgmb1ePxRSJLctzpLyb/ldNSgcBtbHCmqhodKkoRUgQEzGmlGUcgXmfj3NxaX3Uw WnuX8dZs9wT99DSX/123Tgy96TQenebAXzmzZClK2+ILTcDlWwxNb00by8ABUBX1mUzu UwOIJ6i4pS0u21/66McTLySBXMN9f5FVSQeFJR09tGviaPP40XL50+f3TtVVRwZmg13V Sv5Z6gr+M29CCVB7OwmWFFxsRjwBj8IWCT/8qtWU9WCCpikv6LEVhoLEi34Sgq+6M6+J p3rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Q8w551VA; 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 t12si14679899vsh.63.2021.07.06.17.01.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:01:12 -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=Q8w551VA; 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]:46426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v03-000176-RV for patch@linaro.org; Tue, 06 Jul 2021 20:01:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0up6-0001Kb-CF for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:52 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:41684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uoz-0006dx-DD for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:52 -0400 Received: by mail-pj1-x102d.google.com with SMTP id oj10-20020a17090b4d8ab0290172f77377ebso507980pjb.0 for ; Tue, 06 Jul 2021 16:49:44 -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=uYCxAUoRWyRn/9euH4vCsN2ms/pTKei5OwvPABaSm8o=; b=Q8w551VA/ZasYQxd8/aaaxJx19ojVZdG2AMt5TU2qrs0u2VyYWY2q3hLbs1454pO5C Ut1NW76rbF2EKQ8FYJM2pCf4725Uz20UoUM3wOXS9cVoTjcBzDjV72rXYvR3mvkeafGH e0EOAU57YP0oDYvbu6SxZPpkDb+7lxXOfMGUOnmiO0/qllZYm6JIayWnoA+Ac8VBK8LG pXPIeGIV0QANw2OuIHAnMPsysewTzqDQxeRwLp6faMM64PYgNW6MJ6zmZD6RvcMpAxOt qV7aRcCt86+So0LqCl+MEYeEruv+QBDwVVSruu2FaTltEAjusxcO5H5FlZrtNsX7/8WB LomA== 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=uYCxAUoRWyRn/9euH4vCsN2ms/pTKei5OwvPABaSm8o=; b=ML8FLkpinhfKRkQMoBAOg3od5ll00Q7EkB/OO/o8CpfLgH+EarsaNfhRD9u0Luz5Va RmLbRIlG25EorFXQROf19UNHfzmBf7Zfao7S5Mpry4bjaoO3fDKrBk+KLNpttU9ecnXs 4xKSfxDNtNJ8QBnhWeL6PErSvvnycQgqCnU+0q9DKW3aUQtB+rH/tzw6tkynOqbaATTQ IBVs2r32rf/BUTTVr8yF+re3vUdgHOSHjZjaFbDkEo3WphzODG9mU0FgERM7jdc3WI1C IvaNEUajWGsmKWY+06GBoq62RfkfCXWkB+q93A+A+h22y+Ex/1hHybyuvBZvZ2Npt7lt GoKg== X-Gm-Message-State: AOAM531iSiQN/F0QOcK2f2RDmJwp8OyC6qUbnHj0PRT3vyuFp2MOW2N6 RO13LwWtazrK7bJKSmplSCcqGdCHv+2gyA== X-Received: by 2002:a17:902:e0d4:b029:129:acad:4552 with SMTP id e20-20020a170902e0d4b0290129acad4552mr4661349pla.55.1625615383487; Tue, 06 Jul 2021 16:49:43 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 15/36] target/arm: Add isar_feature_aa32_a32 Date: Tue, 6 Jul 2021 16:49:11 -0700 Message-Id: <20210706234932.356913-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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=unavailable 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: qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Add a probe for whether A32 mode is supported. Fill in the field for the pre-v5 cpus. Cc: qemu-arm@nongnu.org Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 +++++ target/arm/cpu_tcg.c | 7 +++++++ 2 files changed, 12 insertions(+) -- 2.25.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index be9a4dceae..33f7ce9bc5 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3802,6 +3802,11 @@ static inline bool isar_feature_aa32_i8mm(const ARMISARegisters *id) return FIELD_EX32(id->id_isar6, ID_ISAR6, I8MM) != 0; } +static inline bool isar_feature_aa32_a32(const ARMISARegisters *id) +{ + return FIELD_EX32(id->id_pfr0, ID_PFR0, STATE0) != 0; +} + static inline bool isar_feature_aa32_ras(const ARMISARegisters *id) { return FIELD_EX32(id->id_pfr0, ID_PFR0, RAS) != 0; diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c index d2d97115ea..980f62f35d 100644 --- a/target/arm/cpu_tcg.c +++ b/target/arm/cpu_tcg.c @@ -73,6 +73,8 @@ static void arm926_initfn(Object *obj) cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1); cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSP, 1); cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPDP, 1); + /* Similarly, we need to set STATE0 for A32 support. */ + cpu->isar.id_pfr0 = FIELD_DP32(cpu->isar.id_pfr0, ID_PFR0, STATE0, 1); } static void arm946_initfn(Object *obj) @@ -86,6 +88,9 @@ static void arm946_initfn(Object *obj) cpu->midr = 0x41059461; cpu->ctr = 0x0f004006; cpu->reset_sctlr = 0x00000078; + + /* We need to set STATE0 for A32 support. */ + cpu->isar.id_pfr0 = FIELD_DP32(cpu->isar.id_pfr0, ID_PFR0, STATE0, 1); } static void arm1026_initfn(Object *obj) @@ -115,6 +120,8 @@ static void arm1026_initfn(Object *obj) cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1); cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSP, 1); cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPDP, 1); + /* Similarly, we need to set STATE0 for A32 support. */ + cpu->isar.id_pfr0 = FIELD_DP32(cpu->isar.id_pfr0, ID_PFR0, STATE0, 1); { /* The 1026 had an IFAR at c6,c0,0,1 rather than the ARMv6 c6,c0,0,2 */ From patchwork Tue Jul 6 23:49:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470586 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5547119ejx; Tue, 6 Jul 2021 16:55:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlnhwh7AqvqTgiLvTpsikORKgQTTepYSMHQ+2VsCV4XrcqHiHSu/XXinD9uLjXN8FutoR+ X-Received: by 2002:a05:620a:2229:: with SMTP id n9mr22314234qkh.41.1625615710228; Tue, 06 Jul 2021 16:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615710; cv=none; d=google.com; s=arc-20160816; b=Qmdfadz5klgdoD+LpcR2pm0gUKwNunDlw0UVhh/7ChzwS59CCyVdeo+xsODasg3Ul2 +X+PCYtTyPTZ7WPHrc5bdIBY07wEKUuu3DcbiYZ7KAHNknnnDNh34abiJQm/f3ZdHDQy oTB5n7uJV1GRUoK7xkQzssYASSIX8KE6tWD5DE+3haBvkuMxZsqkKU/vLA6TwvpGeOZO C5Fb6+mMlX17zmrV83YHXm8ocqj1Dj5C6/HC88VyDsPnLgYGoUoO1qQzkByXLhkV0d0h OJVhfvynKRUCZ6kDSZte4MTFXxoEehO3Tl0G7qAEvqdEQZdX4SzzKCB+OYKNLmovvzOx fLMQ== 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=JDT8q96D/T2tu/PjTc+pzQSWIjDUETgQ0u9mYrVmj2Q=; b=QwKgnEIx/KOG38v9Bq9ZZOSB5ROI5jHBb+7B71nvDdh5al1nEXyyufXkR7o0RLaDlT CONpp8Hx551G1GLaMoQzdb3pDDwPCMG0oXGvwpoJPskLeI6a7H4BN+LRXKtO2tAYyT9K UQhEpCOyr44FZ24dySjO7HYFJZgdifOAwPglxLpZ5s1DJa0NBTnE5/9b7X3+tJyfZ3RP rE2JSw3BZS10HJxOUM4qN0xZ2JUPbwB0qKAj0VN0IMAeBTKqZVkuj3OFrEq1FMwGm51p xxqrv5EaiLv56dZExc/08b+EMIDuN22WMId/EArL50B1OnRP2hw6pYSVjXKEKiroNfnO 5QAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jBLXfhHk; 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 a1si12552129qvm.151.2021.07.06.16.55.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:55:10 -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=jBLXfhHk; 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]:55086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uuD-0004zT-G8 for patch@linaro.org; Tue, 06 Jul 2021 19:55:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0up7-0001PP-Uk for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:53 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:42850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up0-0006eC-N5 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:53 -0400 Received: by mail-pj1-x102f.google.com with SMTP id p17-20020a17090b0111b02901723ab8d11fso485818pjz.1 for ; Tue, 06 Jul 2021 16:49:45 -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=JDT8q96D/T2tu/PjTc+pzQSWIjDUETgQ0u9mYrVmj2Q=; b=jBLXfhHkTlTcbZotQXaon5VYNaLvdrNgvF28GUppb/xKo6dqylXQHPJrCUf582mRxT j3i06GG5jwWoFpEtCHnNV3IeRIALUjhpAUtPEdWDP0sEHVyxIZCGVbXH1ldu8XoV3qWi 7SCPPGGqXNUAGG53eh82TVvkMyZf98NAuR6yrclk1HvUuKUwXij1p6obPFH5Vzv1sLY/ PpHcsLShi7Mf7S9uwxAyC8AAN/MJjCX5gq7b7kUqhMXQUnx6MzUHB9UGlsp/dMazTDk4 n6X8voTn25ei6dhk2emXNJoPRQIWzE1muQIcsZirsvt06LifPJuY7vJ98DKM1hTG1Www n+kA== 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=JDT8q96D/T2tu/PjTc+pzQSWIjDUETgQ0u9mYrVmj2Q=; b=K12pvQLKoUBPOI9IHfe8kWmbRdYmSNNSPMC2TgWESFV0qXtmK53LozulvuT7jDr6g/ ctq27RiTEQ58UDNgxM03RhXHOiwnL5mMH16CQh4fsHIAzKOr6xl8toz6t5HB5eRzV7P7 o/QEbY+HICQUT/3KeXoXmoxO34EOA0cDrm/pfxy8dTa4tj6WzwS+fZeBcS+d42d5BQ/J A9ln3mP1pO2JSNmj9StNs/Rj08o1XPq1qaCi5VV6IQliWzNvTpun5lFEMppV1IbxNmtU jAUHOwYpLvo6VODZVAnO8ptKO93FrlGRZmTMCImZcWqBennbYaLEP/YLc09tz0aP4Jla RzQw== X-Gm-Message-State: AOAM532I/1O2y0aaemZeufexkyrG6TkofHfNHtuZ3ScnprQxeLdhRpL8 engorfoUbRbSTWuHLQdkIeVw0yergEb4Ag== X-Received: by 2002:a17:902:dad0:b029:128:b6d1:3e44 with SMTP id q16-20020a170902dad0b0290128b6d13e44mr19049585plx.4.1625615384189; Tue, 06 Jul 2021 16:49:44 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 16/36] linux-user/arm: Add vdso and use it for rt_sigreturn Date: Tue, 6 Jul 2021 16:49:12 -0700 Message-Id: <20210706234932.356913-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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=unavailable 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: qemu-arm@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Building of the vdsos are not actually wired up to anything, since we require a cross-compiler. Just check in the files for now. The thumb vdso will only be used for m-profile, as all of our a-profile cpus support arm mode. Cc: qemu-arm@nongnu.org Signed-off-by: Richard Henderson --- linux-user/arm/signal.c | 83 +++----------- linux-user/elfload.c | 24 ++++ linux-user/arm/Makefile.vdso | 17 +++ linux-user/arm/meson.build | 18 +++ linux-user/arm/vdso-arm-be.so | Bin 0 -> 5648 bytes linux-user/arm/vdso-arm-le.so | Bin 0 -> 5648 bytes linux-user/arm/vdso-thm-be.so | Bin 0 -> 5620 bytes linux-user/arm/vdso-thm-le.so | Bin 0 -> 5620 bytes linux-user/arm/vdso.S | 209 ++++++++++++++++++++++++++++++++++ linux-user/arm/vdso.ld | 74 ++++++++++++ 10 files changed, 359 insertions(+), 66 deletions(-) create mode 100644 linux-user/arm/Makefile.vdso create mode 100755 linux-user/arm/vdso-arm-be.so create mode 100755 linux-user/arm/vdso-arm-le.so create mode 100755 linux-user/arm/vdso-thm-be.so create mode 100755 linux-user/arm/vdso-thm-le.so create mode 100644 linux-user/arm/vdso.S create mode 100644 linux-user/arm/vdso.ld -- 2.25.1 diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c index 565a355fc4..8edc1b1373 100644 --- a/linux-user/arm/signal.c +++ b/linux-user/arm/signal.c @@ -102,40 +102,6 @@ struct rt_sigframe abi_ulong retcode[4]; }; -/* - * For ARM syscalls, we encode the syscall number into the instruction. - */ -#define SWI_SYS_SIGRETURN (0xef000000|(TARGET_NR_sigreturn + ARM_SYSCALL_BASE)) -#define SWI_SYS_RT_SIGRETURN (0xef000000|(TARGET_NR_rt_sigreturn + ARM_SYSCALL_BASE)) - -/* - * For Thumb syscalls, we pass the syscall number via r7. We therefore - * need two 16-bit instructions. - */ -#define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_sigreturn)) -#define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_rt_sigreturn)) - -static const abi_ulong retcodes[4] = { - SWI_SYS_SIGRETURN, SWI_THUMB_SIGRETURN, - SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN -}; - -/* - * Stub needed to make sure the FD register (r9) contains the right - * value. - */ -static const unsigned long sigreturn_fdpic_codes[3] = { - 0xe59fc004, /* ldr r12, [pc, #4] to read function descriptor */ - 0xe59c9004, /* ldr r9, [r12, #4] to setup GOT */ - 0xe59cf000 /* ldr pc, [r12] to jump into restorer */ -}; - -static const unsigned long sigreturn_fdpic_thumb_codes[3] = { - 0xc008f8df, /* ldr r12, [pc, #8] to read function descriptor */ - 0x9004f8dc, /* ldr r9, [r12, #4] to setup GOT */ - 0xf000f8dc /* ldr pc, [r12] to jump into restorer */ -}; - static inline int valid_user_regs(CPUARMState *regs) { return 1; @@ -188,9 +154,10 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, abi_ulong handler = 0; abi_ulong handler_fdpic_GOT = 0; abi_ulong retcode; - - int thumb; - int is_fdpic = info_is_fdpic(((TaskState *)thread_cpu->opaque)->info); + bool thumb; + bool is_fdpic = info_is_fdpic(((TaskState *)thread_cpu->opaque)->info); + uint32_t cpsr; + int idx; if (is_fdpic) { /* In FDPIC mode, ka->_sa_handler points to a function @@ -208,7 +175,7 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, thumb = handler & 1; - uint32_t cpsr = cpsr_read(env); + cpsr = cpsr_read(env); cpsr &= ~CPSR_IT; if (thumb) { @@ -222,39 +189,23 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, cpsr &= ~CPSR_E; } + /* Our vdso default_sigreturn label is a table of entry points. */ + idx = is_fdpic * 2 + ((ka->sa_flags & TARGET_SA_SIGINFO) != 0); + retcode = default_sigreturn + idx * 16; + + /* + * Put the sigreturn code on the stack no matter which return + * mechanism we use in order to remain ABI compliant. + */ + memcpy(rc, g2h_untagged(retcode & ~1), 16); + if (ka->sa_flags & TARGET_SA_RESTORER) { if (is_fdpic) { - /* For FDPIC we ensure that the restorer is called with a - * correct r9 value. For that we need to write code on - * the stack that sets r9 and jumps back to restorer - * value. - */ - if (thumb) { - __put_user(sigreturn_fdpic_thumb_codes[0], rc); - __put_user(sigreturn_fdpic_thumb_codes[1], rc + 1); - __put_user(sigreturn_fdpic_thumb_codes[2], rc + 2); - __put_user((abi_ulong)ka->sa_restorer, rc + 3); - } else { - __put_user(sigreturn_fdpic_codes[0], rc); - __put_user(sigreturn_fdpic_codes[1], rc + 1); - __put_user(sigreturn_fdpic_codes[2], rc + 2); - __put_user((abi_ulong)ka->sa_restorer, rc + 3); - } - - retcode = rc_addr + thumb; + /* Place the function descriptor in slot 3. */ + __put_user((abi_ulong)ka->sa_restorer, rc + 3); } else { retcode = ka->sa_restorer; } - } else { - unsigned int idx = thumb; - - if (ka->sa_flags & TARGET_SA_SIGINFO) { - idx += 2; - } - - __put_user(retcodes[idx], rc); - - retcode = rc_addr + thumb; } env->regs[0] = usig; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8088828f5f..40cc79b129 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -517,6 +517,30 @@ static const char *get_elf_platform(void) #undef END } +#ifdef TARGET_WORDS_BIGENDIAN +# include "vdso-arm-be.c.inc" +# include "vdso-thm-be.c.inc" +#else +# include "vdso-arm-le.c.inc" +# include "vdso-thm-le.c.inc" +#endif + +static const VdsoImageInfo *vdso_image_info(void) +{ + ARMCPU *cpu = ARM_CPU(thread_cpu); + + /* + * The only cpus we support that do *not* have arm mode are m-profile. + * It's not really possible to run Linux on these, but this config is + * useful for testing gcc. In any case, choose the vdso image that + * will work for the target cpu. + */ + return (cpu_isar_feature(aa32_a32, cpu) + ? &vdso_arm_image_info + : &vdso_thm_image_info); +} +#define vdso_image_info vdso_image_info + #else /* 64 bit ARM definitions */ #define ELF_START_MMAP 0x80000000 diff --git a/linux-user/arm/Makefile.vdso b/linux-user/arm/Makefile.vdso new file mode 100644 index 0000000000..89da6f91ae --- /dev/null +++ b/linux-user/arm/Makefile.vdso @@ -0,0 +1,17 @@ +CROSS_CC ?= arm-linux-gnueabihf-gcc +LDFLAGS := -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=sysv -Wl,--build-id=sha1 + +all: vdso-arm-le.so vdso-arm-be.so vdso-thm-le.so vdso-thm-be.so + +vdso-arm-le.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mlittle-endian -marm vdso.S -o $@ + +vdso-arm-be.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mbig-endian -marm vdso.S -o $@ + +vdso-thm-le.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mlittle-endian -mthumb vdso.S -o $@ + +vdso-thm-be.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mbig-endian -mthumb vdso.S -o $@ diff --git a/linux-user/arm/meson.build b/linux-user/arm/meson.build index 5a93c925cf..66072411d6 100644 --- a/linux-user/arm/meson.build +++ b/linux-user/arm/meson.build @@ -5,3 +5,21 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +# ??? There does not seem to be a way to do +# when: ['TARGET_ARM', !'TARGET_WORDS_BIGENDIAN'] +# so we'd need to add TARGET_WORDS_LITTLEENDIAN. +# In the meantime, build both files for arm and armeb. + +gen = [ + gen_vdso.process('vdso-arm-be.so', + extra_args: ['-s', 'sigreturn_codes', '-p', 'vdso_arm']), + gen_vdso.process('vdso-arm-le.so', + extra_args: ['-s', 'sigreturn_codes', '-p', 'vdso_arm']), + gen_vdso.process('vdso-thm-be.so', + extra_args: ['-s', 'sigreturn_codes', '-p', 'vdso_thm']), + gen_vdso.process('vdso-thm-le.so', + extra_args: ['-s', 'sigreturn_codes', '-p', 'vdso_thm']), +] + +linux_user_ss.add(when: 'TARGET_ARM', if_true: gen) diff --git a/linux-user/arm/vdso-arm-be.so b/linux-user/arm/vdso-arm-be.so new file mode 100755 index 0000000000000000000000000000000000000000..197a8cc1b5303c0b5844272f2279eb79f9ddb724 GIT binary patch literal 5648 zcmeHL%}*Ow5T9LRV+a^0p-m+?xGD!!g{37ZiqtB?1PqZ3iTIF`(_(A~y9FEBOMr+d z?k8!Irbrx`OC?fq=q0^2Qd=d59{NZ0kSdClR#iVF)Ke<@`@Mb7n3PM^QzZ`>&-=~H z&g`3gFVf7l;bg+HEvZsKy0L~LN>#te(T!lm<|-y3*rL(~eaN@buJ|D&xj}PHKxm}l zxX*abx9IrHq4I2CK@Ms=5?U|qv8=#GR`E05lk+0>4|^;_u#ruE%AFeS!kS!bZwC&H zj8Ds_r)S*W+>M{_de@q}J0CpydS~P+Y!UFZ|BUqvGKhSv4fbyFU7Nv0@F8%txVsA< zdmHjEU>ovxh&x#SSIU|Ihh_H%8pSuT3zE``(F9LIK2J2cI%(_-7fEB+b z>q5dFtHdvb?;!LMaox+Aa?wrC7t?RMb6L;JFJuo?p6vgJx|A&&oqn=-DU({2`Fvq% zrH64H{Ci!JXUC^6xP8t^mC;6a|Ifmyz+daH5AMRky>){5ZPZDHmlgPO=}#cqNUCO5 zN8k;t2f&RYt^EEMAWuOqLM9=vL(V{MK|&|^X05jnGz&m4Q0vNs*lQ81qooxp zl?Qcf`A)3|BjI)XHtWUwuR;It0R1TR-yEQyf&M=9QQ3>r4=l(ziKJ~zI#Y?h)AnxU zz1H_zJ~;GY^Lo?u@JEd|LN|lA8a@u(wm)HV5cA_~w5&jON+R+|>tn#*L%#;uF40Kv z>P|2eiZ(S;zS6)WATjVS@R^5<`aU7;6EZ$9)u~>AdIjngs8^s~fqDh%6{uIBUV(ZA z{;w6N4D|fexVZJ$T3dhIXl?vfseJpCx=pRytkH$FE?lDy|xD31u%r*HQ z@Vy$m)A!kvu)X>8=x(pFdnfkeI0|_zl}*j&(ea@P3-(V*$PROT5baQj236br-WHgB zD@gU}wEI1*Sm^H*(EYCJ>uJ<|uj=oKRYPR@cVP67Bzv2`z~~Q2oIxnuM2S^Q{ra;3 zETe?<=Zv6Az%2mPJvI1!{bAz|8~xGC1ymo1HD?V~(*DN~0zD`LskuN5&z}bzz~=cp z`cVJjRP=wafe6U#6)~-*c~035O*Yb zZZMv7&m|I*!&B~5d@woe*31O-1Y+L=;rXdV&7@)9q~d^~gc@LoQ(j&0QnQd=$(K2^ zDipn}IGNQ#Y9XIi3;05&yp%Y(R5|DCyplL`g(c^5wp7j+3;TeZ5ht5-FO^aYSvQw~ zr$OR)*%eQm_{5l#^1M=hcF99o{tb1&ndg#co%evu8HXW##^q%wc%E_W%uG$q()1Zu zvmc)4SHV0th{t=Q?#>J_{diUxj~~2GW5&aIQfG?i*%1B6r@*{djQ7lEIS!2H6dAwM zS_ePgKXnH=S2JYpNdhyqT`1{y$7gkqOg!jSEhfzj4shFN^)B28eVCUt3ubJ_!#!4a zWrzk%#%~c=`vqcneX#ZXe)-51F#V8+Wg@GYCM8KJAS(!H-kItR{HS{jNizG@IejJk ozJO^9h;zvozn+a literal 0 HcmV?d00001 diff --git a/linux-user/arm/vdso-arm-le.so b/linux-user/arm/vdso-arm-le.so new file mode 100755 index 0000000000000000000000000000000000000000..94c757a7e283fecc45847a7942c2943b989a1163 GIT binary patch literal 5648 zcmeHL%}-oa6hChs3_}Y8{ZL78fsqAi;8Bq@O>7Lq$CR3ZHhdWB=JA-B!bF&v%sdJ- z81a*8Yn_CcxKYtGjSFkyN*8VH!bSfGO*EuQO^jkBu4=~L@4k2G!?G}OW%ADOn{&^{ zJ?GxTdy|~=>QE|a7=~yvr9+g|EYb^Qa28-JB0B7OZI*^lhs6ajdUH}dPyvBoSwQwEw zzrcC^ZSW7d_>Ytg>^~&GR}+v=At7@fM)of74hXyt<;TH~24oynIcqy>s)_gKeOMQg zSATC!Hy)opifsF0rd+Vo^M&-w_H5R5a|>D7PkEyE5p^kB);fP@;X=k)k@;MHak-0e zE&M$rsWYRKQ+AJaf*B*bA3ibseERLLjl9Q`0RJ~6@0^DGx%j0?8%fv9Xf>bfgIou+ zH;PPwp9C+0r@$|RPlIoQ7s0o|uY$)AbQ8Q29HmrbTpE+eYTRgTXjHXsf%dxwukO+x zkF7_p8O(nixU-Lb82VfL=%=Co26~mpkJAes2|34+w24Wl*P35zdOiL|b|8*mp`)%ly_wXf{dMx)L3b>vUi zM3v7k@R`?VQ9e=MC#rm44k@faSb?wtVFkhpgcS%Y5LO_pKv;qQaRt`;x_+)JZf+T? z>sxh3<+ru9+xMy4@O2vjUCh_T0=iM?M#bBQuIZ;G$V-s9CT>E$8IX5+KDrl+Y}`Lm z?N)a8*}Zb&2^7=GIx{&j(1Ky`Fd@+hJF-V<$5)xE3-sm%RGF%C_4;&A_PW?@KZ@yh zyzJ{eyVv=$zxQNsQla~IQ+1Fc?C(8$OmWU1Jh@)+HosXm)pP(Vzj-v(lt8(tFH;)) z6MMQE^!10h)XgUR*~|6rHs72!JS6(FOuCmhAh$t2hy8uv5$rz>uFoe@F9VSE{po)m zvL?CrYC+7~*?Jg9%)9Ha1r;4SQtb(*V(w-4}@cd|E z!7kB{I0^8rVm!WQL?_nVN78=JV@)0X`2G=`t7*bEMM->D{n;Ad zOM-cIJcugBIJlm{@qHzD7T$wC%uAX97@NA_91)@-?N@}P{o0U>XwZj(P5WK){Zw69 zD4+tSi7L_>fDlElNfj74OVXr6>zrEuIs7)Ew POVF*CA@cg6s1SiroF+~Rv4fmOY7x?lW5320jUCx9 zO;WYOK%s?}QmH~JDI2DE8Z{Kd}gj^6Oq&Mk! z_BT5_^LBQ((#*>v;~6Vt$vTDQQH-HTQq?bVmltV`+H+>0@} zb^dPP@MvyIzRgXQzqqvP+KcbT2KEf)7k|3-!YRxpz*GJj>o#Nr@t7Oz-MR?b39f;+ zfs?hhHQ0n!ApZgmLH-JH8RP#-u5qwk)_%h{jc^Y_#&-Cz`+)BO?$r2RV1ARq%r&#F zG4r}kVT^c|%nJ#7TqmxkFS=aL_bMBVP{r&$?*WHHE>6Nvk zrNXitt5g@3`smljzr8YkFgJDB*=O%p5krXX|5>;d_>2GYjP?9t5|G#CiUQA#F(9wfK{eXCa3muR=Zxi8G6r;WP$$5)${;zo6EM zyo63Bte&noR4NYg*!300osv$(&V(*7UyQ#8`p>q|k3oNJ3;i_oSD=rz_~{20#GFLX zZU&uhCSU1(HSt>fbl2)RKMj9*$Xzm;_(AJa zz+Xd;{lg}ih@4uDM5D=$cFKp_cm*T{{uws-PV8CPM72%S*kCH4AOk@Lf(!&12r>|4 zAjm+Ffgl4x2L7)ZXns2Qd;3oLzImOaOL{c1dV0~<6By5_NyUEzDF<(V@*T>$!FmJ+(x}YVU2maYb&9o;D*4e}aYn|ROg^0*amI%8;*5?@45i1NiA-j4 zx?mr7>y1jSx&b&PvE8zBv|gBVopK4528r#tOP<*2 zeAX^_UcEB2;2|ylhI(Mkd&#@bcR*$z!;rq?@(>if&$xD`Z>IWX`i`sq4)610V4g4h z@!hDmGYw2To-_UNLhsX<{&1hvo#K5qL_0EjD12A+ciU%S&jjlf8M|k+4t9Kh>J74Y zX2`sg4EknkP}1(Q&*~i+f6%L3OqxC$;EK=cTeuI}FfM5ZOyBf}cdXvZFefw_yLn)3 z7f$(a+}gZfE;*s?5Qk|ZtG*>ANhu(kaA>}nYCz#x8Z!IUF^xKT9-na)h`mR?OMV}H d@@=>H+rb=v4mM=`;s2KncDH~p8Y4($_c!UoWV`?X literal 0 HcmV?d00001 diff --git a/linux-user/arm/vdso-thm-le.so b/linux-user/arm/vdso-thm-le.so new file mode 100755 index 0000000000000000000000000000000000000000..241fc569a4752fbe5642971f8dff72c3625799d1 GIT binary patch literal 5620 zcmeHL-%lJ>6h6DdE>M)T_@fWiXyS|dq&_wF!I;K>L5)p}i4ToIB|cU0`|h1f2js!TCzCnw&3Dha z=bn4#%*-a|yf8GHi9{k|#FAa2w3J96jNU!CL?zZIT@uG!N;<%Lj`PF~A5CE5ZZs&6 z9vBI(bEZ;s(}lm0wrW&>zBvE#Pg~y%)S4I?qG>K5$z=$5AB`(3w*syno&g z^Fq=2*JHZz`1DcYI428@s*^ua%|GwVx}H}myRw;af8RgMb+=(`{>tj{LT*t`lqz!z zy^L$)f3J)l9-BJq?6dcC$LQK0-x&VA_vJ6`d~Oc_d^Qw)&WQXm_ldvHrB=7IY^4NM^3gJ2m>-lDw=xCtDEoj#IE#?Gw7;_*~# zGx?FGxbnG;sS)_7dsaSi-zTnoxHOb717QZj41^g7GZ1DV%s`ldFau!*{=XSm`mF!A z<{k3G(shpB^he_>XXmwT>@o6<%%{K05-|_mjL9Ew(67In_~z|QYS{REzd=vmk6h*4 z+)PQ8r4oChH!Jb>=4|Wc#qx@uT1!=Wx+g%BrK(e1i)&q1s>>{RAeLX%vUbVts1`HY@nMLjN65O}!q0-UWRx*7t*>Sic9%9*CA!IfQ|^fBGLYQ(*QE^59_a zU>&f%K>|p2*6xMYKHZ~ao z-Gp`Bh)o&~s!1VsW3lYzX24!ubJ2_{RnHZ>uvp2JOL;YbFF5Dr#4hF_+HVj5%m@iSpOzMlJho$>fS5oimn z3H^uz0KY26<99~%V9a$C<985a+UUpck6`c22$m_y;JWJf&-h&u+}Ff|s$xunO`nb5 zE5WnyKIp@JDKh|L(-!O%LRDh?YS4^d7d9gj=1`b3ey4mtl~*PT;94UzQI-INSevS0 zg3r>332pW?_Dk@)1|xfq+X3#&nEd52IlxeQwuyYffiET=e_w)rKf>>daRM8^zX6tP BWsm>> literal 0 HcmV?d00001 diff --git a/linux-user/arm/vdso.S b/linux-user/arm/vdso.S new file mode 100644 index 0000000000..1831b29efc --- /dev/null +++ b/linux-user/arm/vdso.S @@ -0,0 +1,209 @@ +/* + * arm linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + + .text + .eabi_attribute Tag_FP_arch, 0 + +#ifdef __thumb__ + .thumb + .arch armv7-m + .eabi_attribute Tag_ARM_ISA_use, 0 + .eabi_attribute Tag_CPU_arch, 13 /* TAG_CPU_ARCH_V7_M */ + +.macro raw_syscall n + .ifne \n < 0x100 + mov r7, #\n + .else + ldr r7, =\n + .endif + swi #0 +.endm + +.macro fdpic_thunk ofs + ldr r3, [sp, #\ofs] + ldmia r2, {r2, r3} + mov r9, r3 + bx r2 +.endm + +#else + .arm + .arch armv4t + .eabi_attribute Tag_THUMB_ISA_use, 0 + +.macro raw_syscall n + .ifne \n < 0x100 + mov r7, #\n + .else + mov r7, #(\n & 0xff) + orr r7, r7, #(\n & 0xff00) + .endif + svc #(\n | __NR_OABI_SYSCALL_BASE) +.endm + +.macro fdpic_thunk ofs + ldr r3, [sp, #\ofs] + ldmia r3, {r3, r9} + bx r3 +.endm + +#endif + +.macro FUNC name + .globl \name + .type \name, %function +#ifdef __thumb__ + .thumb_func +#endif +\name: +.endm + +.macro ENDF name + .size \name, . - \name +.endm + +/* + * We must save/restore r7 for the EABI syscall number. + * While we're doing that, we might as well save LR to get a free return, + * and a branch that is interworking back to ARMv5. + */ + +.macro syscall n + .cfi_startproc + push {r7, lr} + .cfi_adjust_cfa_offset 8 + .cfi_offset r7, -8 + .cfi_offset lr, -4 + raw_syscall \n + pop {r7, pc} + .cfi_endproc +.endm + +FUNC __vdso_clock_gettime + syscall __NR_clock_gettime +ENDF __vdso_clock_gettime + +FUNC __vdso_clock_gettime64 + syscall __NR_clock_gettime64 +ENDF __vdso_clock_gettime64 + +FUNC __vdso_clock_getres + syscall __NR_clock_getres +ENDF __vdso_clock_getres + +FUNC __vdso_gettimeofday + syscall __NR_gettimeofday +ENDF __vdso_gettimeofday + + +/* + * We, like the real kernel, use a table of sigreturn trampolines. + * Unlike the real kernel, we do not attempt to pack this into as + * few bytes as possible -- simply use 16 bytes per slot. + * + * Within each slot, use the exact same code sequence as the kernel, + * lest we trip up someone doing code inspection. + */ + +/* offsetof(struct sigframe, retcode[3]) */ +#define SIGFRAME_RC3_OFFSET 756 +#define RT_SIGFRAME_RC3_OFFSET 884 + +.macro slot n + .balign 16 + .org sigreturn_codes + 16 * \n +.endm + +/* + * Start the unwind info at least one instruction before the signal + * trampoline, because the unwinder will assume we are returning + * after a call site. + */ + .cfi_startproc simple + .cfi_signal_frame + .cfi_return_column 15 + + .cfi_def_cfa sp, 32 + 64 + .cfi_offset r0, -16 * 4 + .cfi_offset r1, -15 * 4 + .cfi_offset r2, -14 * 4 + .cfi_offset r3, -13 * 4 + .cfi_offset r4, -12 * 4 + .cfi_offset r5, -11 * 4 + .cfi_offset r6, -10 * 4 + .cfi_offset r7, -9 * 4 + .cfi_offset r8, -8 * 4 + .cfi_offset r9, -7 * 4 + .cfi_offset r10, -6 * 4 + .cfi_offset r11, -5 * 4 + .cfi_offset r12, -4 * 4 + .cfi_offset r13, -3 * 4 + .cfi_offset r14, -2 * 4 + .cfi_offset r15, -1 * 4 + + nop + + .balign 16 +FUNC sigreturn_codes + /* [EO]ABI sigreturn */ + slot 0 + raw_syscall __NR_sigreturn + + .cfi_def_cfa_offset 160 + 64 + + /* [EO]ABI rt_sigreturn */ + slot 1 + raw_syscall __NR_rt_sigreturn + + .cfi_endproc + + .macro cfi_fdpic_pc ofs + /* + * fd = *(r13 + ofs) + * pc = *fd + * + * DW_CFA_expression lr (14), length (5), + * DW_OP_breg13, ofs, DW_OP_deref, DW_OP_deref + */ + .cfi_escape 0x10, 14, 5, 0x7d, (\ofs & 0x7f) + 0x80, (\ofs >> 7), 0x06, 0x06 + .endm + + .macro cfi_fdpic_r9 ofs + /* + * fd = *(r13 + ofs) + * r9 = *(fd + 4) + * + * DW_CFA_expression r9, length (7), + * DW_OP_breg13, ofs, DW_OP_deref, + * DW_OP_plus_uconst, 4, DW_OP_deref + */ + .cfi_escape 0x10, 9, 7, 0x7d, (\ofs & 0x7f) + 0x80, (\ofs >> 7), 0x06, 0x23, 4, 0x06 + .endm + + /* FDPIC sigreturn */ + .cfi_startproc + cfi_fdpic_pc SIGFRAME_RC3_OFFSET + cfi_fdpic_r9 SIGFRAME_RC3_OFFSET + + slot 2 + fdpic_thunk SIGFRAME_RC3_OFFSET + .cfi_endproc + + /* FDPIC rt_sigreturn */ + .cfi_startproc + cfi_fdpic_pc RT_SIGFRAME_RC3_OFFSET + cfi_fdpic_r9 RT_SIGFRAME_RC3_OFFSET + + slot 3 + fdpic_thunk RT_SIGFRAME_RC3_OFFSET + .cfi_endproc + + .balign 16 +ENDF sigreturn_codes diff --git a/linux-user/arm/vdso.ld b/linux-user/arm/vdso.ld new file mode 100644 index 0000000000..3bddef97a5 --- /dev/null +++ b/linux-user/arm/vdso.ld @@ -0,0 +1,74 @@ +/* + * Linker script for linux arm replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_clock_getres; + __vdso_clock_gettime64; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* + * We can't prelink to any address without knowing something about + * the virtual memory space of the host, since that leaks over into + * the available memory space of the guest. + */ + . = SIZEOF_HEADERS; + + /* + * The following, including the FILEHDRS and PHDRS, are modified + * when we relocate the binary. We want them to be initially + * writable for the relocation; we'll force them read-only after. + */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + .data : { + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text +} From patchwork Tue Jul 6 23:49:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470575 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5546439ejx; Tue, 6 Jul 2021 16:53:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHzecr6IjU1vEL8IL+PbT8pM/u/iwtjRdQYUw0jt3HGwI5CrMAFFltXPtpXsp1h54DaEJY X-Received: by 2002:ac8:4f51:: with SMTP id i17mr18545316qtw.257.1625615628218; Tue, 06 Jul 2021 16:53:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615628; cv=none; d=google.com; s=arc-20160816; b=njByHJv1ig+qVt/ypAtQA/7iP/Ph6oevrPGMouk1gXbwSzIg8F/6ERb+cZD7Qf5T9C HD8WdpTFyEkCetbS4VgQvXJ2MbDy0rIdCia3R1TsKqZHJo1zpDPOtkVRnm0SrFCMlj6g Kv/CxcsFUaZIV3e3dkdceL/wHW0muEtANRc/qopmAD//ALdxQ8dmlJlreklkj1LWNkt0 ia5Cp2y3AJx1DZUiTz+8uNuXE+rSkuitLrKzmR+ZSccacKSkWrJGVt9VcJH8ftJM9EZ+ bgHUSpvRYwCIgBMLDzU2RzFW4u5J4LETXJgiaKmYx7KPMScusBknqnnmrv6CbMCIQRWb CVKw== 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=Jv0AKUAYCfq8gx2BZJi7SVG0aTCPQkqBNcO1pY7PIho=; b=HgKcYmykvaDqopc+jFktn/QhHZWMfeaQn/X/pJfe/sySWZNIYgFD9IVMX25rk3Skkn qs0DZO1xO5oECuJmcyqeZi2jWs29PTDE4peAxedQa8xcgXdWwA5uAYvEosnkSKaHjp2c JaWfPYItgPn1ibi3jR8HlZNL8AB9KP0c97RwcJI898Af4TfqgAEqcx91O4arrdQEW6Me t4Lefum+xzkcY1gCYICuH+QoPxupSrljkkWpDsFB7Sjm3GNsslp/PwMIv0Z2V7UT4ycH 250crH5Xb5h8TMfbcmnUHwCu0akqvxV+4qdgSSHm4yS4ubd1UYjCaGnixntCLRtzILZV oRdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iQXX8E1Z; 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 a11si10954477qta.287.2021.07.06.16.53.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:53:48 -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=iQXX8E1Z; 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]:46416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0ust-0007mv-Ey for patch@linaro.org; Tue, 06 Jul 2021 19:53:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0up6-0001Js-59 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:52 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:41803) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up0-0006eI-N4 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:51 -0400 Received: by mail-pl1-x635.google.com with SMTP id y2so51252plc.8 for ; Tue, 06 Jul 2021 16:49:45 -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=Jv0AKUAYCfq8gx2BZJi7SVG0aTCPQkqBNcO1pY7PIho=; b=iQXX8E1ZI69fJpbq3/OXKIscKs5hnShvqJg32c6OKrcRS/DHr+/jsGrTPzcdfuh7L0 1RwS7J/UwlUshn13iBiyCMe9e2LT+YpGcIwLoSW4fhhtBpoFRpY7UxznJYs3w08/RguL 3AVROREGO4MlA9dtlLxpYQEN0XOS9lcqDB2IBKf21qXqhN1gwuuvR+LVsn0mgedeNDLI qCmTtALHhhbPtsWbFo+9wpA4LuyqqOMMjvRdPHBGPPNFB7KE20L1WiPp/LA/4wNh3OfR 9FwpOYJGfqi26CeagCYVLih8sc/YWp5UzNtXT7cqumifxYnRIAPQUUd1lMx2+svwurWl Ff9Q== 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=Jv0AKUAYCfq8gx2BZJi7SVG0aTCPQkqBNcO1pY7PIho=; b=Y+1sHKLhxyjy6U0QtEuYZtXQovZcW1Eqkxdjw4759I3koVtccYeyQTMr8xbf9kiBTR yRef9uQsf+9IsjuRv9ulcyrYgTVXoWMe1uZvisaIbpmm3nv6kafiGUPWUW4IM52sWnCu HjE8hori5gV70ewjusbgBSGdFeSZyzuD6FT8bsXBCLMuKyEMzRAn5JtrFHF3DGTygp+k JDD13rWJcA1w488PsxE+rf2kAge0oHnVc4hnlvRiOweO1wL+PtlM5WHyY2YcmAMldkDX 8uxcu6DkQw+ucVTceHjqEu7W5RLjruaATZzqiZUwsM+MN1Mo6LAr0qeUcKk6t/tsCIsU YrpQ== X-Gm-Message-State: AOAM5331u1ab0hgs3vBmDyG7SPtJTG0XTXkAVIgt7fUBigsVStkQ+76k wzE/wmEslN0glkdNNoTCIzFfrNlvP3dcKw== X-Received: by 2002:a17:902:8343:b029:122:eb4:218f with SMTP id z3-20020a1709028343b02901220eb4218fmr18852396pln.71.1625615384737; Tue, 06 Jul 2021 16:49:44 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 17/36] linux-user/alpha: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:13 -0700 Message-Id: <20210706234932.356913-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= 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 ka_restorer. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/alpha/target_signal.h | 1 + linux-user/alpha/signal.c | 34 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) -- 2.25.1 diff --git a/linux-user/alpha/target_signal.h b/linux-user/alpha/target_signal.h index 250642913e..0b6a39de65 100644 --- a/linux-user/alpha/target_signal.h +++ b/linux-user/alpha/target_signal.h @@ -93,6 +93,7 @@ typedef struct target_sigaltstack { #define TARGET_ARCH_HAS_SETUP_FRAME #define TARGET_ARCH_HAS_KA_RESTORER +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 /* bit-flags */ #define TARGET_SS_AUTODISARM (1U << 31) /* disable sas during sighandling */ diff --git a/linux-user/alpha/signal.c b/linux-user/alpha/signal.c index 1129ffeea1..e15f5438c3 100644 --- a/linux-user/alpha/signal.c +++ b/linux-user/alpha/signal.c @@ -54,13 +54,11 @@ struct target_ucontext { struct target_sigframe { struct target_sigcontext sc; - unsigned int retcode[3]; }; struct target_rt_sigframe { target_siginfo_t info; struct target_ucontext uc; - unsigned int retcode[3]; }; #define INSN_MOV_R30_R16 0x47fe0410 @@ -141,12 +139,7 @@ void setup_frame(int sig, struct target_sigaction *ka, if (ka->ka_restorer) { r26 = ka->ka_restorer; } else { - __put_user(INSN_MOV_R30_R16, &frame->retcode[0]); - __put_user(INSN_LDI_R0 + TARGET_NR_sigreturn, - &frame->retcode[1]); - __put_user(INSN_CALLSYS, &frame->retcode[2]); - /* imb() */ - r26 = frame_addr + offsetof(struct target_sigframe, retcode); + r26 = default_sigreturn; } unlock_user_struct(frame, frame_addr, 1); @@ -195,12 +188,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, if (ka->ka_restorer) { r26 = ka->ka_restorer; } else { - __put_user(INSN_MOV_R30_R16, &frame->retcode[0]); - __put_user(INSN_LDI_R0 + TARGET_NR_rt_sigreturn, - &frame->retcode[1]); - __put_user(INSN_CALLSYS, &frame->retcode[2]); - /* imb(); */ - r26 = frame_addr + offsetof(struct target_rt_sigframe, retcode); + r26 = default_rt_sigreturn; } if (err) { @@ -268,3 +256,21 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 6 * 4, 0); + assert(tramp != NULL); + + default_sigreturn = sigtramp_page; + __put_user(INSN_MOV_R30_R16, &tramp[0]); + __put_user(INSN_LDI_R0 + TARGET_NR_sigreturn, &tramp[1]); + __put_user(INSN_CALLSYS, &tramp[2]); + + default_rt_sigreturn = sigtramp_page + 3 * 4; + __put_user(INSN_MOV_R30_R16, &tramp[3]); + __put_user(INSN_LDI_R0 + TARGET_NR_rt_sigreturn, &tramp[4]); + __put_user(INSN_CALLSYS, &tramp[5]); + + unlock_user(tramp, sigtramp_page, 6 * 4); +} From patchwork Tue Jul 6 23:49:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470616 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5552579ejx; Tue, 6 Jul 2021 17:04:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfWrqVnCR0DvesUL9nMuNHiNmF8p1yln9ebcoeyBFRzJJLeuH3rGRZLTgbfIqyU+YwJOUb X-Received: by 2002:a17:906:25cb:: with SMTP id n11mr21192589ejb.539.1625616243311; Tue, 06 Jul 2021 17:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616243; cv=none; d=google.com; s=arc-20160816; b=kmcgpeG66StJoxg5JLgK1bshxmjYBtTf31cIk0qcILbmfCMJBj6Pc3JUwQf9tsHcHS wFAmlgyhPJbNhkOJ6w/7QlKlnziehBl4WivF4M07ofp/RnjAKAUpTDqQVTk5zTh3n3E5 PejSI6arVf5BN1jrrG260u0aH0Jl1gU4Vny39FZ4Gxzrz4wiOExZW5qMK3D+Z/3gKmDI VEYKkRUyaP/wZ/gl14d+0hYpd66rmf/0odNZNCm9JWK7V76PqQhAk1nm+8g/aJeKBilc GpuOOED3GB4y3Fu9eoEpVhkOcPnLbviGkyQgXzM6T5kMwMQF/R0+yuI0PVWoNQX+A7AT mEag== 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=4mopW7s5yqP9F0ovgsMWsgQoRxKhvaHRwRrnWnVsrug=; b=qNtRljBbZ13tqOK9go5Ysl56DCwG1XXzq7naz0dcpCJe/GOK1liJUnnxrsT2N1zff/ KQp9BF7rRVtCEVYUYYB8m6GcE1iIG4aCM2q5XYociF0nPGeyvz6F7dyxeImes3Zz0e83 BFMz7F1IpzeTsm8ljjzezFFV7jtSwfHh2r2dXrwHC88wdtVU09ZVXDajsc24HuTipRgD D1hf4HLloayV3FYp9NMePKNQOW7rvpY7qJqL/ZgNTiNfbpBRkGKft7bze04Z8LozGsZR F8pwnTlJFgjRrEsRdDBtzk+YGJO+oDuprr9nUDk4fkPrOpj7FbSdId/G1HZCgj6Khix7 AL2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="Q4/R5H+l"; 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 m19si8913217edr.133.2021.07.06.17.04.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:04:03 -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="Q4/R5H+l"; 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]:57354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v2o-0000DM-DQ for patch@linaro.org; Tue, 06 Jul 2021 20:04:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0up7-0001PC-TK for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:53 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:38849) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up0-0006eU-VQ for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:53 -0400 Received: by mail-pj1-x1035.google.com with SMTP id cs1-20020a17090af501b0290170856e1a8aso2555247pjb.3 for ; Tue, 06 Jul 2021 16:49:46 -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=4mopW7s5yqP9F0ovgsMWsgQoRxKhvaHRwRrnWnVsrug=; b=Q4/R5H+lIAuM3R/QCkcbyAlk5IfnkGPqDs1oewXFzsIOfO9z1X1BjTvkmnndZQ4i+h iGUffW43V8b3Y+0b8euSp5AeFr13DjPW5N7kSZHxbWB4ZbvmI5yClcExED8eBV18n8I8 t+A+bfUCNlbeFdua+e/F5oRug/V0o0cnNEs/ti/lhJEJCiq+XU4EV8NhJ2UHDTmejDfH 59YcwnG+8BqadruKx9z8ztRFlXBeH7wEeIsAX3LZEX34sWZsf+TQZRdaQWbEJ6180cZe I3oSVJ3TjOGOSLGNejMtyaO11prrcm3wY5bWfzacQacsFjm9owji697blmxBT0chnEgW CorA== 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=4mopW7s5yqP9F0ovgsMWsgQoRxKhvaHRwRrnWnVsrug=; b=JdKtK/z/OcK9VODlfPXWbZ1B4LGgZ6i1+br838aktR0DvUjDRV5sJ/mJ4xtfMvldIQ oWJBoLdlNuBvbg2MlyULaLDiBvXKRFBoBIbzd2+JgyH19cTS3Fd733fdakAKVeboo1ED a79/y6fkvLKEdvKa1AgtbS2TQA3NAnNgDTWoZzgo7QkMNxZUSrNIJ925/xkn6CvoUX2r dKUsTwTwqSJFpqR3cj0DKnEJ60b1671SbDSI8ogfYDHPTEq593jDRW/r8HCSHaAj46R4 gmYaLNNOMEKJpRrKNPJrTvkjE4LM1bQ/J/3WYGL4KzHCJ8xJqyiaxu/3pnyHic+FPKrH mTsA== X-Gm-Message-State: AOAM532Vo3ip58tCjxY/2og88e1Rop94Xj7gqPfe4GzbFg2kX1Jegynt gWnUQkx5f9Aj/D1vFMbf+YUN9aI622xY1Q== X-Received: by 2002:a17:902:e84b:b029:129:3120:153b with SMTP id t11-20020a170902e84bb02901293120153bmr18870159plg.47.1625615385401; Tue, 06 Jul 2021 16:49:45 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 18/36] linux-user/cris: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:14 -0700 Message-Id: <20210706234932.356913-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.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: "Edgar E . Iglesias" , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out setup_sigreturn so that we can continue to initialize the words on the stack, as documented. However, use the off-stack trampoline. Cc: Edgar E. Iglesias Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/cris/target_signal.h | 2 ++ linux-user/cris/signal.c | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/linux-user/cris/target_signal.h b/linux-user/cris/target_signal.h index 495a142896..83a5155507 100644 --- a/linux-user/cris/target_signal.h +++ b/linux-user/cris/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 /* CRIS_TARGET_SIGNAL_H */ diff --git a/linux-user/cris/signal.c b/linux-user/cris/signal.c index 1e02194377..9dad50f31f 100644 --- a/linux-user/cris/signal.c +++ b/linux-user/cris/signal.c @@ -96,6 +96,14 @@ static abi_ulong get_sigframe(CPUCRISState *env, int framesize) return sp - framesize; } +static void setup_sigreturn(uint16_t *retcode) +{ + /* This is movu.w __NR_sigreturn, r9; break 13; */ + __put_user(0x9c5f, retcode + 0); + __put_user(TARGET_NR_sigreturn, retcode + 1); + __put_user(0xe93d, retcode + 2); +} + void setup_frame(int sig, struct target_sigaction *ka, target_sigset_t *set, CPUCRISState *env) { @@ -111,14 +119,8 @@ void setup_frame(int sig, struct target_sigaction *ka, /* * The CRIS signal return trampoline. A real linux/CRIS kernel doesn't * use this trampoline anymore but it sets it up for GDB. - * In QEMU, using the trampoline simplifies things a bit so we use it. - * - * This is movu.w __NR_sigreturn, r9; break 13; */ - __put_user(0x9c5f, frame->retcode+0); - __put_user(TARGET_NR_sigreturn, - frame->retcode + 1); - __put_user(0xe93d, frame->retcode + 2); + setup_sigreturn(frame->retcode); /* Save the mask. */ __put_user(set->sig[0], &frame->sc.oldmask); @@ -134,7 +136,7 @@ void setup_frame(int sig, struct target_sigaction *ka, env->regs[10] = sig; env->pc = (unsigned long) ka->_sa_handler; /* Link SRP so the guest returns through the trampoline. */ - env->pregs[PR_SRP] = frame_addr + offsetof(typeof(*frame), retcode); + env->pregs[PR_SRP] = default_sigreturn; unlock_user_struct(frame, frame_addr, 1); return; @@ -186,3 +188,14 @@ long do_rt_sigreturn(CPUCRISState *env) qemu_log_mask(LOG_UNIMP, "do_rt_sigreturn: not implemented\n"); return -TARGET_ENOSYS; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint16_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 6, 0); + assert(tramp != NULL); + + default_sigreturn = sigtramp_page; + setup_sigreturn(tramp); + + unlock_user(tramp, sigtramp_page, 6); +} From patchwork Tue Jul 6 23:49:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470600 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5548802ejx; Tue, 6 Jul 2021 16:58:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6oNjj3yS99dft1IXrc4hbcyxsk6fH+UQxayrITpx6BTSrnSvz7TM5Ix0ZGGGmVUn92ufI X-Received: by 2002:a37:a2c4:: with SMTP id l187mr10991523qke.261.1625615902511; Tue, 06 Jul 2021 16:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615902; cv=none; d=google.com; s=arc-20160816; b=lcyubZbYnSTewc53OrnlF+jer4zTvVhc2MvRnQL5L6A5TbxHGGT/EOHg4jPBilgNcH JQSlhLNO17lOM6UGyAY2c3tEtZElJ4a4dMc1O2GHbh8860OEw8QmqkdUCXiESe6+OaOZ GmPVnQmMCawsmSssjoqLTPZWoqr9sy6gISIhgMyrqEscEL87ke+TnXXjWYD76Ln9lfhr QIyC1Z+C4a3cxmuleFCgOZ435pv2iGsqFPdhzM2S0Ok4SjVVTVkTXFrvlmCkwES4KtFV a+dnWgK3kKTKhEupXs1z3LbBnBYFAe6Ge1RJGXJN5jmpWKfK6GQ6XzUrIB3ebxVB/9jL El5w== 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=9iNrkNfNiht6gNc7s+Sfth7iEg29J37zPd797X3OxQE=; b=u9ipYFXrV6n7cZysJKiCNg71R30dnRGS1wL+Py7QmXD/AQcIDADizCk1Jb64psZin4 iVEdbwq775n9E2mk1ryj7lUkuHM+Ffm4xXdemqsoWHUl1vAGxYRd/PMbwrHF8BNo9cyh nt//+BUqe0VeZtOAxnCqBc/I++k8MqYnqpoPA8MmUWBcehWha8BXt4vE26puBjCP2boC 7q6dQ/uA2DXMtLAZoSPTFQwxVR57M/9CmR3nlvD6TMygzUXT9smSH7VeYeCbPevyMYMs CtwcwInX7J/VpNEnQ3M60Tqa0mJXmS5bUqcyiSiqlW92Xo4x6y2hUMu6zX6K4YpltUrB TWeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=i5JUERA2; 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 m1si13707263qtn.263.2021.07.06.16.58.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:58:22 -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=i5JUERA2; 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]:35608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uxJ-0002G3-RY for patch@linaro.org; Tue, 06 Jul 2021 19:58:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0up8-0001Rz-JY for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:54 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:46026) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up1-0006ee-II for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:54 -0400 Received: by mail-pl1-x634.google.com with SMTP id s13so41736plg.12 for ; Tue, 06 Jul 2021 16:49:46 -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=9iNrkNfNiht6gNc7s+Sfth7iEg29J37zPd797X3OxQE=; b=i5JUERA2/P2iYZkHrcjPM2IRemKJ5K1KdtgYYi03sONM+hSiyLpaqK0LzBP7ORIEZ3 GbVgwwdj7KgFH5N+rxO71klw3sXEkYMCYv+boyhfUOCO4t5LoHo/DEjVCvzho7xUZaNc gjJZETrLTeYORoivRka+TyZpArsaOHxdzQeCkjya9Z4Ygb3GgPnvPaVIGFyUe9vS/+PU h1jmZDceyz+K9LyB6NXhfo57/AgM1brySZjRiGmR7r8Vvtz3SykqYXklOKQIz6LDQ55D ZmrOWUbZth/KAi1MDOTKUuHuEK1nw0dsfYU0X+Z8B3tCUYh0RYjrmrWOoBSSwtVHFiYZ H01w== 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=9iNrkNfNiht6gNc7s+Sfth7iEg29J37zPd797X3OxQE=; b=HgZ2kAlphNYMLJewMMgr+wSnkvK7gSlywHz1M1DNuiHvpaHrtpNlku1XfzF6IIOTCE 91maqZ6V0SewrR90PIFgzlUSDQaFopHExD1oNmuDotPn7TnIjrpvv/lr+tnoCh+WRsby Zlaby93nDoiEQMMKJSNhU5o8w2qt1/dk8+x51q4oVkSLGj9br27YZVvJKPiBAzC8g2eR TETxwzkmQouWpuPPyei+JWBuez5P8eOBMVC/HcM0FfGr+9CeQOaVW1AHnEo96dHK+oxG 1WeWGWquLG/b7p0Xmsu5O98TPrvHAX0IGKCF7H+pPtOobz6XIJstNtsASGxTYz+RVpPa +B+A== X-Gm-Message-State: AOAM531EaQengkm05BfE/TIqaqms1MiShRsb1BnDF6h3yAiEMZ8O/gVT 7ZEMIbAQIO71nL7Xf3UBjAm6KcqJlJgVTA== X-Received: by 2002:a17:902:8d82:b029:120:4377:8e0e with SMTP id v2-20020a1709028d82b029012043778e0emr18967194plo.32.1625615385958; Tue, 06 Jul 2021 16:49:45 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 19/36] linux-user/hexagon: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:15 -0700 Message-Id: <20210706234932.356913-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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: Taylor Simpson , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Continue to initialize the words on the stack, as documented. However, use the off-stack trampoline. Cc: Taylor Simpson Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/hexagon/target_signal.h | 2 ++ linux-user/hexagon/signal.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) -- 2.25.1 Reviewed-by: Taylor Simpson Tested-by: Taylor Simpson diff --git a/linux-user/hexagon/target_signal.h b/linux-user/hexagon/target_signal.h index 345cf1cbb8..9e0223d322 100644 --- a/linux-user/hexagon/target_signal.h +++ b/linux-user/hexagon/target_signal.h @@ -31,4 +31,6 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif /* TARGET_SIGNAL_H */ diff --git a/linux-user/hexagon/signal.c b/linux-user/hexagon/signal.c index 85eab5e943..bd0f9b1c85 100644 --- a/linux-user/hexagon/signal.c +++ b/linux-user/hexagon/signal.c @@ -161,6 +161,11 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, setup_ucontext(&frame->uc, env, set); tswap_siginfo(&frame->info, info); + /* + * The on-stack signal trampoline is no longer executed; + * however, the libgcc signal frame unwinding code checks + * for the presence of these two numeric magic values. + */ install_sigtramp(frame->tramp); env->gpr[HEX_REG_PC] = ka->_sa_handler; @@ -170,8 +175,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, frame_addr + offsetof(struct target_rt_sigframe, info); env->gpr[HEX_REG_R02] = frame_addr + offsetof(struct target_rt_sigframe, uc); - env->gpr[HEX_REG_LR] = - frame_addr + offsetof(struct target_rt_sigframe, tramp); + env->gpr[HEX_REG_LR] = default_rt_sigreturn; return; @@ -270,3 +274,14 @@ badframe: force_sig(TARGET_SIGSEGV); return 0; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 4 * 2, 0); + assert(tramp != NULL); + + default_rt_sigreturn = sigtramp_page; + install_sigtramp(tramp); + + unlock_user(tramp, sigtramp_page, 4 * 2); +} From patchwork Tue Jul 6 23:49:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470610 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5550689ejx; Tue, 6 Jul 2021 17:01:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlbi7pAIt2E3lP7DHD/sY/desL2WOrXphQetZZ2cS6qM4GMTh14IrpfS7JJ+Ftq1eSAo0u X-Received: by 2002:a1f:2608:: with SMTP id m8mr16218618vkm.17.1625616086057; Tue, 06 Jul 2021 17:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616086; cv=none; d=google.com; s=arc-20160816; b=Ettk8amj72U+P1715ryOFHPaR3JHPqxSikyD8GXMJscHQU0nMHscBXs8kvgXt9U4h6 RZ7TM1cPQlrTAGNFRlna2RWVGrq0ZOkewiUBScOBcdkbmYcfu7Nkwof97sPnf6yLXf9t x9+l2zyjFqphbRPDZ6rWpQF2kJP3Kn1i9WlXzPTV7f4xR0j7vQJf6RYYLvW4HnkasRyO 9UYF1pF3kVFGmfSg4POuUQqYAxL9VIRgWw9YDD7rTvk/QflT9myRE2apOumIkcW5xY+E 7lEy+UuvbRb9MD0nYLMBZuOumFN2XW9JhrT8CwYUjxdfByQlgmLMtfKHwNVOTnblR5xc thqA== 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=l6ttjRfQ6jH1AfHE03jdic7003sgS0FcDvhNsfAtMaA=; b=Y0ukwSU259qH6OqSoHfatCSWyBh4hcnyyfnMeYVgZ3akTK85c4nnD8uC10Ug8Hwb/6 EWyV6+Uwa9B4KUNyd/SB/agyNUPsU7I1QN6JH7EPZpB2OhrhtZPfuXLzcBSaAYn+QWe8 TTN+WgZHFU+Qv/byBtzmJ22/jG88n0ot92IiRF9jBIMHWkwa4j5IrQMFMVpIjCLFmePF jElu4gJ61wFEVUbuvU2TwtkSPKRVoqYRz4FjAr0/gC6YvyoD9DSBu4QqgOX5xsbj51+x CISHJIDgVCUXnDM6fDcU40UUE72ruv5y8Zlut0eJ2Hv0NcCFTm+bUNrhD4qiUjPKRBF+ 2m+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KwTveJbr; 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 90si14969510uam.157.2021.07.06.17.01.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:01:26 -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=KwTveJbr; 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]:44112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v0H-0007sK-9Z for patch@linaro.org; Tue, 06 Jul 2021 20:01:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0up9-0001U9-BA for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:55 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:42853) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up2-0006eu-33 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:55 -0400 Received: by mail-pj1-x1032.google.com with SMTP id p17-20020a17090b0111b02901723ab8d11fso485871pjz.1 for ; Tue, 06 Jul 2021 16:49:47 -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=l6ttjRfQ6jH1AfHE03jdic7003sgS0FcDvhNsfAtMaA=; b=KwTveJbrOoSxZbmt5Q7pdYsAO9yUUDeq5VvRHo1UV3AIy69jpAl90a6uQT+z1Ps+3u tpFusvCPfJZ66bRC0NTrE/ULLVOBe5jlH0hv6iICKOlhY7zqfOIODrGQC86XBLkKyy9j L4idkWdfP9Jk8gKdGE4nfjH2LCE2O+dA4AABr2lsIT2e+N50hrn8EWoF6Dei/RGZFA66 UtXonDT+SKAy/QoWXez6dQRAE2QrYJ1l5aATltOQw7Kw+sGVsCWBcLg/FP/dY5RR6LDO gw0Dlsa9ZIJKhD6fVFJgsa/vZFh/uV1BCRHHQfXM4RCBjPLtsDuU01juq2TNblPcBp5M qzgA== 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=l6ttjRfQ6jH1AfHE03jdic7003sgS0FcDvhNsfAtMaA=; b=nQY4kzDSbN/Au5CzlULhh0oq6NzHjEMYxmaZojzwEeX6Np978EMXUkL6+4v4MWMdvA h3EnKzIlgmOSozOt2lvIR2OyOA0OpWyWVyANMVR/3vphI6/ViKYFyF8FTWnZ79QfOmQS /dkCiBoU5/ILfcEwpDj4inmOaDzSGvUYhgkYLqMBwN+xTXzg7rgY8cse7nO/NgfF93Th p8FS9PQ5bwjTAKDfcrkRaVl2EbzWgDttf4EtyFT0LHxxMHqA8WntbbCjNTUKU/yKfdGZ C0FgwvwOdF/6F5vBx34jJy5qie4IqfRxSveYTsfdO9UoOSRYXUZdLl89e/njwWugKVeu j4gQ== X-Gm-Message-State: AOAM531y74O1OG46lFPX5VAA9OlZ589Y6lxk4tmjaZ7k2dICQmIxQRoB Q8QhCQtP5KLnDR+BvNt5cczrNE24AnGudw== X-Received: by 2002:a17:902:e2d3:b029:129:70aa:990 with SMTP id l19-20020a170902e2d3b029012970aa0990mr15687931plc.34.1625615386478; Tue, 06 Jul 2021 16:49:46 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 20/36] linux-user/hppa: Add vdso and use it for rt_sigreturn Date: Tue, 6 Jul 2021 16:49:16 -0700 Message-Id: <20210706234932.356913-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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" Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in that file for now. Drop the now-unused 9 trampoline words, and describe the frame without the trampoline in __kernel_rt_sigreturn. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 + linux-user/hppa/signal.c | 8 +- linux-user/hppa/Makefile.vdso | 6 ++ linux-user/hppa/meson.build | 6 ++ linux-user/hppa/vdso.S | 149 ++++++++++++++++++++++++++++++++++ linux-user/hppa/vdso.ld | 75 +++++++++++++++++ linux-user/hppa/vdso.so | Bin 0 -> 5196 bytes 7 files changed, 241 insertions(+), 7 deletions(-) create mode 100644 linux-user/hppa/Makefile.vdso create mode 100644 linux-user/hppa/vdso.S create mode 100644 linux-user/hppa/vdso.ld create mode 100755 linux-user/hppa/vdso.so diff --git a/linux-user/hppa/vdso.so b/linux-user/hppa/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..bd77b8a5c33d66380a79b2f816237568998c8af3 GIT binary patch literal 5196 zcmeHLTX2&_6y8m`h?i>1Fr!Y<(V03TLgZ2vMX_m{v|xHmQlRzno08B(+64dnt!Y&# zrJ#tSAYi?V;vMhzD?akzLq~o0rOYtnjH5H?lUl!T|9?q4!-F$E`0}6R%h_|;v%6QP>C*pB(!-jarNeZBIKVIh--%n9~VdDL|l%$<-U@r0?d=`hp5?Q4RN~Mq4!%Rm4%zLDf8@TJBYAN^0$} zx^+aw?o+MztF{MJ`&QMlO?8e+72hsZVoa*!4yn4vrCPUBs`b01+OS8e?%hnkK0EIH zydxN!+)(e6p8-Dueg^yu_!;ms;Ag|OQN+)eJyT*#P!?yV zQ&h9abt&t(0<;koy=|9(# zlb(FGCucpGbvTISruJt&jy<~jlWwgHpMahZ8|PnQ_UGAGK&Q#8tydymxwf{Ny4%97 zYZ_5RqhDY}TC8Y1+#0c3n&QH0j? z-$4&WznP_wIhXHB=Nx>wCo|r07v>$nQtsp6p7eWSyh#^=eGtsk#CXJNfI9k}bfJ4U zP-*hsw1}c#GYt*=_#X9}^vRPP6^7Nd_-O+SnRwMu O%=EJ%j~XX%?e`Db?gR4x literal 0 HcmV?d00001 -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 40cc79b129..ec3a854b44 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1496,6 +1496,10 @@ static inline void init_thread(struct target_pt_regs *regs, #define STACK_GROWS_DOWN 0 #define STACK_ALIGNMENT 64 +#include "vdso.c.inc" + +#define vdso_image_info() &vdso_image_info + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c index 0e266f472d..44e2db6d3e 100644 --- a/linux-user/hppa/signal.c +++ b/linux-user/hppa/signal.c @@ -40,7 +40,6 @@ struct target_ucontext { }; struct target_rt_sigframe { - abi_uint tramp[9]; target_siginfo_t info; struct target_ucontext uc; /* hidden location of upper halves of pa2.0 64-bit gregs */ @@ -138,14 +137,9 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, setup_sigcontext(&frame->uc.tuc_mcontext, env); - __put_user(0x34190000, frame->tramp + 0); /* ldi 0,%r25 */ - __put_user(0x3414015a, frame->tramp + 1); /* ldi __NR_rt_sigreturn,%r20 */ - __put_user(0xe4008200, frame->tramp + 2); /* be,l 0x100(%sr2,%r0) */ - __put_user(0x08000240, frame->tramp + 3); /* nop */ - unlock_user_struct(frame, frame_addr, 1); - env->gr[2] = h2g(frame->tramp); + env->gr[2] = default_rt_sigreturn; env->gr[30] = sp; env->gr[26] = sig; env->gr[25] = h2g(&frame->info); diff --git a/linux-user/hppa/Makefile.vdso b/linux-user/hppa/Makefile.vdso new file mode 100644 index 0000000000..d4362c4961 --- /dev/null +++ b/linux-user/hppa/Makefile.vdso @@ -0,0 +1,6 @@ +CROSS_CC ?= hppa-linux-gnu-gcc + +vdso.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--build-id=sha1 \ + -Wl,--hash-style=sysv vdso.S -o $@ diff --git a/linux-user/hppa/meson.build b/linux-user/hppa/meson.build index 4709508a09..e065a16a96 100644 --- a/linux-user/hppa/meson.build +++ b/linux-user/hppa/meson.build @@ -3,3 +3,9 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +gen = [ + gen_vdso.process('vdso.so', extra_args: ['-r', '__kernel_rt_sigreturn']) +] + +linux_user_ss.add(when: 'TARGET_HPPA', if_true: gen) diff --git a/linux-user/hppa/vdso.S b/linux-user/hppa/vdso.S new file mode 100644 index 0000000000..eeae2c999a --- /dev/null +++ b/linux-user/hppa/vdso.S @@ -0,0 +1,149 @@ +/* + * hppa linux kernel vdso replacement. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + + .text + +#define sizeof_rt_sigframe 696 +#define offsetof_sigcontext 152 +#define offsetof_sigcontext_gr offsetof_sigcontext + 4 +#define offsetof_sigcontext_fr offsetof_sigcontext_gr + 32 * 4 +#define offsetof_sigcontext_iasq offsetof_sigcontext_fr + 32 * 8 +#define offsetof_sigcontext_iaoq offsetof_sigcontext_iasq + 8 +#define offsetof_sigcontext_sar offsetof_sigcontext_iaoq + 8 + + /* + * While this frame is marked as a signal frame, that only applies + * to how this return address is handled for the outer frame. + * The return address that arrived here, from the inner frame, is + * not marked as a signal frame and so the unwinder still tries to + * subtract 1 to examine the presumed call insn. Thus we must + * extend the unwind info to a nop before the start. + */ + + .cfi_startproc simple + .cfi_signal_frame + + /* Compare pa32_fallback_frame_state from libgcc. */ + + /* Record the size of the stack frame. */ + .cfi_def_cfa 30, -sizeof_rt_sigframe + + /* Record save offset of general registers. */ + .cfi_offset 1, offsetof_sigcontext_gr + 1 * 4 + .cfi_offset 2, offsetof_sigcontext_gr + 2 * 4 + .cfi_offset 3, offsetof_sigcontext_gr + 3 * 4 + .cfi_offset 4, offsetof_sigcontext_gr + 4 * 4 + .cfi_offset 5, offsetof_sigcontext_gr + 5 * 4 + .cfi_offset 6, offsetof_sigcontext_gr + 6 * 4 + .cfi_offset 7, offsetof_sigcontext_gr + 7 * 4 + .cfi_offset 8, offsetof_sigcontext_gr + 8 * 4 + .cfi_offset 9, offsetof_sigcontext_gr + 9 * 4 + .cfi_offset 10, offsetof_sigcontext_gr + 10 * 4 + .cfi_offset 11, offsetof_sigcontext_gr + 11 * 4 + .cfi_offset 12, offsetof_sigcontext_gr + 12 * 4 + .cfi_offset 13, offsetof_sigcontext_gr + 13 * 4 + .cfi_offset 14, offsetof_sigcontext_gr + 14 * 4 + .cfi_offset 15, offsetof_sigcontext_gr + 15 * 4 + .cfi_offset 16, offsetof_sigcontext_gr + 16 * 4 + .cfi_offset 17, offsetof_sigcontext_gr + 17 * 4 + .cfi_offset 18, offsetof_sigcontext_gr + 18 * 4 + .cfi_offset 19, offsetof_sigcontext_gr + 19 * 4 + .cfi_offset 20, offsetof_sigcontext_gr + 20 * 4 + .cfi_offset 21, offsetof_sigcontext_gr + 21 * 4 + .cfi_offset 22, offsetof_sigcontext_gr + 22 * 4 + .cfi_offset 23, offsetof_sigcontext_gr + 23 * 4 + .cfi_offset 24, offsetof_sigcontext_gr + 24 * 4 + .cfi_offset 25, offsetof_sigcontext_gr + 25 * 4 + .cfi_offset 26, offsetof_sigcontext_gr + 26 * 4 + .cfi_offset 27, offsetof_sigcontext_gr + 27 * 4 + .cfi_offset 28, offsetof_sigcontext_gr + 28 * 4 + .cfi_offset 29, offsetof_sigcontext_gr + 29 * 4 + .cfi_offset 30, offsetof_sigcontext_gr + 30 * 4 + .cfi_offset 31, offsetof_sigcontext_gr + 31 * 4 + + /* Record save offset of fp registers, left and right halves. */ + .cfi_offset 32, offsetof_sigcontext_fr + 4 * 8 + .cfi_offset 33, offsetof_sigcontext_fr + 4 * 8 + 4 + .cfi_offset 34, offsetof_sigcontext_fr + 5 * 8 + .cfi_offset 35, offsetof_sigcontext_fr + 5 * 8 + 4 + .cfi_offset 36, offsetof_sigcontext_fr + 6 * 8 + .cfi_offset 37, offsetof_sigcontext_fr + 6 * 8 + 4 + .cfi_offset 38, offsetof_sigcontext_fr + 7 * 8 + .cfi_offset 39, offsetof_sigcontext_fr + 7 * 8 + 4 + .cfi_offset 40, offsetof_sigcontext_fr + 8 * 8 + .cfi_offset 41, offsetof_sigcontext_fr + 8 * 8 + 4 + .cfi_offset 42, offsetof_sigcontext_fr + 9 * 8 + .cfi_offset 43, offsetof_sigcontext_fr + 9 * 8 + 4 + .cfi_offset 44, offsetof_sigcontext_fr + 10 * 8 + .cfi_offset 45, offsetof_sigcontext_fr + 10 * 8 + 4 + .cfi_offset 46, offsetof_sigcontext_fr + 11 * 8 + .cfi_offset 47, offsetof_sigcontext_fr + 11 * 8 + 4 + .cfi_offset 48, offsetof_sigcontext_fr + 12 * 8 + .cfi_offset 49, offsetof_sigcontext_fr + 12 * 8 + 4 + .cfi_offset 50, offsetof_sigcontext_fr + 13 * 8 + .cfi_offset 51, offsetof_sigcontext_fr + 13 * 8 + 4 + .cfi_offset 52, offsetof_sigcontext_fr + 14 * 8 + .cfi_offset 53, offsetof_sigcontext_fr + 14 * 8 + 4 + .cfi_offset 54, offsetof_sigcontext_fr + 15 * 8 + .cfi_offset 55, offsetof_sigcontext_fr + 15 * 8 + 4 + .cfi_offset 56, offsetof_sigcontext_fr + 16 * 8 + .cfi_offset 57, offsetof_sigcontext_fr + 16 * 8 + 4 + .cfi_offset 58, offsetof_sigcontext_fr + 17 * 8 + .cfi_offset 59, offsetof_sigcontext_fr + 17 * 8 + 4 + .cfi_offset 60, offsetof_sigcontext_fr + 18 * 8 + .cfi_offset 61, offsetof_sigcontext_fr + 18 * 8 + 4 + .cfi_offset 62, offsetof_sigcontext_fr + 19 * 8 + .cfi_offset 63, offsetof_sigcontext_fr + 19 * 8 + 4 + .cfi_offset 64, offsetof_sigcontext_fr + 20 * 8 + .cfi_offset 65, offsetof_sigcontext_fr + 20 * 8 + 4 + .cfi_offset 66, offsetof_sigcontext_fr + 21 * 8 + .cfi_offset 67, offsetof_sigcontext_fr + 21 * 8 + 4 + .cfi_offset 68, offsetof_sigcontext_fr + 22 * 8 + .cfi_offset 69, offsetof_sigcontext_fr + 22 * 8 + 4 + .cfi_offset 70, offsetof_sigcontext_fr + 23 * 8 + .cfi_offset 71, offsetof_sigcontext_fr + 23 * 8 + 4 + .cfi_offset 72, offsetof_sigcontext_fr + 24 * 8 + .cfi_offset 73, offsetof_sigcontext_fr + 24 * 8 + 4 + .cfi_offset 74, offsetof_sigcontext_fr + 25 * 8 + .cfi_offset 75, offsetof_sigcontext_fr + 25 * 8 + 4 + .cfi_offset 76, offsetof_sigcontext_fr + 26 * 8 + .cfi_offset 77, offsetof_sigcontext_fr + 26 * 8 + 4 + .cfi_offset 78, offsetof_sigcontext_fr + 27 * 8 + .cfi_offset 79, offsetof_sigcontext_fr + 27 * 8 + 4 + .cfi_offset 80, offsetof_sigcontext_fr + 28 * 8 + .cfi_offset 81, offsetof_sigcontext_fr + 28 * 8 + 4 + .cfi_offset 82, offsetof_sigcontext_fr + 29 * 8 + .cfi_offset 83, offsetof_sigcontext_fr + 29 * 8 + 4 + .cfi_offset 84, offsetof_sigcontext_fr + 30 * 8 + .cfi_offset 85, offsetof_sigcontext_fr + 30 * 8 + 4 + .cfi_offset 86, offsetof_sigcontext_fr + 31 * 8 + .cfi_offset 87, offsetof_sigcontext_fr + 31 * 8 + 4 + + /* Record save offset of %sar */ + .cfi_offset 88, offsetof_sigcontext_sar + + /* Record save offset of return address, iaoq[0]. */ + .cfi_return_column 89 + .cfi_offset 89, offsetof_sigcontext_iaoq + + nop + +__kernel_rt_sigreturn: + + ldi 0, %r25 + ldi __NR_rt_sigreturn, %r20 + be,l 0x100(%sr2, %r0), %sr0, %r31 + nop + + .cfi_endproc + + .size __kernel_rt_sigreturn, . - __kernel_rt_sigreturn + .type __kernel_rt_sigreturn, @function + .globl __kernel_rt_sigreturn diff --git a/linux-user/hppa/vdso.ld b/linux-user/hppa/vdso.ld new file mode 100644 index 0000000000..fed994c3eb --- /dev/null +++ b/linux-user/hppa/vdso.ld @@ -0,0 +1,75 @@ +/* + * Linker script for linux hppa vdso. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +/* + * Note that the kernel does not implement a vdso for hppa. + * Mirror the symbol that other targets use for this, e.g. i386. + */ + +VERSION { + QEMU { + global: + __kernel_rt_sigreturn; + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + note PT_NOTE FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; +} + +SECTIONS { + . = SIZEOF_HEADERS; + + /* The following, including the FILEHDRS and PHDRS, are modified + when we relocate the binary. We want them to be initially + writable for the relocation; we'll force them read-only after. */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + .data : { + /* There ought not be any real read-write data. + But since we manipulated the segment layout, + we have to put these sections somewhere. */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text +} From patchwork Tue Jul 6 23:49:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470608 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5549513ejx; Tue, 6 Jul 2021 16:59:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3Je6KBBjc0SbcTjBH6oJoXFTPwIBEO9Qi28V8zLRgX7RCsd3mc6dsPHO2LvvUJZGnRzeJ X-Received: by 2002:ad4:4e2b:: with SMTP id dm11mr5313679qvb.22.1625615987850; Tue, 06 Jul 2021 16:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615987; cv=none; d=google.com; s=arc-20160816; b=jRj9FfcyNRNGEVfB6LECXeL6xW9oid4Dhzq0tZiRxUNAfL1n8PMpnfG4cr1zCd0SIs WVxBbQ8ZHkrMy9Rst1M1LuuSZgfTt6j8n9/Sq32lDd+IHggFA3esOCaJpeAar816OeCb 5iQuaV6qsQDsegbzK49IIXqdhjKjaKsz4CcrHQ2Y4Z0d8FsOqEPLEd/U67R7i+1GTNdc etaH7Bb5jzuxGgsPXzC9MuXI1ZNOheF+51K7WKciOLtoupwTCfTeQKfLjCuXVw7cIlh6 1LXJuvEW2SulDkrZdEVoZRV1c8SXni3wY1Nt/xz7klfJN6Q6QqbNEGokvQ/85Quwuqw8 L+dw== 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=tH4IeYUpSuBmU0n3gRCjrNiQSJ25jU7sgYsJhDOIqq4=; b=nbr+8qc0kmIfp9eyT050+O5uoo5t6EzDjX5xeNd6c7J5pUzhC+JhmbsF6A7q7JS/Df zGKM14IobHfQqfTp1QrU7GKDWJ5VGz0cYDRhCADo4Gm8tTfA6h0lvTOyQ+Ajr8Wn0d1W M8cQDFSrz25OjhSS6LuI+oJAaNonnAEzz+pUflaqAKHRjIjlaSXJ9610l/Ef1hcqENtN kVwYjoaek3EOsPjdzBef5Gr5yNmXTiTfXXD6MrHe895EBtYaGLeZZ3no+PU1REjsGeqU yhfdddxFQ7vfzhRB54YtQMCINLMBjD0U1e1EZxqbjEAoA0pqPvV05dlqm1zMmHL1lqac zg1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iqyMQLGr; 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 k4si12229833qtj.32.2021.07.06.16.59.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:59:47 -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=iqyMQLGr; 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]:42320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0uyh-0006iH-6m for patch@linaro.org; Tue, 06 Jul 2021 19:59:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upA-0001Wp-8L for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:56 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:40797) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up2-0006f5-8k for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:56 -0400 Received: by mail-pj1-x1034.google.com with SMTP id b14-20020a17090a7aceb029017261c7d206so2539482pjl.5 for ; Tue, 06 Jul 2021 16:49:47 -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=tH4IeYUpSuBmU0n3gRCjrNiQSJ25jU7sgYsJhDOIqq4=; b=iqyMQLGrKtY9n5dpEtwUoobadUtvUbcrjsef00FIYOgC9WErPYREInqXAPgMOzAjG9 tp8+37VY5IzAm50VKf91xniEzkAt0bgq6kEYD8z3QCg3IrZ7ItY7RQ/txhIU1XMDiLVv HxZN8WRujQA8vq0WTLkuCmWqVS4ejhUnThZ8wuNi+A1WtZKEl/1nldNJQAwqRF/cgN99 MbCQfqmdGZvCHYwegSI6vtRIcffM+ZBHvNx3f1r0QD1Cp5/EBgEibGzF9oYey985nXCL 1AudJbvlYzEwEznVJ0aOm0VNb/DjQg6oPP7bB6U5+n6MklndVJzGCp6iE/y5/MUk/4N6 /nqA== 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=tH4IeYUpSuBmU0n3gRCjrNiQSJ25jU7sgYsJhDOIqq4=; b=Bczn3t6d36zdXqPPFARiHpkFllakiJB4OOugECh9f6H2zCDO861LbqP9PukJEOG3Yy igar3wtYf8S1b4KQzqoh9bb1b5HISvHoFCvT0+qhku0PCqw2CGe5QHaYq7wEuNWLDruB JBX2DrmuJ6c6wuJgvzmrhhaWQdem0zw/6DryliLxNDhHzIlA6fAbpfM1qS35q1fRA4Yq vXvixRUyEV+6mr3FiAVaLNDcHnDQfOwjYUE+xcUXjE3yeJLGV00/KJTudPuqp7l/kf9f goLz02RVLiO4LYShHm1Lit4vOGYFWxgxq0MpHceJAUwqAdlrykVNTLz5Kxc/2xKbAdAG HkAA== X-Gm-Message-State: AOAM532q+orDO4ZIWDMb07h6R/iVnUrmrYvRBeNceoBWVGJwwHLu6yCA Zq+/Rsur27JW9L/9NsAycVkpkxW2s/yEzg== X-Received: by 2002:a17:90a:c003:: with SMTP id p3mr22612286pjt.14.1625615386980; Tue, 06 Jul 2021 16:49:46 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 21/36] linux-user/x86_64: Raise SIGSEGV if SA_RESTORER not set Date: Tue, 6 Jul 2021 16:49:17 -0700 Message-Id: <20210706234932.356913-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.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" This has been a fixme for some time. The effect of returning -EFAULT from the kernel code is to raise SIGSEGV. Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.25.1 diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 8701774e37..9894e7c9ac 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -411,10 +411,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, /* Set up to return from userspace. If provided, use a stub already in userspace. */ -#ifndef TARGET_X86_64 if (ka->sa_flags & TARGET_SA_RESTORER) { __put_user(ka->sa_restorer, &frame->pretcode); } else { +#ifdef TARGET_X86_64 + /* For x86_64, SA_RESTORER is required ABI. */ + goto give_sigsegv; +#else uint16_t val16; addr = frame_addr + offsetof(struct rt_sigframe, retcode); __put_user(addr, &frame->pretcode); @@ -423,12 +426,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, __put_user(TARGET_NR_rt_sigreturn, (int *)(frame->retcode+1)); val16 = 0x80cd; __put_user(val16, (uint16_t *)(frame->retcode+5)); - } -#else - /* XXX: Would be slightly better to return -EFAULT here if test fails - assert(ka->sa_flags & TARGET_SA_RESTORER); */ - __put_user(ka->sa_restorer, &frame->pretcode); #endif + } /* Set up registers for signal handler */ env->regs[R_ESP] = frame_addr; From patchwork Tue Jul 6 23:49:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470612 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5551690ejx; Tue, 6 Jul 2021 17:02:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdh7hJ8/8/E4NvGCJp0HQwT3+4dJ6MN3vHp0ZDORYoCQpN0OTjuSCenE+34HCt4gf9VTUw X-Received: by 2002:a50:9b06:: with SMTP id o6mr26925318edi.284.1625616169331; Tue, 06 Jul 2021 17:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616169; cv=none; d=google.com; s=arc-20160816; b=vUYWR2ktWmxVnT5HnCY2iEcH0NxKRrGL9GVQhg0Drzb9Jrda5cSvRrWEsFA+Nr1vOY /gwCsXRMqmKaKu2fW5hEZBUz6LnRlNJfG7+Ukq7bW9YI0J4JHri4ldXIe6RiBQ1bwCH9 ckGrcliFChbOURtxc8CmcEbq/IcTli9kXczLXU2cEv8kGwkdiduXyjZkmm5+JRPTYAdD L/lz+ay3fAsUC2/HSUZ7eVjiXAPNPjLtkNiNcD24wTO3ZZxCFhXD05KzMsqQuX1WI6FA cM7y1FKm40vSseXAe6TmHsk2kUFi8Hpd0ZKjOmQudcgTaZjrRcLKaHKm4VE8bOQF7LeS Covw== 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=KG9vmdKuvHiWB/mJT47jTSloEC6SI1jRyoZWluyCLDc=; b=koLE5tm/PkTb/7TAyS6lu7OqoYlIYMsaWy6YyD1/GAIEsLvXwdLEJ+MHe7ZGgvC2SO bI7r4yK2fwDulOBGqaMtNJQPbx9mOnhcpbockujk7hv0EB4ttwj/nGRLKUY51xYfgnpv MOkpHhu65duq37I7IXO9ltaITSLxULtz84lVhJTHk7bviOh4FAKMWr5egAzB6wGDJLG9 3e+ScBYVqhTpLiMkdzId0MU7NY9oqyyfxa+PQ/SScaRUiltXHbkKatWJP7eoRMNz+VSS Vyj04YTbGKqGMf7x6vVUXAFe4K07NQV8qvd1k75Ch5Q+DVpdrPGs01s3ufuo8l3BAJpI UtlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MWuKwEzh; 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 cw19si15118569ejc.372.2021.07.06.17.02.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:02:49 -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=MWuKwEzh; 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]:50978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v1c-0004Ir-BL for patch@linaro.org; Tue, 06 Jul 2021 20:02:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53396) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upC-0001f3-Ti for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:58 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:40799) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up3-0006fO-Ei for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:58 -0400 Received: by mail-pj1-x1036.google.com with SMTP id b14-20020a17090a7aceb029017261c7d206so2539496pjl.5 for ; Tue, 06 Jul 2021 16:49:48 -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=KG9vmdKuvHiWB/mJT47jTSloEC6SI1jRyoZWluyCLDc=; b=MWuKwEzhiQNjlZAI7HtJdtDz/cbiASGgs0apm/xrdDdVLq7a1UR61QA46Gus4mIGOU bnr57u7Nx9cn8G03j1Tc38hUrax2rm4ejJPc1srPzzYNahmZkFSFl5fV2OyxdWojc8wg GuAVnbzN3TiADPuyNW1gLUAy/jvP03bs0z+14UWYKb8fGIluSw565uj36bbckZ0SHI5v aQKC46RNoL+c5s9bG/4vkiw+SVCC+tadsgjUCsvWzLmBBNqJ74H4UZNPXW2k/sYjiCMz YXQDHT3Kkh994JD/QlygnvqATeAadyI5hlhvdMvO1B4XXg1pZNJpq1xSP7VV0ApQm51x v8NA== 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=KG9vmdKuvHiWB/mJT47jTSloEC6SI1jRyoZWluyCLDc=; b=NF734QVVSLSTx8ml3Yi3dtuXjt6pE0cjJuTg28944H8TjRqANtCjkdWRkVXO+n2N7L Agu9qMr2JMYPYfkNSSovQofdjU0FMH+OeOhg36pFKVioibLjOLM8i+SqsjS9TX/BA2tZ w09DBYOtE4arVxP1Cryj6v3EaBMzTgQJh7mRlfRuGJ726HhSHG41z40hXp/+z1QxJEpC oqKIzOKAiUzW+ArOeMm/MM69O9mR+GSLDfQ4SvSTEyQlLrlWaLApyt7AAuJnCOOu3JLX /TkKLdXZVHP+Ct9OTuVGTcFbOEYCeN81ZV4rHgrhIMXpnZM0Nsd2+lScpIt+X4/362Yd tXlg== X-Gm-Message-State: AOAM533d0jsac+H9Wa566L+pBbUnX9oGLhHIGSMlWZEp7p5DzoQIZz8l 8Tg8OdeuymDlknd1a2ePV2rkn+NX9hX7TA== X-Received: by 2002:a17:902:d102:b029:128:e250:ebca with SMTP id w2-20020a170902d102b0290128e250ebcamr18973068plw.14.1625615387858; Tue, 06 Jul 2021 16:49:47 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 22/36] linux-user/i386: Add vdso and use it for sigreturn Date: Tue, 6 Jul 2021 16:49:18 -0700 Message-Id: <20210706234932.356913-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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" Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in that file for now. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 16 +++- linux-user/i386/signal.c | 39 ++++----- linux-user/i386/Makefile.vdso | 5 ++ linux-user/i386/meson.build | 7 ++ linux-user/i386/vdso.S | 149 ++++++++++++++++++++++++++++++++++ linux-user/i386/vdso.ld | 76 +++++++++++++++++ linux-user/i386/vdso.so | Bin 0 -> 5528 bytes 7 files changed, 271 insertions(+), 21 deletions(-) create mode 100644 linux-user/i386/Makefile.vdso create mode 100644 linux-user/i386/vdso.S create mode 100644 linux-user/i386/vdso.ld create mode 100755 linux-user/i386/vdso.so diff --git a/linux-user/i386/vdso.so b/linux-user/i386/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..7a78ee23182f904f091b3fca9fbb354282372773 GIT binary patch literal 5528 zcmeHLPi$007@yZy=(f)fB#*WG*j?E_y6?5N z#^{0-H&LW0haU9gflC!kh}nzDCPohi3x+=@n+uFeEa>K zZ{~e7lk_(qjEo&M3`1x#g(;-fBg7D#v8VjVkmwT|#cr`hL?Qhcyc0S(7~c-t1Rt9? zCB9ob@Kf9A7ovM_qz1m~e=yMY@P|85#J*HxMzNsBf7S|RNUrf7B)?@DYwUuof;WNr zIZtY}!U_ui0m=H0Ag@vRkEDCXQrj@wNyr!`j41n6$iaZU8+Kp7c3~$1b_(`n!2TY# zrmf=l+9eooBHjVX`FIR^0{JUC8It*27keQ07_t+ri9O<;GKYJ>9`buwo9ibrMj!K7 zqvPdBe=M@2r1Mzg*5cfC@k{T`sVjr&!*?s)4{nz}@BZxhi{(8(?|OJ;{_3+|AIX0L zUD)<{r&F$@FOp4>;uMr1>`%9v45WEbZ z-h2Au;A<_uY50~}d|CKDZSj@hD+hc#VUw_)lX^k1vQcWku;Jpy4?7kkA9Y^p`goIE z_g>_k!Pu=Fa5#GKSoA*I6;jxNumfQS!VZKT2s;pVAnZWcf&XO(?v#GKd}|j!?XrXf zl}`No+i)&bzG$(#TI>l74d!<@+e_1xccf>j@{N@ES&vqgQ@uV&>`xc54~bZtL^MPq zCMTH^QR4sqx-DN3Bu4k+J|fi^-1L!-AV&A&3WX4uf=q>6<8_2zxYtVHM z^tCz*A8RvDFPd{`(s_9}bRO?8`L0fa)OqtNPxh6K0`m=06I~=-%eRE^5GcXf4F}%{ lS&zAV@6z7}RjlGc;WiaTtV7~ELolzpO^Ekp#Q)KGe*q5id-MPR literal 0 HcmV?d00001 -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ec3a854b44..7a598f9f76 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -276,12 +276,24 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en (*regs)[15] = env->regs[R_ESP]; (*regs)[16] = env->segs[R_SS].selector & 0xffff; } -#endif + +/* + * i386 is the only target which supplies AT_SYSINFO for the vdso. + * All others only supply AT_SYSINFO_EHDR. + */ +#define DLINFO_ARCH_ITEMS 1 +#define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); + +#include "vdso.c.inc" + +#define vdso_image_info() &vdso_image_info + +#endif /* TARGET_X86_64 */ #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 -#endif +#endif /* TARGET_I386 */ #ifdef TARGET_ARM diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 9894e7c9ac..8e4677e800 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -313,7 +313,7 @@ get_sigframe(struct target_sigaction *ka, CPUX86State *env, size_t frame_size) void setup_frame(int sig, struct target_sigaction *ka, target_sigset_t *set, CPUX86State *env) { - abi_ulong frame_addr; + abi_ulong frame_addr, retcode_addr; struct sigframe *frame; int i; @@ -335,19 +335,19 @@ void setup_frame(int sig, struct target_sigaction *ka, /* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa_flags & TARGET_SA_RESTORER) { - __put_user(ka->sa_restorer, &frame->pretcode); + retcode_addr = ka->sa_restorer; } 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)); + /* + * This is popl %eax ; movl $,%eax ; int $0x80. + * This is no longer used, but is retained for ABI compatibility. + */ + __put_user(0xb858, (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(0x80cd, (uint16_t *)(frame->retcode+6)); + + retcode_addr = default_sigreturn; } + __put_user(retcode_addr, &frame->pretcode); /* Set up registers for signal handler */ env->regs[R_ESP] = frame_addr; @@ -373,7 +373,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUX86State *env) { - abi_ulong frame_addr; + abi_ulong frame_addr, retcode_addr; #ifndef TARGET_X86_64 abi_ulong addr; #endif @@ -412,22 +412,23 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, /* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa_flags & TARGET_SA_RESTORER) { - __put_user(ka->sa_restorer, &frame->pretcode); + retcode_addr = ka->sa_restorer; } else { #ifdef TARGET_X86_64 /* For x86_64, SA_RESTORER is required ABI. */ goto give_sigsegv; #else - uint16_t val16; - addr = frame_addr + offsetof(struct rt_sigframe, retcode); - __put_user(addr, &frame->pretcode); - /* This is movl $,%eax ; int $0x80 */ + /* + * This is movl $,%eax ; int $0x80 + * This is no longer used, but is retained for ABI compatibility. + */ __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(0x80cd, (uint16_t *)(frame->retcode+5)); + retcode_addr = default_rt_sigreturn; #endif } + __put_user(retcode_addr, &frame->pretcode); /* Set up registers for signal handler */ env->regs[R_ESP] = frame_addr; diff --git a/linux-user/i386/Makefile.vdso b/linux-user/i386/Makefile.vdso new file mode 100644 index 0000000000..42cfc1974b --- /dev/null +++ b/linux-user/i386/Makefile.vdso @@ -0,0 +1,5 @@ +CROSS_CC ?= $(CC) + +vdso.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) -m32 -nostdlib -shared -Wl,-T,vdso.ld -Wl,--build-id=sha1 \ + -Wl,-h,linux-gate.so.1 -Wl,--hash-style=both vdso.S -o $@ diff --git a/linux-user/i386/meson.build b/linux-user/i386/meson.build index ee523019a5..b729d73686 100644 --- a/linux-user/i386/meson.build +++ b/linux-user/i386/meson.build @@ -3,3 +3,10 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +gen = [ + gen_vdso.process('vdso.so', extra_args: ['-s', '__kernel_sigreturn', + '-r', '__kernel_rt_sigreturn']) +] + +linux_user_ss.add(when: 'TARGET_I386', if_true: gen) diff --git a/linux-user/i386/vdso.S b/linux-user/i386/vdso.S new file mode 100644 index 0000000000..6938c577ec --- /dev/null +++ b/linux-user/i386/vdso.S @@ -0,0 +1,149 @@ +/* + * i386 linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + + .balign 16 +__kernel_vsyscall: + .cfi_startproc + int $0x80 + ret + .cfi_endproc + + .globl __kernel_vsyscall + .type __kernel_vsyscall, @function + .size __kernel_vsyscall, . - __kernel_vsyscall + + .balign 16 + .cfi_startproc +__vdso_clock_gettime: + mov $__NR_clock_gettime, %eax + int $0x80 + ret + .cfi_endproc + + .globl __vdso_clock_gettime + .type __vdso_clock_gettime, @function + .size __vdso_clock_gettime, . - __vdso_clock_gettime + + .balign 16 + .cfi_startproc +__vdso_clock_gettime64: + mov $__NR_clock_gettime64, %eax + int $0x80 + ret + .cfi_endproc + + .globl __vdso_clock_gettime64 + .type __vdso_clock_gettime64, @function + .size __vdso_clock_gettime64, . - __vdso_clock_gettime64 + + .balign 16 + .cfi_startproc +__vdso_clock_getres: + mov $__NR_clock_getres, %eax + int $0x80 + ret + .cfi_endproc + + .globl __vdso_clock_getres + .type __vdso_clock_getres, @function + .size __vdso_clock_getres, . - __vdso_clock_getres + + .balign 16 + .cfi_startproc +__vdso_gettimeofday: + mov $__NR_gettimeofday, %eax + int $0x80 + ret + .cfi_endproc + + .globl __vdso_gettimeofday + .type __vdso_gettimeofday, @function + .size __vdso_gettimeofday, . - __vdso_gettimeofday + + .balign 16 + .cfi_startproc +__vdso_time: + mov $__NR_time, %eax + int $0x80 + ret + .cfi_endproc + + .globl __vdso_time + .type __vdso_time, @function + .size __vdso_time, . - __vdso_time + + /* + * While this frame is marked as a signal frame, that only applies + * to how this return address is handled for the outer frame. + * The return address that arrived here, from the inner frame, is + * not marked as a signal frame and so the unwinder still tries to + * subtract 1 to examine the presumed call insn. Thus we must + * extend the unwind info to a nop before the start. + */ + + .balign 16 + .cfi_startproc simple + .cfi_signal_frame + + /* + * For convenience, put the cfa just above eip in sigcontext, + * and count offsets backward from there. Re-compute the cfa + * in the several contexts we have for signal unwinding. + * This is far simpler than the DW_CFA_expression form that + * the kernel uses, and is equally correct. + */ +#define IA32_SIGCONTEXT_cfa 60 +#define IA32_RT_SIGFRAME_sigcontext 164 + + .cfi_def_cfa %esp, IA32_SIGCONTEXT_cfa + 4 + .cfi_offset %eip, -4 + /* err, -8 */ + /* trapno, -12 */ + .cfi_offset %eax, -16 + .cfi_offset %ecx, -20 + .cfi_offset %edx, -24 + .cfi_offset %ebx, -28 + .cfi_offset %esp, -32 + .cfi_offset %ebp, -36 + .cfi_offset %esi, -40 + .cfi_offset %edi, -44 + + nop +__kernel_sigreturn: + popl %eax /* pop sig */ + .cfi_adjust_cfa_offset -4 + movl $__NR_sigreturn, %eax + int $0x80 + + .globl __kernel_sigreturn + .type __kernel_sigreturn, @function + .size __kernel_sigreturn, . - __kernel_sigreturn + + .cfi_adjust_cfa_offset IA32_RT_SIGFRAME_sigcontext - 4 + nop +__kernel_rt_sigreturn: + movl $__NR_rt_sigreturn, %eax + int $0x80 + + .globl __kernel_rt_sigreturn + .type __kernel_rt_sigreturn, @function + .size __kernel_rt_sigreturn, . - __kernel_rt_sigreturn + .cfi_endproc + +/* + * ??? Perhaps add elf notes. E.g. + * + * #include + * ELFNOTE_START(Linux, 0, "a") + * .long LINUX_VERSION_CODE + * ELFNOTE_END + * + * but what version number would we set for QEMU? + */ diff --git a/linux-user/i386/vdso.ld b/linux-user/i386/vdso.ld new file mode 100644 index 0000000000..18937710c9 --- /dev/null +++ b/linux-user/i386/vdso.ld @@ -0,0 +1,76 @@ +/* + * Linker script for linux x86-64 replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +ENTRY(__kernel_vsyscall) + +VERSION { + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_time; + __vdso_clock_getres; + __vdso_clock_gettime64; + }; + + LINUX_2.5 { + global: + __kernel_vsyscall; + __kernel_sigreturn; + __kernel_rt_sigreturn; + local: *; + }; +} + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* ??? We can't really prelink to any address without knowing + something about the virtual memory space of the host, since + that leaks over into the available memory space of the guest. */ + . = SIZEOF_HEADERS; + + /* The following, including the FILEHDRS and PHDRS, are modified + when we relocate the binary. We want them to be initially + writable for the relocation; we'll force them read-only after. */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + .data : { + /* There ought not be any real read-write data. + But since we manipulated the segment layout, + we have to put these sections somewhere. */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text =0x90909090 +} From patchwork Tue Jul 6 23:49:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470642 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5555171ejx; Tue, 6 Jul 2021 17:07:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt3gK8Xfy5GIuw6yHP6nDn7y2AZQCEcKHutz93OIRejKY6W8tdpIlkbEr4gmB3/zdX+WYc X-Received: by 2002:a05:6102:9d5:: with SMTP id g21mr12422711vsi.34.1625616455001; Tue, 06 Jul 2021 17:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616454; cv=none; d=google.com; s=arc-20160816; b=aC3vKg9Pqku/dL2KvL2PYVLabJtf9GK5ICwjLt5cKJAZhTPGFEaVQNGFKln0fjWS2c tF2sbE22nV+3zb5pUCKPWedrLV4q1MnwKR3y0I5OReWKe3mLDab5xUPckfUczbOSqae1 44ql1ST15EfSv1PYmrdpi9bdjdHyNcD30AcZJOyj7YKXYA2ncXw4v0wN/FjVjY8mUXDg W2Zk6LJpPIOe0i35TBDs4/v2F7O3b0Jmwla9k/tOAHsnqTq00SEAyunTwMoGimcRBI/g voi/Fm10rHp1KGVxGUtncZ/xI+Mid4qz8qqv3iWqdpoRDTI+Wuw3IG1a+tfrGACHi3li Jj8g== 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=yZhf1bHNA1vjB+M6QgN/FYYI6NUWFt0z8JMbCm/NEP0=; b=ryDLqpr+0J0sB51xZRQvqPK3RZ7gaSxCGCkOmBicz+MUunTr6aVH4QGtIp2PbBG6rR 1oaBLI4jLlRvPOMYDBdRPAVrmyX0WvkVkYxXGe2NpVYInj7XP1VT1uBXRa4Bg3zbep1p AltB0Dm0NL//0a7qFygZKWdpRqPrbxo/WI9qBe4jv0dNTyopn65zJ+lWWt8Pwq+cojih mK+6EhA0NAmhgFF6mtERd/uAWuecaP1x1c2HSZjkToDARzg7PLlUtpFarGVM5z7+g2nX DiDnN5G2x0dmfm82JA3ZjaYO7Ye70XBfe6hCFcPyebqGKzHR1XT2pUzt4ji6sNSubOcU EQXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jaGl7tzY; 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 r4si631806vsk.1.2021.07.06.17.07.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:07:34 -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=jaGl7tzY; 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]:37722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v6E-0005qj-7e for patch@linaro.org; Tue, 06 Jul 2021 20:07:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upB-0001cS-Tr for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:57 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:43824) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up3-0006fT-KB for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:57 -0400 Received: by mail-pj1-x102d.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso484432pjp.2 for ; Tue, 06 Jul 2021 16:49:49 -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=yZhf1bHNA1vjB+M6QgN/FYYI6NUWFt0z8JMbCm/NEP0=; b=jaGl7tzYKuZQOs0oLhxjhSmwJIzGTOMQYC5e3/J0TUyFzcr75TCqDoEgd5ipGmfhQc v/ATGza0T6fvJis3waXptGUxSeKVk2aC6d0eJf6c2zkFfW0Po33yvhMqXqpI0/KTQeFS k8mktr3I549j2tV2TFJIMWs+06JWiajz6PLoD/yHUhTCJWSnOPfZiFH2dkgIJyS9GdYz BZ50bZeDLmvp4/YgVWqL4EmgcjpsrEywA+A6tfZGJ7BlowLmpULLFTW9VOuOz3+fV24M 7fCcdH4grfMDuQGlltsJ2SeXj26o/UMz4tZbvjo8oyqGri4PXsltpDvmituFoEuRYp8S iEnQ== 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=yZhf1bHNA1vjB+M6QgN/FYYI6NUWFt0z8JMbCm/NEP0=; b=AAOMuOXiWHr2VxQA+idVnVNIBHbFD2a5eaPACVT9NOCKK1zZRNcGBOfdeULOXKH7h/ 9uG1qTyGoq+ZO+elR9Vumv/WzhaxUjt2jCLZnDpD/fhtI1YzufKJs2h9FYT8Zq9J9x1F XqcStUelhTlROwTTgDRLXYw/YnrQtO1FRVzbRmoqoQ9K6xjtci+PVrEcDf1mPRNxVf5U ccmidAYHqkrLlZkypCxgOj2TFEUifDHYCAlLTO3jUfnb2QK4mlEhrhU78tTtv0LQsb/6 +XF/DrlJSOCELCgOoxY32PMudyZ1Bajm8F4Y5kiw0bbpia40H54yjVlTAaGo8EMPT5P1 H/tQ== X-Gm-Message-State: AOAM532cTc5BP6c+vpcB/CZL4UXLvhPhALfZyT5mEoxQwZe0Z0R093C6 LuaRLg42PSBCupHfKp1injW9FxScFzDorQ== X-Received: by 2002:a17:90a:454b:: with SMTP id r11mr21972252pjm.60.1625615388410; Tue, 06 Jul 2021 16:49:48 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 23/36] linux-user/x86_64: Add vdso Date: Tue, 6 Jul 2021 16:49:19 -0700 Message-Id: <20210706234932.356913-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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" Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in that file for now. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 +- linux-user/x86_64/Makefile.vdso | 5 ++ linux-user/x86_64/meson.build | 6 ++ linux-user/x86_64/vdso.S | 122 ++++++++++++++++++++++++++++++++ linux-user/x86_64/vdso.ld | 74 +++++++++++++++++++ linux-user/x86_64/vdso.so | Bin 0 -> 6008 bytes 6 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 linux-user/x86_64/Makefile.vdso create mode 100644 linux-user/x86_64/vdso.S create mode 100644 linux-user/x86_64/vdso.ld create mode 100755 linux-user/x86_64/vdso.so diff --git a/linux-user/x86_64/vdso.so b/linux-user/x86_64/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..0397ef0f4f3c1e7006146a1113d49ba93b7f5042 GIT binary patch literal 6008 zcmeHL&1+m$6hD*6bW%;4w2CP4BTB81(jh6O1S%zMlQ_{f#6U1z)R$>ynhDL!#F>{e zBc*~EB_e)+D;LFL*V5(etQ1Pyzn}dkbd%SaAn>;?%6^jWaE{CPr8VHzi>!?3K4UusflWqFHUv?;pbZZ&6ZWm{5Xkw4) zfrjm0$=yWILlj#N?3!KHCQm$N0}{!1DUWs5Z9Ogqn^pzu=Q?Na_*vME*?L?&pnVV` zbRj^L_ia2EcSA{q2we#9K`n7D&&|xsOK11)tzA92?}KkI-@3ef_h>r#@}PF9=L1wETG zIh`vkywwoTJD07LyrtFB(phgg=ld&#+&yGDS0QIAr8C(~ja=A9`d0Be+lpDm?-Z+wzbL+=*rN{qSP{Z;Vz16gtU3@I>`nII-GF1o+-qvXvjR7w zW!2#(l*>CD)|_>?Rpl0y<6Y5aM>-zpc%b8fjt4p(=y;&xfsP0M=N_nktq$l9=(~~X!zSVZ#>=T*XSUb-q`XJpMT%GxnuO|HC6pPiR-sDdK)5Tek=0tH z{-5z4^$}ylBKE7F?JD<0=rbYM#WKOnXyvM@~$7>4~{e z@MqCxR1j%_qZ^NgLeIz;wHbR#s!}WXnbV4XIlw$?#gdGT&`SMDHYoqURF}MymzLYDdfC-RyEm@l%K2m>XCmhNFpKLXa0uIA#t}e zMYq#_QrpM}AU^=%^Gei9-4y1TcrWal$guVz@4)%_ToZ>v_NdaH`6$Hoc*JPW=bt#C zeGsmX_T0yQ?c36v744ZPBjWjhxb^`n@~rjIo_RGQ^Jvt!?XW3WUn4X>-#bL^lk;;P zBJw`S!Li+XKiPX{%w~fBp~L+fEsI*gnrP4W7!kRRu+VShidqTV^Lt1YST3aS@cOi*#pZ>Q2x M_6IFb{!jLQ0P{>E*#H0l literal 0 HcmV?d00001 -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 7a598f9f76..43c985f318 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -284,12 +284,12 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en #define DLINFO_ARCH_ITEMS 1 #define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); +#endif /* TARGET_X86_64 */ + #include "vdso.c.inc" #define vdso_image_info() &vdso_image_info -#endif /* TARGET_X86_64 */ - #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 diff --git a/linux-user/x86_64/Makefile.vdso b/linux-user/x86_64/Makefile.vdso new file mode 100644 index 0000000000..532c9d6964 --- /dev/null +++ b/linux-user/x86_64/Makefile.vdso @@ -0,0 +1,5 @@ +CROSS_CC ?= $(CC) + +vdso.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) -nostdlib -shared -Wl,-T,vdso.ld -Wl,--build-id=sha1 \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=both vdso.S -o $@ diff --git a/linux-user/x86_64/meson.build b/linux-user/x86_64/meson.build index 203af9a60c..f6a0015953 100644 --- a/linux-user/x86_64/meson.build +++ b/linux-user/x86_64/meson.build @@ -3,3 +3,9 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +gen = [ + gen_vdso.process('vdso.so') +] + +linux_user_ss.add(when: 'TARGET_X86_64', if_true: gen) diff --git a/linux-user/x86_64/vdso.S b/linux-user/x86_64/vdso.S new file mode 100644 index 0000000000..bbd75a79aa --- /dev/null +++ b/linux-user/x86_64/vdso.S @@ -0,0 +1,122 @@ +/* + * x86-64 linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + + .globl __vdso_clock_gettime + .type __vdso_clock_gettime, @function + .balign 16 + .cfi_startproc +__vdso_clock_gettime: + mov $__NR_clock_gettime, %eax + syscall + ret + .cfi_endproc + .size __vdso_clock_gettime, . - __vdso_clock_gettime + +clock_gettime = __vdso_clock_gettime + .weak clock_gettime + + .globl __vdso_clock_getres + .type __vdso_clock_getres, @function + .balign 16 + .cfi_startproc +__vdso_clock_getres: + mov $__NR_clock_getres, %eax + syscall + ret + .cfi_endproc + .size __vdso_clock_getres, . - __vdso_clock_getres + +clock_getres = __vdso_clock_getres + .weak clock_getres + + .globl __vdso_gettimeofday + .type __vdso_gettimeofday, @function + .balign 16 + .cfi_startproc +__vdso_gettimeofday: + mov $__NR_gettimeofday, %eax + syscall + ret + .cfi_endproc + .size __vdso_gettimeofday, . - __vdso_gettimeofday + +gettimeofday = __vdso_gettimeofday + .weak gettimeofday + + + .globl __vdso_time + .type __vdso_time, @function + .balign 16 + .cfi_startproc +__vdso_time: + mov $__NR_time, %eax + syscall + ret + .cfi_endproc + .size __vdso_time, . - __vdso_time + +time = __vdso_time + .weak time + + + .globl __vdso_getcpu + .type __vdso_getcpu, @function + .balign 16 + .cfi_startproc +__vdso_getcpu: + /* + * ??? There is no syscall number for this allocated on x64. + * We can handle this several ways: + * + * (1) Invent a syscall number for use within qemu. + * It should be easy enough to pick a number that + * is well out of the way of the kernel numbers. + * + * (2) Force the emulated cpu to support the rdtscp insn, + * and initialize the TSC_AUX value the appropriate value. + * + * (3) Pretend that we're always running on cpu 0. + * + * This last is the one that's implemented here, with the + * tiny bit of extra code to support rdtscp in place. + */ + xor %ecx, %ecx /* rdtscp w/ tsc_aux = 0 */ + + /* if (cpu != NULL) *cpu = (ecx & 0xfff); */ + test %rdi, %rdi + jz 1f + mov %ecx, %eax + and $0xfff, %eax + mov %eax, (%rdi) + + /* if (node != NULL) *node = (ecx >> 12); */ +1: test %rsi, %rsi + jz 2f + shr $12, %ecx + mov %ecx, (%rsi) + +2: xor %eax, %eax + ret + .cfi_endproc + .size __vdso_getcpu, . - __vdso_getcpu + +getcpu = __vdso_getcpu + .weak getcpu + +/* + * ??? Perhaps add elf notes. E.g. + * + * #include + * ELFNOTE_START(Linux, 0, "a") + * .long LINUX_VERSION_CODE + * ELFNOTE_END + * + * but what version number would we set for QEMU? + */ diff --git a/linux-user/x86_64/vdso.ld b/linux-user/x86_64/vdso.ld new file mode 100644 index 0000000000..6630193079 --- /dev/null +++ b/linux-user/x86_64/vdso.ld @@ -0,0 +1,74 @@ +/* + * Linker script for linux x86-64 replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6 { + global: + clock_gettime; + __vdso_clock_gettime; + gettimeofday; + __vdso_gettimeofday; + getcpu; + __vdso_getcpu; + time; + __vdso_time; + clock_getres; + __vdso_clock_getres; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* ??? We can't really prelink to any address without knowing + something about the virtual memory space of the host, since + that leaks over into the available memory space of the guest. */ + . = SIZEOF_HEADERS; + + /* The following, including the FILEHDRS and PHDRS, are modified + when we relocate the binary. We want them to be initially + writable for the relocation; we'll force them read-only after. */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + .data : { + /* There ought not be any real read-write data. + But since we manipulated the segment layout, + we have to put these sections somewhere. */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text =0x90909090 +} From patchwork Tue Jul 6 23:49:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470638 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5554018ejx; Tue, 6 Jul 2021 17:06:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwljkdnodj6qQqcP2fT4t8LOAdlYSXy8A+ljMti6Uh/JIj6ShHS1kMulNdt/Ag4DUvdpQlU X-Received: by 2002:a05:6402:28b6:: with SMTP id eg54mr448826edb.216.1625616363122; Tue, 06 Jul 2021 17:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616363; cv=none; d=google.com; s=arc-20160816; b=TT8wbDSgR3pMIB5qVNE0YRYErFBcuAL7dgOZ2i8zJSzt3iCqzVfIYWkEFhNwsaSaCY gLGZlztRI1CWFgUOwbCc8XGcgA5b7Ow05YEAYbisxEdC82zcoIJilTAWJpnxvz2wsuSo BuxzlXPQZees5JL+R9FN6Qv+drpg+Az/SltTb7pIIYHVn6Ti//g8cQPGfX4Mf6n8eXTp yVeKFBgxXqylfODRVe9mw5dwpOr8oE/qTJ4bBOWpoBntX4C0AB6vzeSdvobdDase2q6i wXEBcYpch30n9eM/5PXfIvlewQcYA58XOu/JXb7+6AqUIDAqBb+neBAO5J5N5+koWicN LGag== 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=Xpu2YK19uuJHVJ3NNjszM1h9FJEm/LgeiKDUdqCp49o=; b=E3asyaTYwSxtHlSA2LJkTOstUYkJOxLUkUBec0HFQKilo5YyRxz67Dj5AuSkK3NZBu fwmDf+kpyHNc93vpCZW7FZ0Tx3KzND7YC2vjpelKEmj/M+LKj0DeayiapAf5wQbIEFDz PM71N87AC7VzdVLVZgYC3AVwUYkJSq2gVNuE+pCdeG+KUH9KKLd7DOdLElcoW9NJ6NCm X96tMWNIVfJLGIkhm8N99LsQRtpOEsuJkcR+eBXFZ1F7U1d2r0dVL/PzDzWESxT1GrnC p0l0w+TygC5VQ13w/cDaVllLsqeutXz/LQwe9Kz0+PDO3ZwYXGWpCPU9bMR9YcDU/mup xZNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QZHdIJQI; 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 hs36si7271503ejc.198.2021.07.06.17.06.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:06:03 -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=QZHdIJQI; 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]:34606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v4j-0003pO-Tm for patch@linaro.org; Tue, 06 Jul 2021 20:06:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upK-0001py-SQ for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:08 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:36632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up4-0006fc-8O for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:06 -0400 Received: by mail-pg1-x532.google.com with SMTP id f5so415521pgv.3 for ; Tue, 06 Jul 2021 16:49:49 -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=Xpu2YK19uuJHVJ3NNjszM1h9FJEm/LgeiKDUdqCp49o=; b=QZHdIJQILNoCgXECf2yblJwbu0a0J8/Rp9LCPm/VoKRj9Jt+Ldwdt0oFJw6JVPVM/O wwekA/tq1OS1vFg12DWROVSZs/8gDyHxDE27NmW5zy+m7iLmHsPVUa8/zgR2AtopsPRb qzGUrNMHuV3fPV+4yx0McXMESn6tJNZgZJ3vjXExMZKC4W0KzXglQdD4AuCI6YRy7DGc 8vkrX2eNiFCpiTynU5+m9HWuKENUm3GfNVIdUQa9AuvFv5Vz5EAAnrbhFJmn0+iy5dSj g8ZSJ1lZFq05yielQmepB1KXHSYnnZyYlgBcFlHyFLrgPnImX1OtwWxRX+Y8nhRqY7jh s5Lg== 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=Xpu2YK19uuJHVJ3NNjszM1h9FJEm/LgeiKDUdqCp49o=; b=N3rXOeuNlCu2XkqxcGjRUhfTXxkjgpmYYYevR2F2m3I7RSyzcUWrbx3CxdkgHyAnX3 wG6R9rSUcPIAOlE90qWK3C0jJi9h7K5o1mlhgiMgxTgnAiFYjwCnHwlPMbVlVrlNjgv2 Bwd6orbLO+nLB2dUgd86RyqUzyyU0uUpk8m5gG/YZnMf+Xspeyrhw7pDQA+nhUAlBeBx oV0P3dsj/hhRAoaJ/tYWbE8+FBiJVBNV0t+yvFRjnSIw49GwT2yyELDfOKLcPRq3aVG0 fsXiate0PKqnBHba45GS1Y0BjKxzCzOSr5LP00FOfd8OEDepX+IOxUlmGdIzwfoIa/Pu PHng== X-Gm-Message-State: AOAM533dWiJxKh3Qq+0GNzZfoGJdKc2ty8dkEDCCKKolPV4sgh8Fp4l8 vrd1KWYuZVWIHcK7RGrRPNr+7/JvFNiAbw== X-Received: by 2002:a63:e316:: with SMTP id f22mr23117740pgh.100.1625615389016; Tue, 06 Jul 2021 16:49:49 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 24/36] linux-user/m68k: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:20 -0700 Message-Id: <20210706234932.356913-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create and record the two signal trampolines. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/m68k/target_signal.h | 2 ++ linux-user/m68k/signal.c | 47 +++++++++++++++------------------ 2 files changed, 24 insertions(+), 25 deletions(-) -- 2.25.1 diff --git a/linux-user/m68k/target_signal.h b/linux-user/m68k/target_signal.h index d096544ef8..94157bf1f4 100644 --- a/linux-user/m68k/target_signal.h +++ b/linux-user/m68k/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 /* M68K_TARGET_SIGNAL_H */ diff --git a/linux-user/m68k/signal.c b/linux-user/m68k/signal.c index d06230655e..b4fade1ed6 100644 --- a/linux-user/m68k/signal.c +++ b/linux-user/m68k/signal.c @@ -38,7 +38,6 @@ struct target_sigframe int sig; int code; abi_ulong psc; - char retcode[8]; abi_ulong extramask[TARGET_NSIG_WORDS-1]; struct target_sigcontext sc; }; @@ -75,7 +74,6 @@ struct target_rt_sigframe int sig; abi_ulong pinfo; abi_ulong puc; - char retcode[8]; struct target_siginfo info; struct target_ucontext uc; }; @@ -129,7 +127,6 @@ void setup_frame(int sig, struct target_sigaction *ka, { struct target_sigframe *frame; abi_ulong frame_addr; - abi_ulong retcode_addr; abi_ulong sc_addr; int i; @@ -151,16 +148,7 @@ void setup_frame(int sig, struct target_sigaction *ka, } /* Set up to return from userspace. */ - - retcode_addr = frame_addr + offsetof(struct target_sigframe, retcode); - __put_user(retcode_addr, &frame->pretcode); - - /* moveq #,d0; trap #0 */ - - __put_user(0x70004e40 + (TARGET_NR_sigreturn << 16), - (uint32_t *)(frame->retcode)); - - /* Set up to return from userspace */ + __put_user(default_sigreturn, &frame->pretcode); env->aregs[7] = frame_addr; env->pc = ka->_sa_handler; @@ -287,7 +275,6 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, { struct target_rt_sigframe *frame; abi_ulong frame_addr; - abi_ulong retcode_addr; abi_ulong info_addr; abi_ulong uc_addr; int err = 0; @@ -324,17 +311,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, } /* Set up to return from userspace. */ - - retcode_addr = frame_addr + offsetof(struct target_sigframe, retcode); - __put_user(retcode_addr, &frame->pretcode); - - /* moveq #,d0; notb d0; trap #0 */ - - __put_user(0x70004600 + ((TARGET_NR_rt_sigreturn ^ 0xff) << 16), - (uint32_t *)(frame->retcode + 0)); - __put_user(0x4e40, (uint16_t *)(frame->retcode + 4)); - - /* Set up to return from userspace */ + __put_user(default_rt_sigreturn, &frame->pretcode); env->aregs[7] = frame_addr; env->pc = ka->_sa_handler; @@ -410,3 +387,23 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + void *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 4 + 6, 0); + assert(tramp != NULL); + + default_sigreturn = sigtramp_page; + + /* moveq #,d0; trap #0 */ + __put_user(0x70004e40 + (TARGET_NR_sigreturn << 16), (uint32_t *)tramp); + + default_rt_sigreturn = sigtramp_page + 4; + + /* moveq #,d0; notb d0; trap #0 */ + __put_user(0x70004600 + ((TARGET_NR_rt_sigreturn ^ 0xff) << 16), + (uint32_t *)(tramp + 4)); + __put_user(0x4e40, (uint16_t *)(tramp + 8)); + + unlock_user(tramp, sigtramp_page, 4 + 6); +} From patchwork Tue Jul 6 23:49:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470711 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5474942jao; Tue, 6 Jul 2021 17:11:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8zWSCZiorksNBtiNCqDLQdCubXHvS6o091DO//md/gZji313LQDNMtdODNMheB3HkyQqH X-Received: by 2002:a05:6102:db:: with SMTP id u27mr7418094vsp.41.1625616710989; Tue, 06 Jul 2021 17:11:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616710; cv=none; d=google.com; s=arc-20160816; b=UInB3Y69+WPzM0ruRRB3ZkhQc76VWzi9YXXtHxmbIQcaKPj8AkfhAE1vtGRSPu5sVj mdMi+TyB2YQ380lc5Gd3ZfTVbg+wj223xMM/sPE16ryLN8ihEsWCBR7pPdl+YPEI+hVa bhbNeelsJIc1FTi689XRAluAnCcZZSsf7YR6rMP/nbnbJfnpYP948dVBG9qYEMNL2J/d wUgivtBQJqFd4FgQZ48E/ufWVmEvmbkMEceHLo46NiyJr6u0eyxdGKM2oHUPmGrCHas8 wVkbdDaZTkfs3E9j3/bksfr9Nmh6emi7n33J3u6Y3ktm5BhzQ7cSKesAGE6Ac0Rr+rRN m/Eg== 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=TA71KdY0ADT8/xQwWyVtukyaxSrQMBNG8W0Sl0VZeBM=; b=U0hWMgRi8i1XFY/WmC0Xbc5qyngFu+2Tm2vd7WsKCrSPGyRCCpu6wrNSiJbOewWaYa sGFeby+1z8PTXhMT2NL4BzhQ5EmKF2jWUd0fWlTa84TNS0YtRnKnZckr8ix6eX58MpCg j0KxqgggWpzb9ZWQnoEieUQMutXkpZXIVDShDX+RIYkjjcOhYZ0LCbDK1Ij50HH1KdtH QB1QqJDhv4gm+28ftCfFrOr5kwns0dTelYaPTuJvAwIALU3jB+k424d6e/+L2c8AODLa egzTolKSCqvP1bCusw9n5NlIP4VkDFBZfLShQG6KHEUTRHXyesoK/Ye3IOf7rdtfdJLS oWvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uGTxjkZe; 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 l6si11131970vsp.7.2021.07.06.17.11.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:11:50 -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=uGTxjkZe; 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]:54798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0vAM-0008WG-DP for patch@linaro.org; Tue, 06 Jul 2021 20:11:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upJ-0001pB-LE for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:06 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:37827) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up4-0006fk-UR for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:05 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 22-20020a17090a0c16b0290164a5354ad0so2565225pjs.2 for ; Tue, 06 Jul 2021 16:49:50 -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=TA71KdY0ADT8/xQwWyVtukyaxSrQMBNG8W0Sl0VZeBM=; b=uGTxjkZeh/eQV/fD0Uw2pfruz52ZtfAbIYdKNopyxuwqTtj9Q/7r++tuLg0gsgy8s/ igs7MOUmkX+EML5WaXupNTkLRZn3JB0DlL1iNBuVuLgIzVHfaLs2Kg2T/57P37uulxe4 0ZUTlGB2g0HwL/uvqO5bj8hRhlCuF/c7I8A4r9iOrdi+10nbVKAtELb2/7lSankh2rD1 /LWBrdLksOlF1Lg/CxgUu6c0qGht7AxekQQZ3feZdmKyWpWnHYlluc6aQV1nN8okg1sA 48t2+/cUUqUWvddX8shSdpONPcjFREh+GiIdtgAQAWM0FtJxPhvIE70WI/VpD9Hmrati Uy/w== 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=TA71KdY0ADT8/xQwWyVtukyaxSrQMBNG8W0Sl0VZeBM=; b=Iv07GgCdO1Od/Tur0pHQuFgdCSH5o90driPuJaqfj8Q20n3afiz9mOlrUNQEI+DHRZ 2oVts4+F6TGpojgvFFfIY4Df3wzgXTGRHSxLW+iIaMHKjZNOKLBuOSInd0HsbxXYuM4s JVWzKpok2i7jvE59rn5V6HdI/qvuW1DiI1qGxdgxLdG4pThn5jAdxmRxsRbFN3UtBslZ OYyMgkRw1AtHF7L/C5h06f+7VpOrSagTMRiC2DAy3vME2e5l655b3ulzxjP1xDb5soUk SiOoiGdpjWhSJ9xZBJmZwVwmcL3K4Dq7cj00MfSUikmkUOM4blfOq4V2gOr379I7++mU TleA== X-Gm-Message-State: AOAM531LzmUrz0n9zn6fq51gU8SfZ5glyOymPqLD0v7678ThkHM0RmNg CMwyD4lM7hfUxYsniIgla6+npl3pQBDWBQ== X-Received: by 2002:a17:90a:c484:: with SMTP id j4mr19842800pjt.218.1625615389469; Tue, 06 Jul 2021 16:49:49 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 25/36] linux-user/microblaze: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:21 -0700 Message-Id: <20210706234932.356913-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.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=unavailable 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: "Edgar E . Iglesias" , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create and record the rt signal trampoline. Cc: Edgar E. Iglesias Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/microblaze/target_signal.h | 2 ++ linux-user/microblaze/signal.c | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) -- 2.25.1 diff --git a/linux-user/microblaze/target_signal.h b/linux-user/microblaze/target_signal.h index 1c326296de..e8b510f6b1 100644 --- a/linux-user/microblaze/target_signal.h +++ b/linux-user/microblaze/target_signal.h @@ -21,4 +21,6 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif /* MICROBLAZE_TARGET_SIGNAL_H */ diff --git a/linux-user/microblaze/signal.c b/linux-user/microblaze/signal.c index 4c483bd8c6..aa27454931 100644 --- a/linux-user/microblaze/signal.c +++ b/linux-user/microblaze/signal.c @@ -160,17 +160,11 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, /* Kernel does not use SA_RESTORER. */ - /* addi r12, r0, __NR_sigreturn */ - __put_user(0x31800000U | TARGET_NR_rt_sigreturn, frame->tramp + 0); - /* brki r14, 0x8 */ - __put_user(0xb9cc0008U, frame->tramp + 1); - /* * Return from sighandler will jump to the tramp. * Negative 8 offset because return is rtsd r15, 8 */ - env->regs[15] = - frame_addr + offsetof(struct target_rt_sigframe, tramp) - 8; + env->regs[15] = default_rt_sigreturn - 8; /* Set up registers for signal handler */ env->regs[1] = frame_addr; @@ -219,3 +213,19 @@ long do_rt_sigreturn(CPUMBState *env) force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 8, 0); + assert(tramp != NULL); + + /* + * addi r12, r0, __NR_rt_sigreturn + * brki r14, 0x8 + */ + __put_user(0x31800000U | TARGET_NR_rt_sigreturn, tramp); + __put_user(0xb9cc0008U, tramp + 1); + + default_rt_sigreturn = sigtramp_page; + unlock_user(tramp, sigtramp_page, 8); +} From patchwork Tue Jul 6 23:49:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470636 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5553752ejx; Tue, 6 Jul 2021 17:05:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIJnjmomoNAZ2uMFjb+yuIrLp5NgzTVB3rdDiPqUOXmXlRR9niUD/2HMZtZ54VcFv8b1lq X-Received: by 2002:a17:906:7315:: with SMTP id di21mr20647193ejc.511.1625616339422; Tue, 06 Jul 2021 17:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616339; cv=none; d=google.com; s=arc-20160816; b=cU1/NJeMXGEXIzeCeBGMRMNrdEJrYuySzit+FaET8dzJ+H7LoVuM030Q3aCoj9VFrj JqN1B14esfLn3g21nBE4SmJivToBxg565q1BWxijwO8vvPKT0aT2MjkYYdelc9rg4LqJ 6da/6WJrY+TzmNX+bdeySSsrkpVdPDH6vB+LpHvbsW+lyhLF8Arv7rg/EBifOlbUanfy sJ56Q3yh7nBig7kV2XJR3Z28OlswJi5cxWSBSZsJkgGsCk42pPlUyVYXecS6sQytEF1/ MKctLBf+a1D4R01eemPkZmN4fYLQJmbL3GjhZu93nCyNMDSdpeBGNUUZm59jXCQ+rCrO lXtQ== 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=pS8B9+yNUG9KtrWf2HcmVsU4MbTu2x5l7ztmhUnsA5Q=; b=LOCC4iNuDUrSiUcvkMRJhYDVBps1BFybSOTI2+IPYhXgGSjpYW/YXiEruun5j1zg9C DbVLotMfHPvi7w/IhDhiCBlAjIRp3OHED/apRaBGcZ9Jkd7BtR3QDY67+/0NA4idv1PG OQOfHZzhEhCI8g80iTpVQIodS1lwU72AyNzmslddyF59IVki5rpq7UAcH+IGdoHxujnL +cbQOdeWLvnmW8werbgB0j5GSjot+kcJQp+s6Q2WO/M2LnsNXZI0lDRATvBPKJ8sBB9V 3tUDoRnNm/mpRLplZPlvRbD02T20zTJoHZORhD1NmP6pH2VLNv4I1UE9IXR3enWEKmva 3rwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=O9IpJhBV; 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 em21si15628612ejc.542.2021.07.06.17.05.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:05:39 -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=O9IpJhBV; 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]:33310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v4M-0002zK-Gp for patch@linaro.org; Tue, 06 Jul 2021 20:05:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upE-0001ia-5c for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:00 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:39933) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up5-0006fs-A3 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:59 -0400 Received: by mail-pg1-x533.google.com with SMTP id a2so403205pgi.6 for ; Tue, 06 Jul 2021 16:49:50 -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=pS8B9+yNUG9KtrWf2HcmVsU4MbTu2x5l7ztmhUnsA5Q=; b=O9IpJhBV0pM2AireE/hhxFlMqc2x2lHT4FFGgy17yDI1SjD5nVzFKR/uj04LCRq9/e TkDbZDm3HryeHYseCZ7L5WyW76n18p6Chy4V669QjE7nWJupoUwP0hX7S9CcW81aHSP5 sqgnI/gefuDU2TKAO4E8HKBeMiC1dFKZtEBIcUNNX9zaHtUnvrkQQRmQzva0ce1nm89H bcriXsA9qg36DV62V1eocs9DX45r8x30xsdriYdmPx6T9TWY5sTlhGde7i871J+GWFGT waVLxoWwEJblgCa3167t90Uw/tcejIOBDs56htP5xPH7gYm0/JywRB4ft/J5o8E7JdVk sVZA== 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=pS8B9+yNUG9KtrWf2HcmVsU4MbTu2x5l7ztmhUnsA5Q=; b=ELCTzw3pnUznC6QS20tPU4PltjD9Qv/hWpSgxgIM4K0gKnFMavp51/ejeRYMc+cgWc AkxwO5ADg2hacnuZ8QWuOcefEShjaSibbQFR8eME/oFNPB7qc1hIsjMHZErXp7WcYtG4 tXZKMWNseMCcpzLwHxnVTAFIXS5PPKZ7m8cgr5erCo/SEGhz42z3PyQcg4ctBbl7c+Ut r6Yy7XTANFv7N0Eoz2vyzTHoX5Y8puNmMGDEp7Yo9DMxxoinScFW1WVTAP6RJifdKgVE lDTdU32FU7DivLzozvIxyGI+6MfYlnpmCWyETjyIP4lT7beUaWM/agBgaf+8fOo8GDZB KE1g== X-Gm-Message-State: AOAM531HMD/+Z8v0gdTjseAxy84OJvyWy37c9v1o/f6MxMfkJuSyVFVd cnKfJgROch+alAvs/raRAGDWwEGwYywXQA== X-Received: by 2002:aa7:8244:0:b029:2ec:968d:c1b4 with SMTP id e4-20020aa782440000b02902ec968dc1b4mr22362485pfn.32.1625615390052; Tue, 06 Jul 2021 16:49:50 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 26/36] linux-user/mips: Tidy install_sigtramp Date: Tue, 6 Jul 2021 16:49:22 -0700 Message-Id: <20210706234932.356913-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.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, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The return value is constant 0, and unused as well -- change to void. Drop inline marker. Change tramp type to uint32_t* for clarity. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/mips/signal.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) -- 2.25.1 diff --git a/linux-user/mips/signal.c b/linux-user/mips/signal.c index e6be807a81..7cad7526ea 100644 --- a/linux-user/mips/signal.c +++ b/linux-user/mips/signal.c @@ -86,10 +86,8 @@ struct target_rt_sigframe { }; /* Install trampoline to jump back from signal handler */ -static inline int install_sigtramp(unsigned int *tramp, unsigned int syscall) +static void install_sigtramp(uint32_t *tramp, unsigned int syscall) { - int err = 0; - /* * Set up the return code ... * @@ -99,7 +97,6 @@ static inline int install_sigtramp(unsigned int *tramp, unsigned int syscall) __put_user(0x24020000 + syscall, tramp + 0); __put_user(0x0000000c , tramp + 1); - return err; } static inline void setup_sigcontext(CPUMIPSState *regs, From patchwork Tue Jul 6 23:49:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470613 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5551942ejx; Tue, 6 Jul 2021 17:03:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNjmGmYe7D0kLfF1F4niPquY2HACD9vavoerC2CfYt4khHXw2umJUmk2G0cJnzYbWMTC9c X-Received: by 2002:a05:6402:5114:: with SMTP id m20mr26599967edd.174.1625616190210; Tue, 06 Jul 2021 17:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616190; cv=none; d=google.com; s=arc-20160816; b=giUrpT+iFyBN1MwopF0Yb+tJtbTmzaJFs5Jmy+Qy/Vy1RM/2EitTsPV+7RPkxE4rFP 44cAVbn+n0FfCLGdkMt429MqnmYiJ0KzV5y0QHNGNSymU5GGKsIVhgJ0Qo70oJD4+u0y Zjjz0hgx1Yqoj9WtZE2OXssiuHlA2S2qOQgGjWRO2HscLtWGnqMy4/i7TmXAWf+lVMIC 4jQiNdHWZXt78uSU1nKcRHOPnJ8gdq1twhCLZiIZxSuspwwj0gSlCO47tFYU/JQA7fuz pv3arFyDbY8hvyFKQ0ScteP0R3J25RBHlhHRTLi5vd6IFX19i22Cwlke1RXlETWlG0pg RnWA== 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=fJ2heq9/ybEPRov+oRcE6gMbBb+FglnKkmzlhd1SVGQ=; b=wGDNgjFMDEArzST9s/WR3QlMD1G2YMAaEdypsq+o6Fa1q3nPRkK+hbeONCmp35rbD8 mEgxObzdE38PpCwpzitAfwq+iWRUpvBpVYqH7t/uFfKaEE8ZN1M6VOijnZGv9EDLd8qH nuWB7mV5ThpJPs7FcaZRFpWcBM+RMGR9aOanFv/8f4M5AnxqkwXcXzhHl3OnkQSVffdj E1K4k20439iXxnqKPq+V53Vzq+WACiXzgzJ2U0z+6sJsOUrenT7db6oO/ADvzVZMsWsD xKe6AMR5r+G0ccAczjpWhJNPBY4GcB77JQDS/uh3x4OpAbofNTtoi8t/otGbQAxaCrq4 rnAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=E9K+SH4U; 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 eb13si19502674edb.245.2021.07.06.17.03.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:03:10 -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=E9K+SH4U; 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]:52948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v1x-0005bY-61 for patch@linaro.org; Tue, 06 Jul 2021 20:03:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upD-0001hD-Ih for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:59 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:37828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up5-0006fz-SS for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:59 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 22-20020a17090a0c16b0290164a5354ad0so2565252pjs.2 for ; Tue, 06 Jul 2021 16:49:51 -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=fJ2heq9/ybEPRov+oRcE6gMbBb+FglnKkmzlhd1SVGQ=; b=E9K+SH4Unbda+auBY33R347EmbKk1XZsC8gWxhGImBUvaDzupvIFTd6dJM95nUe22p wvyUmL5XKXQTfxYB9ugcD7YRohaAqfYGQt2nDl3OmUXSumWXEVlQzYXkeNwqFSlizpni D02NRXegqZIOiuAjzrwMIWWNKN6EeEWbuGeQs62fJkiRRNDuhqZBc2XIWFba+84frKM+ zNJor1SXm5HCvmoxYK06D4x9ibK7XJD7MOnxAjgs4XDan8DPeuA0pAwc/ten/kjZ8QDU 7Nb7da/eA9FbfKLimyuSXEVdyCvJ35sdxwfN9EMymhRXhE1b4ibUjxKuShEWNG1pzKvS vb+Q== 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=fJ2heq9/ybEPRov+oRcE6gMbBb+FglnKkmzlhd1SVGQ=; b=c+gxOys8Qvon7bSO8hQBg5q3N75zDCX3CD+4NNAsG8v32wnbCeipffRbgnCMc+PhYt ZkpYhgALrpafKyZ5K8QX85zwQfUABTQmlI2zkC/Zd1ww3RoZwUvN4AXBUN/ZoP72429t /SbJr9SM0/WzYQS53t0b0JxsY/wwywBAl4Pcb6K52GoETVYwgDxHt0lJhvyuPU6TOomU VMD8e5P08rSqQMomkqR9oKQA6Pto76/dLv6yNYIAyt/kL0k3eOXCsD9N6SnNvpdA+2if x/ojFp6P6q7ZncW/Nzmh4t/uHbi17ZdHSBg38y/1KZ2kf0QoaTVmx7HpIEVGC8VmEEs4 hu+Q== X-Gm-Message-State: AOAM533S4oECFTmexL3w3b/RXM/mKmOgL+TwMmHjCbBau7RR9qMeGCu4 Qxxk8ZK5r0Cz7dv3q9Gmk3VnEGtETuD8VQ== X-Received: by 2002:a17:90b:806:: with SMTP id bk6mr649448pjb.13.1625615390675; Tue, 06 Jul 2021 16:49:50 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 27/36] linux-user/mips: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:23 -0700 Message-Id: <20210706234932.356913-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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, =?utf-8?q?Philippe_Mathieu-?= =?utf-8?b?RGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create and record the two signal trampolines. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/mips/target_signal.h | 1 + linux-user/mips64/target_signal.h | 2 ++ linux-user/mips/signal.c | 34 ++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) -- 2.25.1 diff --git a/linux-user/mips/target_signal.h b/linux-user/mips/target_signal.h index d521765f6b..780a4ddf29 100644 --- a/linux-user/mips/target_signal.h +++ b/linux-user/mips/target_signal.h @@ -73,6 +73,7 @@ typedef struct target_sigaltstack { /* compare linux/arch/mips/kernel/signal.c:setup_frame() */ #define TARGET_ARCH_HAS_SETUP_FRAME #endif +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 /* bit-flags */ #define TARGET_SS_AUTODISARM (1U << 31) /* disable sas during sighandling */ diff --git a/linux-user/mips64/target_signal.h b/linux-user/mips64/target_signal.h index d857c55e4c..275e9b7f9a 100644 --- a/linux-user/mips64/target_signal.h +++ b/linux-user/mips64/target_signal.h @@ -76,4 +76,6 @@ typedef struct target_sigaltstack { /* compare linux/arch/mips/kernel/signal.c:setup_frame() */ #define TARGET_ARCH_HAS_SETUP_FRAME #endif +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif /* MIPS64_TARGET_SIGNAL_H */ diff --git a/linux-user/mips/signal.c b/linux-user/mips/signal.c index 7cad7526ea..a3db08bfec 100644 --- a/linux-user/mips/signal.c +++ b/linux-user/mips/signal.c @@ -208,8 +208,6 @@ void setup_frame(int sig, struct target_sigaction * ka, goto give_sigsegv; } - install_sigtramp(frame->sf_code, TARGET_NR_sigreturn); - setup_sigcontext(regs, &frame->sf_sc); for(i = 0; i < TARGET_NSIG_WORDS; i++) { @@ -230,7 +228,7 @@ void setup_frame(int sig, struct target_sigaction * ka, regs->active_tc.gpr[ 5] = 0; regs->active_tc.gpr[ 6] = frame_addr + offsetof(struct sigframe, sf_sc); regs->active_tc.gpr[29] = frame_addr; - regs->active_tc.gpr[31] = frame_addr + offsetof(struct sigframe, sf_code); + regs->active_tc.gpr[31] = default_sigreturn; /* The original kernel code sets CP0_EPC to the handler * since it returns to userland using eret * we cannot do this here, and we must set PC directly */ @@ -304,8 +302,6 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, goto give_sigsegv; } - install_sigtramp(frame->rs_code, TARGET_NR_rt_sigreturn); - tswap_siginfo(&frame->rs_info, info); __put_user(0, &frame->rs_uc.tuc_flags); @@ -334,11 +330,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, env->active_tc.gpr[ 6] = frame_addr + offsetof(struct target_rt_sigframe, rs_uc); env->active_tc.gpr[29] = frame_addr; - env->active_tc.gpr[31] = frame_addr - + offsetof(struct target_rt_sigframe, rs_code); - /* The original kernel code sets CP0_EPC to the handler - * since it returns to userland using eret - * we cannot do this here, and we must set PC directly */ + env->active_tc.gpr[31] = default_rt_sigreturn; + + /* + * The original kernel code sets CP0_EPC to the handler + * since it returns to userland using eret + * we cannot do this here, and we must set PC directly + */ env->active_tc.PC = env->active_tc.gpr[25] = ka->_sa_handler; mips_set_hflags_isa_mode_from_pc(env); unlock_user_struct(frame, frame_addr, 1); @@ -378,3 +376,19 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 * 8, 0); + assert(tramp != NULL); + +#ifdef TARGET_ARCH_HAS_SETUP_FRAME + default_sigreturn = sigtramp_page; + install_sigtramp(tramp, TARGET_NR_sigreturn); +#endif + + default_rt_sigreturn = sigtramp_page + 8; + install_sigtramp(tramp + 2, TARGET_NR_rt_sigreturn); + + unlock_user(tramp, sigtramp_page, 2 * 8); +} From patchwork Tue Jul 6 23:49:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470664 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5473142jao; Tue, 6 Jul 2021 17:09:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxohCppWSdlpl8NojwfoQUc89YkfS5jbFAk7+D5N8tG1+8QeSen51+RAnPb8CwjcwZH9q73 X-Received: by 2002:a9f:326c:: with SMTP id y41mr7552252uad.52.1625616540547; Tue, 06 Jul 2021 17:09:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616540; cv=none; d=google.com; s=arc-20160816; b=Ml90v3z0JPhvI5bZEwYs9K1TQGsj0JphB9Q89sX2i8jPtSJgnYCuo30fGrZoTJln55 MPZswBCuvdIuu9md6iqAyRNeg/rWWwvL9k9rWS9PpJf1l8MBfX246n5mkU+BF8AJIKtB MuDB2JvYNXxGRv/nMrqb9Xjy+YukCv9M4mhhkz5lb4Fo9qR9dTV/ORtQreLdZfJvVjH2 57JSD8+8ouT/P22irZUlDrQy63gXGXJFd5a+fAATw+vQ5koWOPa8qnwWQg8/gAQ2P4R7 oNYgmPeyGx83lMVifCivBRqwfhCSLBJfzKVPXaeuCQfRbiH5ITNFX/eyIA7JqM9U6XEx j2Jw== 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=lxt2TIMgKbMWBeD96IyYiDNX06PY6klS8vx7ZxbBwqE=; b=OeGSFW2A6pGlXxunoFLLrU+3TlpePqa3d/X5ktd8maP8L0CXI40syGPqS0rm4p75kK n10gKBwWawzQTgsOPjRCac4tZQjl3hfFOTqtBs/BCLclUgcvly9AOP8guTqiV5gT+wN9 90ul1xfuI5xR6EUXA1l556B/3Xg/9g5Z6xw2/xABE0wkObPm9nmwiqHH5AAyuOlcKDPs eSvCIULI6nztelYJhDXN4/vt6TUSkJj9h0oxPP/C1SnHUO/b0/tE4XJ26sNnBWLnPjFb KzP0KhWqGCHBz5s2FtuO5M7RnHvDGJSsTy0yCHZHXW5TEhjsYnKnqgqfZxJJtAmQArsm MHVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RuNv7WsP; 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 l13si5705088vsb.180.2021.07.06.17.09.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:09:00 -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=RuNv7WsP; 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]:46516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v7b-000393-Vf for patch@linaro.org; Tue, 06 Jul 2021 20:08:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upJ-0001pC-ND for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:06 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:39935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up7-0006g7-6x for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:05 -0400 Received: by mail-pg1-x535.google.com with SMTP id a2so403244pgi.6 for ; Tue, 06 Jul 2021 16:49:52 -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=lxt2TIMgKbMWBeD96IyYiDNX06PY6klS8vx7ZxbBwqE=; b=RuNv7WsPQaWSptcezZn//B/txpbSD+9CfC79wwK65wMPKoGG1byP2+YZHGc4ox8Sap aw8cBKoT/j3dezkmgthXh9/nuk7luAgdA6FRILt8fLi9PHjDEEWFVTu5Fs9hvkuX2juN fun8qkM6QTdd6UtJri+Uv//pOUtH9i6VnI0Kyc5GYeKW7nFb1qClDacTs0uvRT2rwSqL X1R5HkbmY000WsnWAwr24xYeOSlOwOO90iTnTQFoWTgjCQNFtCp2Q37ZYspcp6zD1835 Asx5/sNxL1FOi814LsFlr651qIC3eyyax36bsdGCRoKr1Qoo+RIvQ3CKD+dV74QKZORj bytg== 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=lxt2TIMgKbMWBeD96IyYiDNX06PY6klS8vx7ZxbBwqE=; b=Ik/o+5gffmCg+jva2sg8kix+JuWZ9bsaMoS0yIbfKY8la3IZ7fPdtOnOTan/JTl/mw 5C3M06J5HjxqzaVZd++Df2KtMcpqnLzm2ela2viFt2nMGroqEw49StjloWAwN0B7pgZr MUu0inwYUm8/a4FBUNUlZNgEAqur2UpKS0eJto2+Cxrj2bcCfiIWeECiMGJw3GMlbGSe SwQwLkwihtxxS8JcFmRtXWRsUsHcMc/Q2kgZ9h0MNgOD1rcwoKVBX+nNois0+rW38rLy TXhHhmtDOwElT8XK2Dl+3RG9p2S8pw6qyThG8ww/qmbTx7LlIEtLcCxk0wsP7brHsSUa rxgg== X-Gm-Message-State: AOAM5339p7ngIdcg2ifqHI3wPV0NS5WmHRhsClLwgAboxwEXgcXlInY5 mup/yNRytfARhRzGXU2CZZcdqWkbaN5RAg== X-Received: by 2002:a05:6a00:15d0:b029:305:1ef:8fbd with SMTP id o16-20020a056a0015d0b029030501ef8fbdmr23095625pfu.64.1625615391325; Tue, 06 Jul 2021 16:49:51 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 28/36] linux-user/nios2: Document non-use of setup_sigtramp Date: Tue, 6 Jul 2021 16:49:24 -0700 Message-Id: <20210706234932.356913-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.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: Marek Vasut , Chris Wulff , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu?= =?utf-8?q?-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Cc: Chris Wulff Cc: Marek Vasut Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/nios2/target_signal.h | 3 +++ 1 file changed, 3 insertions(+) -- 2.25.1 diff --git a/linux-user/nios2/target_signal.h b/linux-user/nios2/target_signal.h index aebf749f12..fe266c4c51 100644 --- a/linux-user/nios2/target_signal.h +++ b/linux-user/nios2/target_signal.h @@ -19,4 +19,7 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" +/* Nios2 uses a fixed address on the kuser page for sigreturn. */ +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0 + #endif /* NIOS2_TARGET_SIGNAL_H */ From patchwork Tue Jul 6 23:49:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470635 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5553578ejx; Tue, 6 Jul 2021 17:05:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM0Dfk+D8Wo+rsCAW4vy1vILIA6VNVe1K8UWLq26INsa9Nfzyf/bLV+nq6WhpV/Rg/F5Va X-Received: by 2002:a67:3c2:: with SMTP id 185mr17850861vsd.42.1625616324550; Tue, 06 Jul 2021 17:05:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616324; cv=none; d=google.com; s=arc-20160816; b=Bw2uHm/V09mv/CmUoZM6k3t+bFIer18m7GDMbbKbbgEcG1idgUcm8RdNWJ1A1y0sYM CvqnyYOPIS3/nmECGZtxCW+VhYHbBBKgOmYTbDFm2/S2KWQCLpkFZ5rggNLk8dj5WMqG UYZTv4vTXrIYzenaAKj0YKFtT6f0a9CBRFcUx25ELG4C6Qxz9Vp/33G195U1lP/ezaFh Wjubz9/RhBhbGi/mzqwH6SyBkivsKAAJFHjuFaIFT+VV7NkjhXPYQLE50XycSY1fTQOq aZPPlB1L5Tl1rWDa6/y+DCD24R8tOR+iOxEDcKUVsAUTHolETl/7QTXrGVgWOtxAg3gH lQXA== 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=2Vq41DCrZsY8w8sVZQ5+/3oe8dorwqbm8lEFaa2QNhk=; b=N2RznWWsmMvYCL994Bbg+cBJTvUIInWCe9wgdfu6ioXZvX4dlWNE+EvwYz5cWGUhyv g2WRZ+KjmzBt+qDssLt35yj29KtOtOpFFmpwKYKn9hKNjyMGmsto9IkYl6ZcgWIf1B90 nrMSXbThmgEdsvkV/9zX+3MBbBXRvWmPRzftKCR/ltIzO+s+YzW6pyflL5ebKvvR1Qfp pst1N+UE6FsQFf0JnagcXEFtERRux8NMVXcQB5VDGOHklxSVWdH16TH5tW9NE8MnkC7m NqUO4RKjZZt2MSrK/PjWrWXOA9B5lTvsibEWIO3qpi2fxvvyXGlm1pjou5/ce45UPMrX 6bfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TFNBtg86; 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 az4si12328779uab.19.2021.07.06.17.05.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:05:24 -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=TFNBtg86; 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]:60692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v47-0002Q5-Qc for patch@linaro.org; Tue, 06 Jul 2021 20:05:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upG-0001mI-Tl for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:02 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:40452) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up7-0006gP-7T for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:02 -0400 Received: by mail-pg1-x533.google.com with SMTP id g22so399135pgl.7 for ; Tue, 06 Jul 2021 16:49:52 -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=2Vq41DCrZsY8w8sVZQ5+/3oe8dorwqbm8lEFaa2QNhk=; b=TFNBtg86qS1CVcMbXGlRXDk0HHqQt2YFPq6a0dc9Yc/kfhPnKBoEaBTy4YoiNxcsbD +sSgGerxVuMEAQXacAgwp3kjtdT83XorCB89ogiykghFrjlvIG9u+4sGKIVRNBg1KB7n 4QocVDldj6vR9Fc7JUd+TUxliPq5OgKqaf6yg3DaTOkbYZGAqhjVk59Y2b1E3cJcCbro 3fGv8qRRQYmkNbnlTuKiVrPQejDNYHQ/eqrVlM/TqOZ6edxTvsFFwo8Unp1fTK/mKbWQ J9HM3MbdQGTYgzSGq0lzcIosSUwmEOAr2aQwFzI9CwV3vby4W+sM4hj8xS9MsTmp5c81 3wsw== 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=2Vq41DCrZsY8w8sVZQ5+/3oe8dorwqbm8lEFaa2QNhk=; b=CI2kJHaw1OjTelvbjDNnqaw+tQoWPsB1N4IkzyypWWSUi5jsq0jdZrCcMzclT/Hpcx 7k7bw9AsBCyQUexbJcdDNz18TFstzl6sHcRXZpWsnlROw/1ycibYH6CV4V0JAMflxwcK EPu63QQ7HF4WHRTxwvdpak+DU+H0ojHnxpYTI1rSOLW6tnXCACH7/PJYo0R6exx1cULm su//53ULH3lZttf719PfApl/2obnIhXfgiw60saxz5IxUlT1oU35dziByJ71USSUF2+8 3p/QVzJbXGbekMC9EY7jpk5yAxRnEwADfBbl9eIQg33Ubj1NoWIPaSjPzp4do3ahzmAr KrbQ== X-Gm-Message-State: AOAM531Nqt6L2aFlMQ+0Tw4end65gVrj4B0jkiuLFWyo4+7wYCWIvLdG lKdPxSeVyVhdkHwvAPPNJu5tzXb0XBDW4Q== X-Received: by 2002:aa7:8d86:0:b029:2ec:82d2:5805 with SMTP id i6-20020aa78d860000b02902ec82d25805mr22659605pfr.11.1625615391986; Tue, 06 Jul 2021 16:49:51 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 29/36] linux-user/openrisc: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:25 -0700 Message-Id: <20210706234932.356913-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.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: Stafford Horne , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create and record the rt signal trampoline. Reviewed-by: Stafford Horne Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/openrisc/target_signal.h | 2 ++ linux-user/openrisc/signal.c | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/linux-user/openrisc/target_signal.h b/linux-user/openrisc/target_signal.h index 8283eaf544..077ec3d5e8 100644 --- a/linux-user/openrisc/target_signal.h +++ b/linux-user/openrisc/target_signal.h @@ -26,4 +26,6 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif /* OPENRISC_TARGET_SIGNAL_H */ diff --git a/linux-user/openrisc/signal.c b/linux-user/openrisc/signal.c index 5c5640a284..b411b01864 100644 --- a/linux-user/openrisc/signal.c +++ b/linux-user/openrisc/signal.c @@ -37,7 +37,6 @@ typedef struct target_ucontext { typedef struct target_rt_sigframe { struct target_siginfo info; target_ucontext uc; - uint32_t retcode[4]; /* trampoline code */ } target_rt_sigframe; static void restore_sigcontext(CPUOpenRISCState *env, target_sigcontext *sc) @@ -115,14 +114,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]); } - /* This is l.ori r11,r0,__NR_sigreturn; l.sys 1; l.nop; l.nop */ - __put_user(0xa9600000 | TARGET_NR_rt_sigreturn, frame->retcode + 0); - __put_user(0x20000001, frame->retcode + 1); - __put_user(0x15000000, frame->retcode + 2); - __put_user(0x15000000, frame->retcode + 3); - /* Set up registers for signal handler */ - cpu_set_gpr(env, 9, frame_addr + offsetof(target_rt_sigframe, retcode)); + cpu_set_gpr(env, 9, default_rt_sigreturn); cpu_set_gpr(env, 3, sig); cpu_set_gpr(env, 4, frame_addr + offsetof(target_rt_sigframe, info)); cpu_set_gpr(env, 5, frame_addr + offsetof(target_rt_sigframe, uc)); @@ -168,3 +161,18 @@ long do_rt_sigreturn(CPUOpenRISCState *env) force_sig(TARGET_SIGSEGV); return 0; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 4 * 4, 0); + assert(tramp != NULL); + + /* This is l.ori r11,r0,__NR_sigreturn; l.sys 1; l.nop; l.nop */ + __put_user(0xa9600000 | TARGET_NR_rt_sigreturn, tramp + 0); + __put_user(0x20000001, tramp + 1); + __put_user(0x15000000, tramp + 2); + __put_user(0x15000000, tramp + 3); + + default_rt_sigreturn = sigtramp_page; + unlock_user(tramp, sigtramp_page, 4 * 4); +} From patchwork Tue Jul 6 23:49:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470710 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5474266jao; Tue, 6 Jul 2021 17:10:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxX8YYZf4VI83jq3ixEYmGa9j3rVU2fylKbJ3XzI+RDiJTeuXyxRuwhXZcTOqxpvIKoa9om X-Received: by 2002:ab0:5a4c:: with SMTP id m12mr3297966uad.40.1625616650537; Tue, 06 Jul 2021 17:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616650; cv=none; d=google.com; s=arc-20160816; b=wKym9XFF5Mz1PIOCi9v8mB87iYYqm3VFJyGLqrdZI3yvwXEtyRS7JzWkbeI97JO/Mk gdqPQeaYAy7hl64rbaQbTYhFOjHchHpSgnTIfUKtYRevTagZO27k6Vb4RL1JtxC4sgcr r3E5a+579o6K1743ogyfSH/MXr09ebZMJIFeP/vECzY3mf7NSyxinNU2DvmDFVHYq23k 6/wiMedHh6aMrVxXc11lfS9nx8Xzz9ekRAFM8iOYV9saK6U/HYKHcUEEMcFIbhV/WKcb FwcMrfkBgVgff0NowhA6vv0iPEJSezoUd2MDIzf2oJs1mk7MbRdV/18fP0HWKKfC7y2b iqQQ== 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=EI7h92b1yJotII6nje5EoFkQR471c3va7QkzOD5rBK0=; b=hNGzF8vA5Vx69qjlIF8stjmmq7gRlDqmqw8KDjYnNiduxcc/jJYN4/flfa6gjPfngg +phH9hgdeRJDBkjnaCyHEfouVM5o+b2k/yX5ej0fVr/DQkzD2khcuFCaapY0LC4lY4cF TzaijAhS1iTF6GGquqhJFgc/7QJJ0KcepQEBkGgEiHOnMT6UYtv+0VIwHHxkvh5zXXkQ CCotS71rCSwSv4UdDnUgevLDiDflL64v00DB3MkueYz64NMC4R6sE4CsY/IzSMnEeJDD id5OVoOu71MzAZE1PmaMAqOtQEL7qQ0GKYMOpJk1Kuym07SWIFN1T6sropGYGBV8N/eL ffzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=L+Uw4390; 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 b18si1107741uaj.46.2021.07.06.17.10.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:10:50 -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=L+Uw4390; 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]:51556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v9N-0006Qc-SC for patch@linaro.org; Tue, 06 Jul 2021 20:10:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upM-0001qw-R4 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:10 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:33570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up7-0006gV-OB for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:08 -0400 Received: by mail-pl1-x630.google.com with SMTP id f11so78826plg.0 for ; Tue, 06 Jul 2021 16:49:53 -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=EI7h92b1yJotII6nje5EoFkQR471c3va7QkzOD5rBK0=; b=L+Uw4390qrHD/Zlvi8CwiX3Z2Lp1r0PkrWbZWNtSrXyc/gvIDRpsNVznYvLbV/mfl3 ukAXRCNUwgsXv/2FPsV8KBgXciMtwcP0gMailXPLCPR3FTS3Qx+XzXTssV9Z6P+bQPiF HCYWxcTlaPCjaM1kzRVVFWJw8i+eywYR4u1WvYvfFkWz2K2LpyTcLDLr4WP8Jz/xhQO+ yjAB3HMx9IPDROHWl+Z3mga2iAdH62xJp/jTPLIZ7ua/5QtNn2gTSwhJXg9EV81HVB3g wtI/2quUbUo90VLxHap4H5qfIxmDXeVg3aEMf3De0VqTPdMY7dwrGelQm6bSuPey1Krw pk+w== 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=EI7h92b1yJotII6nje5EoFkQR471c3va7QkzOD5rBK0=; b=KEHr8NPzMA1Z0b21slzSdMtTJwbOQae+eSgTsbDyPCIszE3wwYvkBH7y/RLTznjdf3 6e5JVoxRPCthRNyr3TapXqzTzRcE0YCSZO4xGLBYOhpihVZ+iDCRGuftME+h/+YDJN0T IJ3xOIAEp8sl3033F5F5Eew7w6AXOWtAb1G/8nJDU4E7lmkO39JwSXtXBDke9gD9H8d+ FoeADuKmfWoTtB4qlANd8yU2v5rwkJ06RSNsPG2ST73i/Fx0eobCXRGboBx587BUXNBx GIRkvEo5Hdf4FCVyMMnpxbYOFL/GKF60YD8S41dzgKFs3Knis5XK0ks0sBm0q9lAostu xRWQ== X-Gm-Message-State: AOAM533yRpiB4UyNgukfa2UrroQubbhsgQ8KH15RbJsEr+v9NNrsIJJY 4SApQs52L3IpDiaX7l/dNJq2gfFibO8phA== X-Received: by 2002:a17:90b:3712:: with SMTP id mg18mr22666440pjb.164.1625615392523; Tue, 06 Jul 2021 16:49:52 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 30/36] target/ppc: Simplify encode_trampoline Date: Tue, 6 Jul 2021 16:49:26 -0700 Message-Id: <20210706234932.356913-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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: Peter Maydell , alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The sigret parameter is never 0, and even if it was the encoding of the LI instruction would still work. Reported-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/ppc/signal.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.25.1 diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index edfad28a37..70cc27b0f6 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -308,10 +308,8 @@ static void save_user_regs(CPUPPCState *env, struct target_mcontext *frame) static void encode_trampoline(int sigret, uint32_t *tramp) { /* Set up the sigreturn trampoline: li r0,sigret; sc. */ - if (sigret) { - __put_user(0x38000000 | sigret, &tramp[0]); - __put_user(0x44000002, &tramp[1]); - } + __put_user(0x38000000 | sigret, &tramp[0]); + __put_user(0x44000002, &tramp[1]); } static void restore_user_regs(CPUPPCState *env, From patchwork Tue Jul 6 23:49:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470655 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5472692jao; Tue, 6 Jul 2021 17:08:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbN5ub9Kq5d0pq6wSTG+sktGu8zaVX4Zw1WEy3Bup8chry71zi4s9xG/j6NSMGU9KtJX6Y X-Received: by 2002:a05:6402:1655:: with SMTP id s21mr26542857edx.295.1625616505039; Tue, 06 Jul 2021 17:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616505; cv=none; d=google.com; s=arc-20160816; b=Nxvsmt8uvILnelUBI3XngnkRlvxR49Ab2l45YCkLFS5xPhgw/Cs/o1HNf9L21WjLxB 7t4pAOf2WfqHYw3SX9IQKR0VN8AqMDzzQg7RdvXnr22hX+VKyePSNMK1tlaK5IfQa60L Ad2z8p6oPXoanAvi0tQQT2N+YRppKxpPbzcIxV6YHjrivZDS9ZKsgCJIy/jQWBNwfHJR anTsDDAK7c7KBGuMfk+jg7lpH5APOOrdePGYGUvhSXmgaIVsVO0VPrYLbkFk29ismZI0 WpTQob5s9xsw8ohimHLmvvORXIMX3loKFdFQifE0D5LKbxYr+VhwVTIi+mgKLtYLUNsH +EWg== 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=fM4gXsn+1azg0N7aKG1RgGgXofpXEZEL88nXdO/LS1Y=; b=I90Rqs3dhSwDhFxzUon1tQwbCfmFqwvmAAkS5q/k9kkAFuKtqLiwcUBUiW2FWw4F/e X0AYzgqcTfXZJlh2pQT+lAinLEb9e+OCUzX5rdjX1G62X3QMjKHt2dHBkOduW+YDahyC UxLeFFFlUwhWhld9Fv6dxBz9vdowNnBzZOrIKhyqZSJJ2UztC3izqOm7O+R7br7r4Rcd HWwWIWz9MuIhNkTGq4k4NpICSOq0T1hnmeU+P4GXBAAlQ5868+F4pEOHNZO8jM0eGiRX zsrZdze2FJlKxLo1DM+XBZ30uijAF42CAqmo8vVceOby9tfkT/XYxxLbcMiFyaVCY1fU NnNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="hj/w0S+I"; 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 a17si15371498edx.349.2021.07.06.17.08.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:08:25 -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="hj/w0S+I"; 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]:43114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v71-0000w7-9z for patch@linaro.org; Tue, 06 Jul 2021 20:08:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upM-0001qB-KI for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:08 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:33502) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up8-0006gk-BU for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:08 -0400 Received: by mail-pg1-x533.google.com with SMTP id 37so447479pgq.0 for ; Tue, 06 Jul 2021 16:49:53 -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=fM4gXsn+1azg0N7aKG1RgGgXofpXEZEL88nXdO/LS1Y=; b=hj/w0S+I9lgJlo7FAMiA1O44Ti/8/Av8uutaVQlUwv9hsd8jSPS1IiT96Sk8hwnzXk is0byr8QzrlbwVml5dkXoohq/CFe5c7WJS8YAKOV3fQGDvF56QlkNHJqqrRb/U5z+IQ0 pJj4hecn9pfNrDTtv3Vj2NDLuRzVpsRwAmMD8DBmPeN64paUwc9bVc+QKPLwvuDPLVMZ DvSSmJ/mF2Og+ir9+xiyyhhW2f5msxaEc45lJRwERtTVRUKT8ThAcn/gverCXl903bBU pQQZrFejBCF4OmqeJt4VbHs0zTPt/Ech1FND5mCf2W07+sIYEApoc9lbDwJTILburRJQ BpdQ== 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=fM4gXsn+1azg0N7aKG1RgGgXofpXEZEL88nXdO/LS1Y=; b=oNMERN0v7k3jZuykHrcpnAtReEyiyiOceDOYa7cBimypan80u0u2RMnJci3BqfsxjB AfKDEv3zGwSCkET9ISolDYhSCizmQEN117r08jz0zw4OXr2aM9E4r+h6996LWXlast/m XvGEAuMBlbVa2YRmcRiQGFBC/0bHpq3Is/0uAAzGNPhGBZ2lP4ddXWFzYOJhNR2Ozbs/ XUpbXa9KJt8wgXy099Z92NUQhPxEL0gPIsjIUPL/7GN+pL/2NibRSIYXj+0SBmXam71/ FjWPQe0TFsbIsn6I8IjZ5hT7mjMkuCX6lzBcpf6FgiNcG6tLHGQAeW8FXMyIUwa3Kx1y fuoA== X-Gm-Message-State: AOAM530BudGXJaU+dh/0eCcDxP9KvPDD1gmGLlTiOdNu+S+6AfOmzNbM K8Y+TerZMxTzoI7EdmC8lmoNVNV3mZnozw== X-Received: by 2002:a65:6443:: with SMTP id s3mr11400259pgv.72.1625615393141; Tue, 06 Jul 2021 16:49:53 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 31/36] linux-user/ppc: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:27 -0700 Message-Id: <20210706234932.356913-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.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: qemu-ppc@nongnu.org, 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. Cc: qemu-ppc@nongnu.org Signed-off-by: Richard Henderson --- linux-user/ppc/target_signal.h | 2 ++ linux-user/ppc/signal.c | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 16 deletions(-) -- 2.25.1 diff --git a/linux-user/ppc/target_signal.h b/linux-user/ppc/target_signal.h index 72fcdd9bfa..82184ab8f2 100644 --- a/linux-user/ppc/target_signal.h +++ b/linux-user/ppc/target_signal.h @@ -24,4 +24,6 @@ typedef struct target_sigaltstack { #if !defined(TARGET_PPC64) #define TARGET_ARCH_HAS_SETUP_FRAME #endif +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif /* PPC_TARGET_SIGNAL_H */ diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index 70cc27b0f6..2124eef932 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -202,9 +202,6 @@ struct target_func_ptr { #endif -/* We use the mc_pad field for the signal return trampoline. */ -#define tramp mc_pad - /* See arch/powerpc/kernel/signal.c. */ static target_ulong get_sigframe(struct target_sigaction *ka, CPUPPCState *env, @@ -435,12 +432,7 @@ void setup_frame(int sig, struct target_sigaction *ka, /* Save user regs. */ save_user_regs(env, &frame->mctx); - /* Construct the trampoline code on the stack. */ - encode_trampoline(TARGET_NR_sigreturn, (uint32_t *)&frame->mctx.tramp); - - /* The kernel checks for the presence of a VDSO here. We don't - emulate a vdso, so use a sigreturn system call. */ - env->lr = (target_ulong) h2g(frame->mctx.tramp); + env->lr = default_sigreturn; /* Turn off all fp exceptions. */ env->fpscr = 0; @@ -476,7 +468,6 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, target_sigset_t *set, CPUPPCState *env) { struct target_rt_sigframe *rt_sf; - uint32_t *trampptr = 0; struct target_mcontext *mctx = 0; target_ulong rt_sf_addr, newsp = 0; int i, err = 0; @@ -506,22 +497,17 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, #if defined(TARGET_PPC64) mctx = &rt_sf->uc.tuc_sigcontext.mcontext; - trampptr = &rt_sf->trampoline[0]; sc = &rt_sf->uc.tuc_sigcontext; __put_user(h2g(mctx), &sc->regs); __put_user(sig, &sc->signal); #else mctx = &rt_sf->uc.tuc_mcontext; - trampptr = (uint32_t *)&rt_sf->uc.tuc_mcontext.tramp; #endif save_user_regs(env, mctx); - encode_trampoline(TARGET_NR_rt_sigreturn, trampptr); - /* The kernel checks for the presence of a VDSO here. We don't - emulate a vdso, so use a sigreturn system call. */ - env->lr = (target_ulong) h2g(trampptr); + env->lr = default_rt_sigreturn; /* Turn off all fp exceptions. */ env->fpscr = 0; @@ -719,3 +705,19 @@ abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx, return 0; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 * 8, 0); + assert(tramp != NULL); + +#ifdef TARGET_ARCH_HAS_SETUP_FRAME + default_sigreturn = sigtramp_page; + encode_trampoline(TARGET_NR_sigreturn, tramp + 0); +#endif + + default_rt_sigreturn = sigtramp_page + 8; + encode_trampoline(TARGET_NR_rt_sigreturn, tramp + 2); + + unlock_user(tramp, sigtramp_page, 2 * 8); +} From patchwork Tue Jul 6 23:49:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470713 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5476196jao; Tue, 6 Jul 2021 17:13:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5MgxlJQDrXxpePy7XYpoCT7RtUos2WyutlftYFnMJLodyfmZdoNhzZukGeUsEgYXCgp4C X-Received: by 2002:a67:c11a:: with SMTP id d26mr271957vsj.11.1625616839888; Tue, 06 Jul 2021 17:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616839; cv=none; d=google.com; s=arc-20160816; b=jICwM/IKCanMPvb9Nk8jwTYGaqmw7lpzJMq3LCfPyMXikmNdoLUtkKUlp+Y3QN6p4K HDKQQCAcKy2tbpZH12/Qz1X7ST9mCmAwX8lN0LJtDQc+ajcjVb8aPWg7IPik9X4MhJ80 q9SWvUjqMibvWizhuuEybrgRCqufeXIZDBkcMAq8rLhst8ONo7J3k94wZrE7EUdYBSdG CnqQCrWzBAF0UpgQJWJs4RssjndWCZYZF1SDK131v4qMsXizarcH+2qwRPu2zkNqsLpR cP9HqDJNtB2fj7wP4osP3AMPw7yQhvuYMhlUqecrAguycp97yJhwvuKX1llUuce82onp mivw== 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=fah/7+FGmIwtKdVPZBEODDrAFrXPTjGeDHD95pFERbE=; b=stdl2bOQcaGWks3NCkNF+zOxxHL8AZTVDKJnEAHL/VxRIRL8giGaJpoaUivOeBQBaj FtYsO0Q60Sns9ep6m/BW+giyr//3btslnbOBcWBlEoSNF/sVvzKXk21xHlH6Hvy83sQ1 tbUK/04QgNIMoSIiDehdorSCdyePu7QRxH6ZuWC97aYEE9poXzOBnm4+FQ1EQ9wna1D6 FkeHB039yWICCVBFp4uAauleZ+4kaC40NatgsjgnTMwkd18/qIGlRD0Ygm/L+h2Liq7B b+9Y2F4K5OV9Ke7FriSFWA+WYm9lr3VJ1kj4UjhJfdPXe9IVM824jp3VsSQg8aqLUnlc Q9Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ksswvOHQ; 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 i25si3632532vsk.225.2021.07.06.17.13.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:13:59 -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=ksswvOHQ; 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]:34624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0vCR-0005NR-7U for patch@linaro.org; Tue, 06 Jul 2021 20:13:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upR-0001xu-4z for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:13 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:45956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up9-0006h4-5k for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:12 -0400 Received: by mail-pj1-x102e.google.com with SMTP id b8-20020a17090a4888b02901725eedd346so469376pjh.4 for ; Tue, 06 Jul 2021 16:49:54 -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=fah/7+FGmIwtKdVPZBEODDrAFrXPTjGeDHD95pFERbE=; b=ksswvOHQhba9y4Izx2jdxdkz42vbhrHBMWT6zLvAeo9EcJTfj/jppBcA8rNJLWzh0w TInd+RizqrLVcKHoUiygU3vjk6m2C+03VyX6A2/SqrBhydvw2tYOA+IE2fKG2W7q33gN 0O/G2GXNc9fgdy5YPhUhzmyf1SGdMXnlfU9qKm5xd+qalWT4tHgH9HWE79hRfuhXKH3B wyWxOSnvLSVer2N9rnIAGaWekGR4GPLidVOGCxU8uOUj6xav8oSBkHkdX/1oVLaBBl3D sQEpQ7sRJLSNHQeOcuPv4eIWIiNqZMEERd3+a6mmbOOC11dYZf5nVmXxrD6i8N+yBeMd slGg== 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=fah/7+FGmIwtKdVPZBEODDrAFrXPTjGeDHD95pFERbE=; b=gbtKD0wfuXVornOWXZ+pdtrTGp41SXXLlm6ErrTdctJOQaUWCpN4neRV4ABTll7xh5 tmquB/jCDaTBHsLnrLRepcixJ9HF4m9f9aznxMeunDQ7MeIr5IrOpl+MyHw377lDL1qx SfvVriG6S7YL6+kXdeDbqCowJwuD/fAtC+0oPaz4WnHYc1gD02nOXs/UenHV6IKVgq/7 u2CgYEDp3fK6NX4j3CeDDntPkb95/3+RDDH9A2p7cRViCHNoeMbGhrFpJ/pIDOKQ4P9G GC7oBsKsm6tcJPJm4f6/7wOMVgVXbPXBxRar6/Fkb0DfywtizN4vyEXU/Z3ZfAUwFmld +AHQ== X-Gm-Message-State: AOAM531SwWZ3esU20aMFst+BEdSN1z7lYK/wvjgRMgYlu9oeBpv0kbRs 4dekLRvkXMYaBrtO5EppNdpZTDPYfxvadw== X-Received: by 2002:a17:90b:787:: with SMTP id l7mr23243602pjz.110.1625615393746; Tue, 06 Jul 2021 16:49:53 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 32/36] linux-user/riscv: Add vdso and use it for sigreturn Date: Tue, 6 Jul 2021 16:49:28 -0700 Message-Id: <20210706234932.356913-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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=unavailable 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: qemu-riscv@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in those files for now. This fixes a bug wrt libgcc fallback unwinding. It expects the stack pointer to point to the siginfo_t, whereas we had inexplicably placed our private signal trampoline at the start of the signal frame instead of the end. Now moot because we have removed it from the stack frame entirely. Cc: qemu-riscv@nongnu.org Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 + linux-user/riscv/signal.c | 10 +- linux-user/meson.build | 1 + linux-user/riscv/Makefile.vdso | 11 ++ linux-user/riscv/meson.build | 9 ++ linux-user/riscv/vdso-32.so | Bin 0 -> 5624 bytes linux-user/riscv/vdso-64.so | Bin 0 -> 6120 bytes linux-user/riscv/vdso.S | 207 +++++++++++++++++++++++++++++++++ linux-user/riscv/vdso.ld | 76 ++++++++++++ 9 files changed, 309 insertions(+), 9 deletions(-) create mode 100644 linux-user/riscv/Makefile.vdso create mode 100644 linux-user/riscv/meson.build create mode 100755 linux-user/riscv/vdso-32.so create mode 100755 linux-user/riscv/vdso-64.so create mode 100644 linux-user/riscv/vdso.S create mode 100644 linux-user/riscv/vdso.ld -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 43c985f318..782d2904bc 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1484,10 +1484,14 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, #ifdef TARGET_RISCV32 #define ELF_CLASS ELFCLASS32 +#include "vdso-32.c.inc" #else #define ELF_CLASS ELFCLASS64 +#include "vdso-64.c.inc" #endif +#define vdso_image_info() &vdso_image_info + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c index 9405c7fd9a..fe7cf7723b 100644 --- a/linux-user/riscv/signal.c +++ b/linux-user/riscv/signal.c @@ -46,7 +46,6 @@ struct target_ucontext { }; struct target_rt_sigframe { - uint32_t tramp[2]; /* not in kernel, which uses VDSO instead */ struct target_siginfo info; struct target_ucontext uc; }; @@ -104,12 +103,6 @@ static void setup_ucontext(struct target_ucontext *uc, setup_sigcontext(&uc->uc_mcontext, env); } -static inline void install_sigtramp(uint32_t *tramp) -{ - __put_user(0x08b00893, tramp + 0); /* li a7, 139 = __NR_rt_sigreturn */ - __put_user(0x00000073, tramp + 1); /* ecall */ -} - void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPURISCVState *env) @@ -126,14 +119,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, setup_ucontext(&frame->uc, env, set); tswap_siginfo(&frame->info, info); - install_sigtramp(frame->tramp); env->pc = ka->_sa_handler; env->gpr[xSP] = frame_addr; env->gpr[xA0] = sig; env->gpr[xA1] = frame_addr + offsetof(struct target_rt_sigframe, info); env->gpr[xA2] = frame_addr + offsetof(struct target_rt_sigframe, uc); - env->gpr[xRA] = frame_addr + offsetof(struct target_rt_sigframe, tramp); + env->gpr[xRA] = default_rt_sigreturn; return; diff --git a/linux-user/meson.build b/linux-user/meson.build index 8021044053..e581d5ceba 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -35,6 +35,7 @@ subdir('microblaze') subdir('mips64') subdir('mips') subdir('ppc') +subdir('riscv') subdir('s390x') subdir('sh4') subdir('sparc') diff --git a/linux-user/riscv/Makefile.vdso b/linux-user/riscv/Makefile.vdso new file mode 100644 index 0000000000..de55a0b9f9 --- /dev/null +++ b/linux-user/riscv/Makefile.vdso @@ -0,0 +1,11 @@ +CROSS_CC ?= riscv64-linux-gnu-gcc +LDFLAGS := -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=both -Wl,--build-id=sha1 + +all: vdso-64.so vdso-32.so + +vdso-64.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mabi=lp64d -march=rv64g -fpic -o $@ vdso.S + +vdso-32.so: vdso.S vdso.ld Makefile.vdso + $(CROSS_CC) $(LDFLAGS) -mabi=ilp32d -march=rv32g -fpic -o $@ vdso.S diff --git a/linux-user/riscv/meson.build b/linux-user/riscv/meson.build new file mode 100644 index 0000000000..475b816da1 --- /dev/null +++ b/linux-user/riscv/meson.build @@ -0,0 +1,9 @@ +gen32 = [ + gen_vdso.process('vdso-32.so', extra_args: ['-r', '__vdso_rt_sigreturn']), +] +gen64 = [ + gen_vdso.process('vdso-64.so', extra_args: ['-r', '__vdso_rt_sigreturn']) +] + +linux_user_ss.add(when: 'TARGET_RISCV32', if_true: gen32) +linux_user_ss.add(when: 'TARGET_RISCV64', if_true: gen64) diff --git a/linux-user/riscv/vdso-32.so b/linux-user/riscv/vdso-32.so new file mode 100755 index 0000000000000000000000000000000000000000..0925aae9f50145bab6ef5d1da4a58c2dcb2ebec3 GIT binary patch literal 5624 zcmeHLU2KzO6n?*!!WeAqFi>z)fq_hvy5SI%iTmpqP{uMgord_ewB0)0I&3>K$iiEN z5Ml@{LJT3q3?zgYLl!ke4N(&lHR=r!6R(UnMz4$p{7D4n^L$_5(jg{Zc;Q9Q_Uydp z=RNP=`Ielc1Ho3yvXmjOx}qGZOsP63N6M9&241HYsp+a(m8m)4u8nr$qb%r0+>8bR zwB6@|^AI2xpJU=27y&m&_JA!w5QF282@}8L`*ifU7rHF!VIz#4{AwPSVoc=Q=RwAF zwV}ORUAq4JCtn`kJbAhA>*jA0=U=GFT>7pQwsdw*3pVuYjme==aPILUIL|VHJr;u> z0cHU_&J2K5K2Ya3Nr8D;u8clmk6#I_?f@ycU|CeOY%xOm~~&58Q?pPpDgu_LBzdsj3y zWcS6=>HfjkP;WH6+vp+#Ly_l=_+;8n_4g%X z>EUET4fH35M^+a8~4}U6Q&Q$`;D-z$zgTKT2 zhho}D=6$RR@4B^+c`tE1UI+MR;BoM8z(>J<1Rn$c1N;oQDsgiX&*PAHPp7g*Evur$ zqZoeyPzGP-hUzF?6h)HLw+85e9={Gz*8+6iqT{@dTXX}^1)($feibqaYj4Bi4OYc$ z&$!3epv2lMo>B4ck!d61+a=S}G9xKPJ7s1Ni7eb&{B6? z%j#FPJaSCSnpd=}9nTQ%N|IK!$h10CiPCXUe^ zEebhtZ_1fsu481zGvlL06GgQB6Xj|Rr;>8}1@!eg6{TAXxw6*@(ZIqI#5$S8x}M~9 zI}eKWy(_yFEbDw%cB^_*uY0rAPRI?5`K*53euV4Ku7FaPb9QzIKr9kKUQ`II{a8Db zEY#tgF_E=XUJ9B04VQ}58Vt<-Y2RW@;H=|Wo8{N(tjo9_^{neN;2FrQO(-7*&#(JW zL(cCLT!0+P^H+Au)9sC0Ha07}qjPI>pryMrV59im+_)iNcQrNz12$@CbW`j=o88*k zxFuk>wR9?bLvU+TW6<8(+PW>!WgPR0=4=UnySn>!W&PA@eM)7Xjg%|=^J@H@j%@;^ z{Hfi8>F^HlbkgNe7dx z?ze33i{Ba10Nt&AO<5hxPM?k6Ap2{ExF^ykU@{wz-z6~@IunociKhV5a|^*pa4-4i zg{XP~#^#*-z9K}2%-Q*L#*g1OanNiEHsiN9>*xF@;e`U{zzk7EGO=6d8A literal 0 HcmV?d00001 diff --git a/linux-user/riscv/vdso-64.so b/linux-user/riscv/vdso-64.so new file mode 100755 index 0000000000000000000000000000000000000000..75fe1db977ee1de538963a062e4da7c337ec6a54 GIT binary patch literal 6120 zcmeHLU2GIp6u!Gdp|l0|6i~3JMNzQA+9C+b-?Vhgk4xK>5^G{IU3RzK#&%0~r=*zX zP9OT936Um1LW~do5aWZ1O*94*6Y(cX&=_KjA;uUq{xrsrsz{7M>Nzv#EVI)Z6JLCA zPnrGh{mwb}+&OdaFy}h4cuP1GQX+=>Rk^*0$C#{`T6MEm);y$x%|bQ*{w@Id}j5;!L+ih!>RnB z)tk2MzJc^$PbzUlxMcre@^R73Aam)waOj*oG$g&A{-J!v>Pse)nZocn+sgO#=F;|1 zF01) zoF6JkM?%k&BvfN;p}kGHxrCdf6LAVLgQ#$mj37i1#}R80Pb02DJj?r@AD1$o=un}N zP^e}>*nK6@J{iMtWc`rcTD(RBoQd2>fTKAK2RNFKjhw8nIUFD3?#IApsHQ4B5iT_5;4KHL&p5F7bqAJA zII#2;2X1=Vftyb|ucDMJI&k}#1GS?Lth}z_j%yn3 z{6oX4-!Mv<%_)5e2 zFE!l%g@z3mHEjG`!vmjb*z~D}%@;I0_=$#xKGv}1yoRmkG;I4o!}j+z?08pWPAIQc zn2T=Q9Fl9KN>a)|DFdYplrm7tKq&*I4E%31aJ+oHB9C|9JE|0w_{Ym5^NRbmf&OTb z{bDREZum}=lkY!?f#2Fv5BqHm{0f(PrkFRB)Tzb%%({*A2A&W|9b9aWU-44>_!I_K zIp(Zy4E)g#;quv6BP56s#^*$pTh9fmqOELdkE{uU>@+(-sQWcpkRkp zF3ya*iS5r)f#;Kb*q*IU?LwaF)L`A&&%FB~jcxgc9%VjQk3P+Ou-<)v`C6X8jPnNb z!8%x3&5yP=?%T6dS?wKdJ7diUI${mseFY+ytFzUZvz4&Lm1$8G$|DtuTwgs~;HV^4Dw;nsU?&bD z+Bpw1(#j6nX%$T!$tDK+l5PWS5fgSoMSHVD(M%$r@pwDuF^AK+eBWTUsAHv6G@Y?} za*2Vol}Vwc^i#b3^&)}xL>NPO8Bf?`i&kVs#U&H!i&%l*sy zMQ}4Yp~(2+CwU#r&GFWFSe$A@#VcH zSk0CaU*ZTpf_gf`lfJzF1m*sN`IiawV1wo){=xH9%CBD}Z^F?M_WR5GRPaRLh9&>v zPiFySLTk_!Sy+s8rs5Y-3+In59AOt5ntWq)E(>@`d|7{THb*{wImL +#include + +.macro syscall nr + li a7, \nr + ecall +.endm + + .text + .balign 16 +__vdso_gettimeofday: + .cfi_startproc +#ifdef __NR_gettimeofday + syscall __NR_gettimeofday + ret +#else + /* No gettimeofday, fall back to clock_gettime64. */ + beq a1, zero, 1f + sw zero, 0(a1) /* tz->tz_minuteswest = 0 */ + sw zero, 4(a1) /* tz->tz_dsttime = 0 */ +1: addi sp, sp, -32 + .cfi_adjust_cfa_offset 32 + sw a0, 16(sp) /* save tv */ + mv a0, sp + syscall __NR_clock_gettime64 + lw t0, 0(sp) /* timespec.tv_sec.low */ + lw t1, 4(sp) /* timespec.tv_sec.high */ + lw t2, 8(sp) /* timespec.tv_nsec.low */ + lw a1, 16(sp) /* restore tv */ + addi sp, sp, 32 + .cfi_adjust_cfa_offset -32 + bne a0, zero, 9f /* syscall error? */ + li a0, -EOVERFLOW + bne t1, zero, 9f /* y2038? */ + li a0, 0 + li t3, 1000 + divu t2, t2, t3 /* nsec -> usec */ + sw t0, 0(a1) /* tz->tv_sec */ + sw t2, 4(a1) /* tz->tv_usec */ +9: ret +#endif + .cfi_endproc + + .globl __vdso_gettimeofday + .type __vdso_gettimeofday, %function + .size __vdso_gettimeofday, . - __vdso_gettimeofday + + .balign 16 +__vdso_clock_gettime: + .cfi_startproc +#ifdef __NR_clock_gettime + syscall __NR_clock_gettime +#else + syscall __NR_clock_gettime64 +#endif + ret + .cfi_endproc + + .globl __vdso_clock_gettime + .type __vdso_clock_gettime, %function + .size __vdso_clock_gettime, . - __vdso_clock_gettime + + .balign 16 +__vdso_clock_getres: + .cfi_startproc +#ifdef __NR_clock_getres + syscall __NR_clock_getres +#else + syscall __NR_clock_getres_time64 +#endif + ret + .cfi_endproc + + .globl __vdso_clock_getres + .type __vdso_clock_getres, %function + .size __vdso_clock_getres, . - __vdso_clock_getres + + .balign 16 +__vdso_getcpu: + .cfi_startproc + syscall __NR_getcpu + ret + .cfi_endproc + + .globl __vdso_getcpu + .type __vdso_getcpu, %function + .size __vdso_getcpu, . - __vdso_getcpu + + .balign 16 +__vdso_flush_icache: + .cfi_startproc + /* qemu does not need to flush the icache */ + li a0, 0 + ret + .cfi_endproc + + .globl __vdso_flush_icache + .type __vdso_flush_icache, %function + .size __vdso_flush_icache, . - __vdso_flush_icache + +/* + * Start the unwind info at least one instruction before the signal + * trampoline, because the unwinder will assume we are returning + * after a call site. + */ + + .cfi_startproc simple + .cfi_signal_frame + +#if __riscv_xlen == 32 +# define offsetof_uc_mcontext 0x120 +#else +# define offsetof_uc_mcontext 0x130 +#endif +#define sizeof_reg (__riscv_xlen / 4) +#define sizeof_freg 8 +#define offsetof_freg0 (sizeof_reg * 32) + + .cfi_def_cfa 2, offsetof_uc_mcontext + + /* Return address */ + .cfi_return_column 64 + .cfi_offset 64, 0 /* pc */ + + /* Integer registers */ + .cfi_offset 1, 1 * sizeof_reg /* r1 (ra) */ + .cfi_offset 2, 2 * sizeof_reg /* r2 (sp) */ + .cfi_offset 3, 3 * sizeof_reg + .cfi_offset 4, 4 * sizeof_reg + .cfi_offset 5, 5 * sizeof_reg + .cfi_offset 6, 6 * sizeof_reg + .cfi_offset 7, 7 * sizeof_reg + .cfi_offset 8, sizeof_reg * 8 + .cfi_offset 9, 9 * sizeof_reg + .cfi_offset 10, 10 * sizeof_reg + .cfi_offset 11, 11 * sizeof_reg + .cfi_offset 12, 12 * sizeof_reg + .cfi_offset 13, 13 * sizeof_reg + .cfi_offset 14, 14 * sizeof_reg + .cfi_offset 15, 15 * sizeof_reg + .cfi_offset 16, 16 * sizeof_reg + .cfi_offset 17, 17 * sizeof_reg + .cfi_offset 18, 18 * sizeof_reg + .cfi_offset 19, 19 * sizeof_reg + .cfi_offset 20, 20 * sizeof_reg + .cfi_offset 21, 21 * sizeof_reg + .cfi_offset 22, 22 * sizeof_reg + .cfi_offset 23, 23 * sizeof_reg + .cfi_offset 24, 24 * sizeof_reg + .cfi_offset 25, 25 * sizeof_reg + .cfi_offset 26, 26 * sizeof_reg + .cfi_offset 27, 27 * sizeof_reg + .cfi_offset 28, 28 * sizeof_reg + .cfi_offset 29, 29 * sizeof_reg + .cfi_offset 30, 30 * sizeof_reg + .cfi_offset 31, 31 * sizeof_reg /* r31 */ + + .cfi_offset 32, offsetof_freg0 /* f0 */ + .cfi_offset 33, offsetof_freg0 + 1 * sizeof_freg /* f1 */ + .cfi_offset 34, offsetof_freg0 + 2 * sizeof_freg + .cfi_offset 35, offsetof_freg0 + 3 * sizeof_freg + .cfi_offset 36, offsetof_freg0 + 4 * sizeof_freg + .cfi_offset 37, offsetof_freg0 + 5 * sizeof_freg + .cfi_offset 38, offsetof_freg0 + 6 * sizeof_freg + .cfi_offset 39, offsetof_freg0 + 7 * sizeof_freg + .cfi_offset 40, offsetof_freg0 + 8 * sizeof_freg + .cfi_offset 41, offsetof_freg0 + 9 * sizeof_freg + .cfi_offset 42, offsetof_freg0 + 10 * sizeof_freg + .cfi_offset 43, offsetof_freg0 + 11 * sizeof_freg + .cfi_offset 44, offsetof_freg0 + 12 * sizeof_freg + .cfi_offset 45, offsetof_freg0 + 13 * sizeof_freg + .cfi_offset 46, offsetof_freg0 + 14 * sizeof_freg + .cfi_offset 47, offsetof_freg0 + 15 * sizeof_freg + .cfi_offset 48, offsetof_freg0 + 16 * sizeof_freg + .cfi_offset 49, offsetof_freg0 + 17 * sizeof_freg + .cfi_offset 50, offsetof_freg0 + 18 * sizeof_freg + .cfi_offset 51, offsetof_freg0 + 19 * sizeof_freg + .cfi_offset 52, offsetof_freg0 + 20 * sizeof_freg + .cfi_offset 53, offsetof_freg0 + 21 * sizeof_freg + .cfi_offset 54, offsetof_freg0 + 22 * sizeof_freg + .cfi_offset 55, offsetof_freg0 + 23 * sizeof_freg + .cfi_offset 56, offsetof_freg0 + 24 * sizeof_freg + .cfi_offset 57, offsetof_freg0 + 25 * sizeof_freg + .cfi_offset 58, offsetof_freg0 + 26 * sizeof_freg + .cfi_offset 59, offsetof_freg0 + 27 * sizeof_freg + .cfi_offset 60, offsetof_freg0 + 28 * sizeof_freg + .cfi_offset 61, offsetof_freg0 + 29 * sizeof_freg + .cfi_offset 62, offsetof_freg0 + 30 * sizeof_freg + .cfi_offset 63, offsetof_freg0 + 31 * sizeof_freg /* f31 */ + + nop + +__vdso_rt_sigreturn: + syscall __NR_rt_sigreturn + .cfi_endproc + + .globl __vdso_rt_sigreturn + .type __vdso_rt_sigreturn, %function + .size __vdso_rt_sigreturn, . - __vdso_rt_sigreturn diff --git a/linux-user/riscv/vdso.ld b/linux-user/riscv/vdso.ld new file mode 100644 index 0000000000..57f3159415 --- /dev/null +++ b/linux-user/riscv/vdso.ld @@ -0,0 +1,76 @@ +/* + * Linker script for linux riscv replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_4.15 { + global: + __vdso_rt_sigreturn; + __vdso_gettimeofday; + __vdso_clock_gettime; + __vdso_clock_getres; + __vdso_getcpu; + __vdso_flush_icache; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* + * We can't prelink to any address without knowing something about + * the virtual memory space of the host, since that leaks over into + * the available memory space of the guest. + */ + . = SIZEOF_HEADERS; + + /* + * The following, including the FILEHDRS and PHDRS, are modified + * when we relocate the binary. We want them to be initially + * writable for the relocation; we'll force them read-only after. + */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + .data : { + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text =0xd503201f +} From patchwork Tue Jul 6 23:49:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470646 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5555318ejx; Tue, 6 Jul 2021 17:07:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcRLEMZE+OYtZEYjUGXunWZrQsnaoWmHXz/L4S83xNYQ5DrDVOqLMmJzvxO/avnOjCRFyG X-Received: by 2002:a67:8c4a:: with SMTP id o71mr18517803vsd.46.1625616469105; Tue, 06 Jul 2021 17:07:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616469; cv=none; d=google.com; s=arc-20160816; b=hktNl1vJcViHDpi4hvm7365Gs58d/91HVhHpkivO2i3fupHqh9+oVuwRZMc1cvPKnp hmyHVkPPDgIzcJ6RQCt/U+Dte5UtfKayQ9uRg05KLF4/gYbJM/gBnk1KEbWLBRkYtj0i VniwRJRO9F/ld5wtiqMVBd5gWlxfpL4dz+E3Dfu+E8WdqGsvYIOvNNH10e6aWtEWJj20 rg7WR/uimHCQVR4HprwGb400sOcx62t119EX6wci5alkffYRQCtNEC+bzu19H5cz/K/7 Xpepd106JqQcKBluOIeI1VK2PrbFiVN/idfRP08GS3ogH9fnmQHR78ELqSMa5SxcxDcL 1jbg== 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=+jVFzflzGymDZrI1ZoMIgTCB/1BSyil5/+M6JPmFwtc=; b=EEI9D60MXe1ukfG6UWlNVjePgRl3aWhwT0Xded7aHYSsC+9EcKd2Ol+UVxWp0opWuH HFJQTDeb9Qa0PsKtDgLHidSx9Y3+JahTbHDEGmMcU2GElPMvXWodoCUl6e10d/Z3KGEl ymGhZp9rU7wpXMb7cnhrzBPGKeTTqxe7qSx0h+JOGtQklH0ArZANkaecnA7xee7AKcVm SwhK2SWknFZmtDoH+CCoqQkTz6o4+ZAKXcEJUMgYuChTg5AiMpcqBQNequHMrFA19qSB O95KQnHJlP1gKLcJob6ujb7znfEw4pY6iR2w2Doh51is7hRtGYgMPy0b1A3QZgL+zwIF FxQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RqHn1ecF; 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 p15si6656709vsm.317.2021.07.06.17.07.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:07:49 -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=RqHn1ecF; 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]:41054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v6S-000818-C4 for patch@linaro.org; Tue, 06 Jul 2021 20:07:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upQ-0001wA-I1 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:12 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:43907) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0up9-0006hE-I7 for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:12 -0400 Received: by mail-pg1-x532.google.com with SMTP id o18so384221pgu.10 for ; Tue, 06 Jul 2021 16:49:55 -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=+jVFzflzGymDZrI1ZoMIgTCB/1BSyil5/+M6JPmFwtc=; b=RqHn1ecFuSdrWAHUFWjD6xuV93TMVllL5lkfak3aXPq0AoiDCwPPIVWoRZrHwXHW5+ ZJjCPkqrCybaDSgoGXPGy827fiK6BS9WC5Y9VixkEGTqg1x/Wwnvtl6xS2ZSxIPDmgRM uk6MYM+3q/r4WOLvfOyiK7Adhw/llnnscMFHfQEwceeGsXp5iSyezGz17J+H8mFASu5f tcd76k9kzukkeYhTiQlkSe2YWrKGd4uxCed5ipfrDJEaB4mcBxkCMQ3gqsuyFcG7/Zom SmJh6BdAv+gfvg49rCaezf46lMVtJWGPF+oCYTmgr/liivFKdKmkbxp0Ee0ClCcBrP5v jqEA== 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=+jVFzflzGymDZrI1ZoMIgTCB/1BSyil5/+M6JPmFwtc=; b=jUCKbzMvaKJCYoW54pmu7+8b8+c0zjG5rCni9iIP3lAWwUcJxvYnFNCsTGurgEf16c pm09IJ77anjCpRjZNkaZZGa4jimXc7k6Yczh9URj2RfcVjhMuHIERVh1Ye22sjza/psf J/0zDAcN4QyXvfM1GDs0DkkdC1QEbKuEVIAtOaB+dEHuBzvEvW3zMdhhaheVd/YjISsL TBQWLEjOuMfZjNXx8AKGhDlfz8+bn2TaYKVlRDUkYXNBtrXIXVD2Xs+GqqPgPU4HBVFv 2DqY2iq6DwW3FcPbVTHOtP6JoAda9OHYADkZRb+5xa2YAYCwJ9wjEH3ovkP7xWnmCEan 6cdA== X-Gm-Message-State: AOAM532y5faxEeFGThaS+42SC3VvBmn+jzV7sOSQIsF+G3TNpk5s/xlR oZyVSVUgu46zjxqcwaq7Yskuk7mMncsFeA== X-Received: by 2002:a65:63ce:: with SMTP id n14mr23080785pgv.273.1625615394360; Tue, 06 Jul 2021 16:49:54 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 33/36] linux-user/s390x: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:29 -0700 Message-Id: <20210706234932.356913-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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: qemu-s390x@nongnu.org, alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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. Cc: qemu-s390x@nongnu.org Tested-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/s390x/target_signal.h | 2 ++ linux-user/s390x/signal.c | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/linux-user/s390x/target_signal.h b/linux-user/s390x/target_signal.h index bbfc464d44..64f5f42201 100644 --- a/linux-user/s390x/target_signal.h +++ b/linux-user/s390x/target_signal.h @@ -19,4 +19,6 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" #define TARGET_ARCH_HAS_SETUP_FRAME +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif /* S390X_TARGET_SIGNAL_H */ diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c index bf8a8fbfe9..18b1997f1e 100644 --- a/linux-user/s390x/signal.c +++ b/linux-user/s390x/signal.c @@ -67,7 +67,6 @@ typedef struct { target_sigregs sregs; int signo; target_sigregs_ext sregs_ext; - uint16_t retcode; } sigframe; #define TARGET_UC_VXRS 2 @@ -84,7 +83,6 @@ struct target_ucontext { typedef struct { uint8_t callee_used_stack[__SIGNAL_FRAMESIZE]; - uint16_t retcode; struct target_siginfo info; struct target_ucontext uc; } rt_sigframe; @@ -208,9 +206,7 @@ void setup_frame(int sig, struct target_sigaction *ka, if (ka->sa_flags & TARGET_SA_RESTORER) { restorer = ka->sa_restorer; } else { - restorer = frame_addr + offsetof(sigframe, retcode); - __put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn, - &frame->retcode); + restorer = default_sigreturn; } /* Set up registers for signal handler */ @@ -261,9 +257,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, if (ka->sa_flags & TARGET_SA_RESTORER) { restorer = ka->sa_restorer; } else { - restorer = frame_addr + offsetof(typeof(*frame), retcode); - __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn, - &frame->retcode); + restorer = default_rt_sigreturn; } /* Create siginfo on the signal stack. */ @@ -404,3 +398,17 @@ long do_rt_sigreturn(CPUS390XState *env) unlock_user_struct(frame, frame_addr, 0); return -TARGET_QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint16_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 + 2, 0); + assert(tramp != NULL); + + default_sigreturn = sigtramp_page; + __put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn, &tramp[0]); + + default_rt_sigreturn = sigtramp_page + 2; + __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn, &tramp[1]); + + unlock_user(tramp, sigtramp_page, 2 + 2); +} From patchwork Tue Jul 6 23:49:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470663 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5555862ejx; Tue, 6 Jul 2021 17:08:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSjeOJBdrYLdBB+LJchKbC5T+PuQBrZirot4qEsFi4MyGbTfSHiUQQLZ1wzNa8YhnBzxF3 X-Received: by 2002:a67:8095:: with SMTP id b143mr18600436vsd.48.1625616517787; Tue, 06 Jul 2021 17:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616517; cv=none; d=google.com; s=arc-20160816; b=x3yUQ70oErgrJflFNHl6E+NS3D9/4VeWYNcpZraZsySajE0SX1gqh+g4UDCUJrq6Bp B0c21Pa/uu1mlN8b2AoAdPWZio14TCfHseBlGp8FeopmtLXqElgsJxgpVQVF9WK6d3Gy QnP1+YOqAppVR9dsbcxgsEvleHWlxP/gMnGZtpmOuFsejJ/axTfhiMJ3rpiFfyZPs+Iz 5of+3iZzhUTnm+5y9Xok27RmHgW0pZ+h4mHyldpoHqLEnG9S9fUjR/mpmUNd3GbmnE9J dcVl4gXZ2Isy/4CMtuh5wGFHIMFAgOrciseOoE/ay6jFFD4LirzEI+2psQxYjTmuX3YJ iuJg== 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=7UwSZzPtNanlmWoP6K+UEdnWrT6YCBYNNgPR1NCdYPw=; b=oSKuaTxKsoqUQMngIpmcT0EZnBs5pEib639E4roFqTP3IPLQ3sgFSeGrjKOuI1aisx qMqjggul85RRXIJTZGJS3Xu0p/jgTBHaCxa5p3o8ebvTTsQOWFcH5vOW5gK4EW49UKyc IJzsS62ddRsF6gXngCbxMAbtCL9aBI7yScSkKmtQUwO1mNanHaeXGOEapmivxLAEAlFC O5ZadBjxrlpNnGh4kAhDk9k07Xna63VQew8Uxncmuo2c2Uts8rQ3+Ol5J05ggcpkBjAO ePQSF/R/CF3tm34DRHfj0EB6PoqLrfnqJCkXYoelKvZCnNKQOS95IrVjNhIv1dxUtWvc mIPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="XsDwZV/Y"; 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 q12si12217736vkq.55.2021.07.06.17.08.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:08:37 -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="XsDwZV/Y"; 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]:41858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0v7F-00005P-1G for patch@linaro.org; Tue, 06 Jul 2021 20:08:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upS-00023i-Pp for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:14 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:33745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0upA-0006hY-5h for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:14 -0400 Received: by mail-pj1-x102e.google.com with SMTP id mn20-20020a17090b1894b02901707fc074e8so2493322pjb.0 for ; Tue, 06 Jul 2021 16:49:55 -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=7UwSZzPtNanlmWoP6K+UEdnWrT6YCBYNNgPR1NCdYPw=; b=XsDwZV/YpjqcFdfJOFx+NKndj/S+eTsUTY6ypj7C3sOTdqGQ2TWbRgvmfdN475hSci lYEUa/kOC3dJsEGusTjZpZD301JnKwf+rycH4cox+UUghe/maRof+LfYT1USRh7F6YuG JKdQQeZHgOALUf8ImxkC2GSfeLU+C2Q8iEQ2kqDjb0do04AttZPRC8wAG5wnwnb991xc oNkA6iDYLMwkxl7i0GVVL+zIkXAoINzpY+uEH5PVCoY2tJd5zsPQ7+aDMOjcJKbYuFjG 6uUS7Kf0BOeht3x4/Lre3KSIUZ0ufTj44aLdV+z9P1HACNJRDWI8PgPjVb2LesAE/ef0 cWNA== 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=7UwSZzPtNanlmWoP6K+UEdnWrT6YCBYNNgPR1NCdYPw=; b=bbZLopOynOOuNDrzWdUyUEYWhX+1Gt+ymY0dxXrGl5zc7I3wlbPPbZ1X1sT/7NJkwF lH31jyZKxSsE0/h203GZUabitMOn+t93glRinobh2jxRoHBSsPsJ9o19xQ8pocd417h/ OauDFmr00Excy6ba1Qy+Q1/cUA4AhOaP1hufBSTFLzejFkFHfg1+7hB+tkU0MM5jNn1E QaIe/I3vIubZdNu0UkV1Ah5Z5i3fqDnT4NPTmuiUseSMjp17eOZwB9TkFGgYe58tyIZF pQVEaXPYDKwC3aQvIuY66eRmlKGppZnrwK7csISGvVF73XS0sUxaF/VvJYrlsa7HYYLL pR6Q== X-Gm-Message-State: AOAM532LxCh42RDrwbke3hjhPi5gRLalspq2rpG3Hji2eLJwyCQM2o+t 2VtH98vN5jSsloQ/AMOzV73GJ+QG8l8rsw== X-Received: by 2002:a17:90a:8c87:: with SMTP id b7mr2888091pjo.230.1625615394989; Tue, 06 Jul 2021 16:49:54 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 34/36] linux-user/sh4: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:30 -0700 Message-Id: <20210706234932.356913-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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, Yoshinori Sato , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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. Cc: Yoshinori Sato Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/sh4/target_signal.h | 2 ++ linux-user/sh4/signal.c | 40 +++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 18 deletions(-) -- 2.25.1 diff --git a/linux-user/sh4/target_signal.h b/linux-user/sh4/target_signal.h index d7309b7136..04069cba66 100644 --- a/linux-user/sh4/target_signal.h +++ b/linux-user/sh4/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 /* SH4_TARGET_SIGNAL_H */ diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c index 0451e65806..5a5ae69785 100644 --- a/linux-user/sh4/signal.c +++ b/linux-user/sh4/signal.c @@ -51,7 +51,6 @@ struct target_sigframe { struct target_sigcontext sc; target_ulong extramask[TARGET_NSIG_WORDS-1]; - uint16_t retcode[3]; }; @@ -67,7 +66,6 @@ struct target_rt_sigframe { struct target_siginfo info; struct target_ucontext uc; - uint16_t retcode[3]; }; @@ -189,15 +187,9 @@ void setup_frame(int sig, struct target_sigaction *ka, /* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa_flags & TARGET_SA_RESTORER) { - regs->pr = (unsigned long) ka->sa_restorer; + regs->pr = ka->sa_restorer; } else { - /* Generate return code (system call to sigreturn) */ - abi_ulong retcode_addr = frame_addr + - offsetof(struct target_sigframe, retcode); - __put_user(MOVW(2), &frame->retcode[0]); - __put_user(TRAP_NOARG, &frame->retcode[1]); - __put_user((TARGET_NR_sigreturn), &frame->retcode[2]); - regs->pr = (unsigned long) retcode_addr; + regs->pr = default_sigreturn; } /* Set up registers for signal handler */ @@ -247,15 +239,9 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, /* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa_flags & TARGET_SA_RESTORER) { - regs->pr = (unsigned long) ka->sa_restorer; + regs->pr = ka->sa_restorer; } else { - /* Generate return code (system call to sigreturn) */ - abi_ulong retcode_addr = frame_addr + - offsetof(struct target_rt_sigframe, retcode); - __put_user(MOVW(2), &frame->retcode[0]); - __put_user(TRAP_NOARG, &frame->retcode[1]); - __put_user((TARGET_NR_rt_sigreturn), &frame->retcode[2]); - regs->pr = (unsigned long) retcode_addr; + regs->pr = default_rt_sigreturn; } /* Set up registers for signal handler */ @@ -333,3 +319,21 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint16_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 * 6, 0); + assert(tramp != NULL); + + default_sigreturn = sigtramp_page; + __put_user(MOVW(2), &tramp[0]); + __put_user(TRAP_NOARG, &tramp[1]); + __put_user(TARGET_NR_sigreturn, &tramp[2]); + + default_rt_sigreturn = sigtramp_page + 6; + __put_user(MOVW(2), &tramp[3]); + __put_user(TRAP_NOARG, &tramp[4]); + __put_user(TARGET_NR_rt_sigreturn, &tramp[5]); + + unlock_user(tramp, sigtramp_page, 2 * 6); +} From patchwork Tue Jul 6 23:49:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470712 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5475918jao; Tue, 6 Jul 2021 17:13:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwk30y7PLDCWpaUfMT+LWjIdUMw7F39OhqC4YggQdxJXce82q4+ufIhhtEZWlDeZdIU7AeL X-Received: by 2002:a37:7307:: with SMTP id o7mr22697911qkc.121.1625616805913; Tue, 06 Jul 2021 17:13:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616805; cv=none; d=google.com; s=arc-20160816; b=qxHCv9r2FvU5obPEbEJKzKwY/xHEtzP4WZlOY+ebQkriRuzdXuuZfbqMf1/no41R3m D0JkyQY1Nzz/iIcWF3pyCuBzN3NDYQXnHOQD33/kzwqpjZfsIk/ItU5bPiXsr2OP08Lq j0mNn4dmlpT1PEvAKE5vmkEha+6z9sO7+zEwYithWABjB6NpfjqbMZgv6YK5i1gaX0mH r46Ku+/jBEWnpFJIp4bgbIqjReno/jwPpBd2c8G5ZEX2MfxeA/Jk2oOf5gM8HCxN2Od7 QSLGo17wgsXloXxOSS1S5wXXMFiUhxU6K85f5Uag5RV3Yp15rTXjotUKnBZ6S0duU1Qs 1mDQ== 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=1VZpf/Cjga2uC2Sey1urjoKxB8BD12dYWIoT4C3ZK3w=; b=KSK9SXoZW67fVyei1asFNgQYFbiQi0OXK3sx16lG/lj/3nWdGLBSObzEuFZQC9xi9K 1k9dwKtRSRO4rVedDBVnr4Cm/gUzvyKlATstylTMix96m6xAbNMlXNsqFuQcySdZlA3f ObfFoiux3B0zLIH6l72psfbTmOPHdrJw/q2dM685Sdz3mb+U1BG8bidKs7T52mcAF8pu EbBeGoApRBINzGoljqcKTGE50cDu5IIJljBELtWJD8Jrn3Y7du0WCBQbgEuJT0qFk8U5 wEUjNrQIIOMNkxrtNs9e77DwWPai1LZKsf8YacHgN+4PpSXq7KlV8GD/i2Ay/oBxPXTd n3Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=U7UpySBm; 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 d19si12253939qtd.272.2021.07.06.17.13.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:13:25 -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=U7UpySBm; 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]:58678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0vBt-0002cf-Am for patch@linaro.org; Tue, 06 Jul 2021 20:13:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53548) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upS-00021x-6Y for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:14 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:34554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0upA-0006hl-Qb for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:13 -0400 Received: by mail-pg1-x532.google.com with SMTP id 62so424427pgf.1 for ; Tue, 06 Jul 2021 16:49:56 -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=1VZpf/Cjga2uC2Sey1urjoKxB8BD12dYWIoT4C3ZK3w=; b=U7UpySBmEqKTDQEHakJwBNclungbIfMHfhPkq/alokfnr9Y7+7ZDvF81xaCHSGGKsA fASYwiV9CgX7v/Vj4xpvPQ0OQKv/Nc7xyXSwZBwDSEYU40jP/91r2llQz3rH8neCBeVT bqDKv8FdoUshjPhplFe+LgeXv6emGcYB6WjRrrrbU63sPSAAAkEv/iMzLGA37U16PK6e 64rkbixYhPgluHbh1UjLTHWGZK+cGYE9F+0ez03JIm5PylD25/SDrH4eJPD8QMOoXn9S l8ZjHjIfyCavmIUvsbPiEWOnrJUkOWT95XahWRw5T13KBYgFXvfU4cFuWV9YvoDvr2WS ZDJw== 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=1VZpf/Cjga2uC2Sey1urjoKxB8BD12dYWIoT4C3ZK3w=; b=rIiBLz8pkUQ8uzlIsiK4flNAfMAP+6X8MXH9o0WWNfTktErCYTfaxXRnMdyxOD+Dfu 7/wJtibZm6vzrdW/1dZ90L1gh45/w6OSx8wG2YKLCDWdtP9xjj0X78cYP9OaNp8hQQOB 3oK+pgB+7jM4hWQFu6fvqb1ijR8wRxJv1vMT85g2u0rXhkZGkQqh+X+WHXjhUb3rU8Ic nEiMIVCPY4mX6aRNfhu8BW0aG8domfGwikYVL+apdO8DjVBsSFs2SguSY4xcPB95j4M6 ieh7YQUqB8pP7rCojD3orTweT4Iw+7u6QKDjQHsVoIHVqcwEsTHsP5Cf306D256Ww8q9 kvcA== X-Gm-Message-State: AOAM530lPC0VQKWMZzA7w2CsbCWdQnIIuTeRcpRoxI8H2mPVHFjK0bXa Hx18yUlv2djPwtum0BChiFtaI1VR3wxMdg== X-Received: by 2002:a63:171e:: with SMTP id x30mr23773106pgl.368.1625615395585; Tue, 06 Jul 2021 16:49:55 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 35/36] linux-user/sparc: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:31 -0700 Message-Id: <20210706234932.356913-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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: Mark Cave-Ayland , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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. Cc: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/sparc/target_signal.h | 4 ++++ linux-user/sparc/signal.c | 32 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) -- 2.25.1 diff --git a/linux-user/sparc/target_signal.h b/linux-user/sparc/target_signal.h index 34f9a12519..e661ddd6ab 100644 --- a/linux-user/sparc/target_signal.h +++ b/linux-user/sparc/target_signal.h @@ -69,6 +69,10 @@ typedef struct target_sigaltstack { #ifdef TARGET_ABI32 #define TARGET_ARCH_HAS_SETUP_FRAME +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 +#else +/* For sparc64, use of KA_RESTORER is mandatory. */ +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0 #endif /* bit-flags */ diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c index 0cc3db5570..65e9b7f8b4 100644 --- a/linux-user/sparc/signal.c +++ b/linux-user/sparc/signal.c @@ -290,13 +290,7 @@ void setup_frame(int sig, struct target_sigaction *ka, if (ka->ka_restorer) { env->regwptr[WREG_O7] = ka->ka_restorer; } else { - env->regwptr[WREG_O7] = sf_addr + - offsetof(struct target_signal_frame, insns) - 2 * 4; - - /* mov __NR_sigreturn, %g1 */ - __put_user(0x821020d8u, &sf->insns[0]); - /* t 0x10 */ - __put_user(0x91d02010u, &sf->insns[1]); + env->regwptr[WREG_O7] = default_sigreturn; } unlock_user(sf, sf_addr, sf_size); } @@ -357,13 +351,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, if (ka->ka_restorer) { env->regwptr[WREG_O7] = ka->ka_restorer; } else { - env->regwptr[WREG_O7] = - sf_addr + offsetof(struct target_rt_signal_frame, insns) - 2 * 4; - - /* mov __NR_rt_sigreturn, %g1 */ - __put_user(0x82102065u, &sf->insns[0]); - /* t 0x10 */ - __put_user(0x91d02010u, &sf->insns[1]); + env->regwptr[WREG_O7] = default_rt_sigreturn; } #else env->regwptr[WREG_O7] = ka->ka_restorer; @@ -774,4 +762,20 @@ do_sigsegv: unlock_user_struct(ucp, ucp_addr, 1); force_sig(TARGET_SIGSEGV); } +#else +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 2 * 8, 0); + assert(tramp != NULL); + + default_sigreturn = sigtramp_page; + __put_user(0x821020d8u, &tramp[0]); /* mov __NR_sigreturn, %g1 */ + __put_user(0x91d02010u, &tramp[1]); /* t 0x10 */ + + default_rt_sigreturn = sigtramp_page + 8; + __put_user(0x82102065u, &tramp[2]); /* mov __NR_rt_sigreturn, %g1 */ + __put_user(0x91d02010u, &tramp[3]); /* t 0x10 */ + + unlock_user(tramp, sigtramp_page, 2 * 8); +} #endif From patchwork Tue Jul 6 23:49:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470714 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5476784jao; Tue, 6 Jul 2021 17:14:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOkCpwvsnmWx+BQv2bQ/iP4y+lsdoAAwQDfF0VBTma+YD/fX8PFSBbtYknGuEPjZf0diMt X-Received: by 2002:a05:620a:d4e:: with SMTP id o14mr23293083qkl.402.1625616893110; Tue, 06 Jul 2021 17:14:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625616893; cv=none; d=google.com; s=arc-20160816; b=c4qAPGgEGRuZPt0T7wRQrucTvIeKqQRMVDW6H3eiRl1ZLaIZVgQL7Nt8grKLmdKipu 00x10xaVO55kOpUK88WDQWFgFfCUzAovxZ74xRwYGBoDYHD5AjxU/LwQ40UgqhCPiK3E i5qx0dDHM0p2EB9DgiF4KOFxQ/sonW8s4x8LJ3zXFm7jzWPxmh3mKkbAOaDxoDy89gto /QoZipju3H1KTGxf+Fxdj04FQSGRQIbZiH7pE18qCSkx6v1LEwZXB4fDSaq2616pYEdu YlDcmKlAMRFa8vtlQnuSnTo640FMzkuVy05RTD2QmzHJv5ROSU4jf8YwcVjwI7VllW8g +7ug== 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=r1aOR56lJG8Y7fzXfcIBZhWpAZ7tMlA6NQMa73cEU+c=; b=zaL/Gt1W6fvgOK8pExvmeQWoj8BMVY49arRf002xQPbeOcGlndFyd9o8JTCpPy6WMV zmVV9RI9mM2Vvhs+8GYcmqREfBV0T0KMTQSFPQTqCsvFQNC8am9gW/d4UX4/qIsvFNKj p4K1bhDcdVLjL2dPBTCexuDl0sswLqGBwpE5txZWhkZ+2P8SX3+Vn42HgrjJW9AVbTBS enAxRvL+qBMVjzsK9f6N6IHgzSAzMhrKltbpGLZCTum5DbC0Harqqyd8rItQcVYIjyhx r2vklHAa1oxRBWCfZPjMS2fIiBST9qVHd/EK8ohxcQ/Mq5gGWWVNpqfqHpMJk7KbdzaV yjQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Or0bIsS8; 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 n13si14368902qkp.19.2021.07.06.17.14.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 17:14:53 -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=Or0bIsS8; 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]:37406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0vDI-0007Bk-IH for patch@linaro.org; Tue, 06 Jul 2021 20:14:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0upU-00029A-9b for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:16 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:37633) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0upB-0006iH-KG for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:50:16 -0400 Received: by mail-pl1-x62d.google.com with SMTP id a14so59658pls.4 for ; Tue, 06 Jul 2021 16:49:57 -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=r1aOR56lJG8Y7fzXfcIBZhWpAZ7tMlA6NQMa73cEU+c=; b=Or0bIsS8kj820PjX0wSeYufzbRbA7uuM6v+dj0tN2EgCBunPFhLXymaa270HymDIP/ wgBE/WrGpd2tOTWLfb1TZu7jwEU/YPqBsEWAVR3UCfVInEizhEgg+XTLrEHhAVg2O0S2 +JaMv+ufC48gZHIbcj7j9dCsyay+nsDqNfUgYlqX+AGDh8ez5jvdn+TzDIsXpWKg0paX UhfG6bSnAfhvGimwoiZBxj8UKE/6x7uP6gu+Ekg7lfe0COpsQFF9OeLCQHGYTwbW0CMi DSKod1JNnuMbQs3KGeOa05NCZT/D4TdF+b5PCFEmRYa7jAlNnis9FRPKN9q2uEMCgfSe hxpQ== 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=r1aOR56lJG8Y7fzXfcIBZhWpAZ7tMlA6NQMa73cEU+c=; b=Dvaun37S7owDuYO2V7x6xlEBWZ9hnWrADjxr/3XtsFbFotOzczkIWHAi0wrfMwj2fV D5yEqYF5lwkSPD1vLkzCGP/cQYdV2NjniCYlNANkBdX6VWTfCvEa6mWQHmBwH2jxoAhX mUtCyxLmxVzjfQx1QvkMp19l4BppFA77dLG8EACsjLxMShhMNSnN2qeuh3upZT3U5A25 ck/YiUJiKszXM2ag7IXUZ8rCOuK79jYlfBrJIrUks8QTib8A7PSIibwbUGHBlyoOMNEt GP77x2CWu3HDojfuqnKA8+tPb2y41xRy87xQjaavlb5ir4ZDcShjgWvsKx1z5IhK0omq huPg== X-Gm-Message-State: AOAM531BbTmV5Krzpl4CeKjl3RTBzp8SsKMS38L54nDyKKh0GMTwIFRP AeRLLQbB3GYpqylEmpfcrGciu/k/RvCx9Q== X-Received: by 2002:a17:903:2452:b029:129:33a0:399d with SMTP id l18-20020a1709032452b029012933a0399dmr19211293pls.31.1625615396244; Tue, 06 Jul 2021 16:49:56 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 36/36] linux-user/xtensa: Implement setup_sigtramp Date: Tue, 6 Jul 2021 16:49:32 -0700 Message-Id: <20210706234932.356913-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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: Max Filippov , alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Create and record the rt signal trampoline. Use it when the guest does not use SA_RESTORER. Reviewed-by: Max Filippov Signed-off-by: Richard Henderson --- linux-user/xtensa/target_signal.h | 2 ++ linux-user/xtensa/signal.c | 50 ++++++++++++++++++------------- 2 files changed, 32 insertions(+), 20 deletions(-) -- 2.25.1 diff --git a/linux-user/xtensa/target_signal.h b/linux-user/xtensa/target_signal.h index c60bf656f6..1c7ee73154 100644 --- a/linux-user/xtensa/target_signal.h +++ b/linux-user/xtensa/target_signal.h @@ -20,4 +20,6 @@ typedef struct target_sigaltstack { #include "../generic/signal.h" +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 + #endif diff --git a/linux-user/xtensa/signal.c b/linux-user/xtensa/signal.c index 72771e1294..fd57481bf5 100644 --- a/linux-user/xtensa/signal.c +++ b/linux-user/xtensa/signal.c @@ -163,26 +163,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, if (ka->sa_flags & TARGET_SA_RESTORER) { ra = ka->sa_restorer; } else { - ra = frame_addr + offsetof(struct target_rt_sigframe, retcode); -#ifdef TARGET_WORDS_BIGENDIAN - /* Generate instruction: MOVI a2, __NR_rt_sigreturn */ - __put_user(0x22, &frame->retcode[0]); - __put_user(0x0a, &frame->retcode[1]); - __put_user(TARGET_NR_rt_sigreturn, &frame->retcode[2]); - /* Generate instruction: SYSCALL */ - __put_user(0x00, &frame->retcode[3]); - __put_user(0x05, &frame->retcode[4]); - __put_user(0x00, &frame->retcode[5]); -#else - /* Generate instruction: MOVI a2, __NR_rt_sigreturn */ - __put_user(0x22, &frame->retcode[0]); - __put_user(0xa0, &frame->retcode[1]); - __put_user(TARGET_NR_rt_sigreturn, &frame->retcode[2]); - /* Generate instruction: SYSCALL */ - __put_user(0x00, &frame->retcode[3]); - __put_user(0x50, &frame->retcode[4]); - __put_user(0x00, &frame->retcode[5]); -#endif + ra = default_rt_sigreturn; } memset(env->regs, 0, sizeof(env->regs)); env->pc = ka->_sa_handler; @@ -263,3 +244,32 @@ badframe: force_sig(TARGET_SIGSEGV); return -TARGET_QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint8_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 6, 0); + assert(tramp != NULL); + +#ifdef TARGET_WORDS_BIGENDIAN + /* Generate instruction: MOVI a2, __NR_rt_sigreturn */ + __put_user(0x22, &tramp[0]); + __put_user(0x0a, &tramp[1]); + __put_user(TARGET_NR_rt_sigreturn, &tramp[2]); + /* Generate instruction: SYSCALL */ + __put_user(0x00, &tramp[3]); + __put_user(0x05, &tramp[4]); + __put_user(0x00, &tramp[5]); +#else + /* Generate instruction: MOVI a2, __NR_rt_sigreturn */ + __put_user(0x22, &tramp[0]); + __put_user(0xa0, &tramp[1]); + __put_user(TARGET_NR_rt_sigreturn, &tramp[2]); + /* Generate instruction: SYSCALL */ + __put_user(0x00, &tramp[3]); + __put_user(0x50, &tramp[4]); + __put_user(0x00, &tramp[5]); +#endif + + default_rt_sigreturn = sigtramp_page; + unlock_user(tramp, sigtramp_page, 6); +}