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,