From patchwork Fri Sep 24 16:59: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: 514582 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1673625jao; Fri, 24 Sep 2021 10:01:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwX0Ih3rR+72w/n2cmkN6ZAfhHzWwipEoJkXzEySUcdZOktGVCaTnw6R+FEPubkyxMkgwJW X-Received: by 2002:ac8:538a:: with SMTP id x10mr5317982qtp.251.1632502886235; Fri, 24 Sep 2021 10:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632502886; cv=none; d=google.com; s=arc-20160816; b=mtS6V1spfKgeMeKQJJGyFefU4sRVJxNki1Njm08Ds5iYnOd0gOaWyUrQDsN1bMXql6 kcWrbmHAqxd8p42mUsaSHqlNP1jUyL0FWiBIkLtS8+FxZhvpoo84Go3yht9Vk0O5A820 c7MLLEdeXlqKG9rGDxg8J1sLXdggNObAQ9Uxi7EMFi2SqWdczm7thz4xH49X5csvzDDP yG1i6iWQntp7nA0Ax5i28QMO7wc0pk+dVd/x7Sla9VmRIcA2Sp4DW8JZhy4LSz7qBHBg cb9V4iB+nr1FcJP0n5VDa0NYPoumRIgcdfaebNc/cwZgeF6jsVBJUGPVUMdEtw3CoxgW dJMA== 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=tmL+joXfoW+8Wn51iJgMBifiuqpS0R+kHN3F+bMNUq0=; b=CGOosasLuWVrQkAKo2YVUubUIw5+FrCZZpw5zdCIfU2ZDrLyuycHwu4HlI8j+GWMbq K7pdtk8aUGfMAgpOTIZJcXTtl+wg4GhTGLUIyvqcLj5luUIlAOwWhHV6/wxslqePzrS2 LUJMrokSNWbccDY+IsfTlKS2VUiEYd5tesbpHzK86yvkTIOWr3ZoN5aTDAzQeotGvdP3 7esn8dfGTvSj+CUcgBNke39lJmMrLYrC+c82EgIrOb7xq0etYC8ChsPUoCInmdegkfSV b7lRs4XiwlG6aqfzGdL9Fi0Y1rCnBQub+mtRU1gASsu4JveZzicF3xbp+ZzyYfSPLLOD ldcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xfAv5iPt; 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 a8si6058263qkh.106.2021.09.24.10.01.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Sep 2021 10: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=xfAv5iPt; 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]:55074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mToZh-0002ff-OT for patch@linaro.org; Fri, 24 Sep 2021 13:01:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mToXx-0002dx-2H for qemu-devel@nongnu.org; Fri, 24 Sep 2021 12:59:38 -0400 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]:39550) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mToXq-0006rS-0d for qemu-devel@nongnu.org; Fri, 24 Sep 2021 12:59:36 -0400 Received: by mail-qv1-xf2f.google.com with SMTP id a14so6648490qvb.6 for ; Fri, 24 Sep 2021 09:59:29 -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=tmL+joXfoW+8Wn51iJgMBifiuqpS0R+kHN3F+bMNUq0=; b=xfAv5iPtHAieHsIzSI/p1Ty23DbheWyX3t4bsn4MClUY6i59zpx8PcKP4794BPIgoV pfWQKnJe5+OqccwWiI1pTfvv3jNj8bAGrBOB7rJLJuoGm9ILv5AdTHvhX3A/YfYZt4dR xfSNNqbxjwciypCFwQ6G19aWGXywb+X0dt+EvojjpE2e1I5d0bDrPE1gAyyF3dQZ4K7N BXRrGViO7p7t/jV667+NetbZOExWc8z/i7eGFoTo25rUWP+uVgqBa4hEWv3WPUh0Gp4T GEE7QASXo9PFTZtiCrCMKdC+Zoy/rtqV0JVvemmamev45an08Ze+lPlJweoaGZCJvffH XaZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tmL+joXfoW+8Wn51iJgMBifiuqpS0R+kHN3F+bMNUq0=; b=Z1e/PnHMrFNY/JqFfE0bPseuGlwPvyGUvx3KldKahEm9zI0pRhh7dWCAw4yA6CmAKi FSOzfItu8Hj+osN52PqZmmFHpE5lKwQXK5DOhd0Tx/TrzjjjO6wZm3QGXoMq4etVTEwx YxhBscb3/DFURUuDngPULxYrMnbo+AaOyEfnSufgd7HxY92h+UuZDtmWrM/C80yOiUsS 7UD+3t9d7WJXeHY8qtc2fVn2iy6Ja1MU/hjqIsAiBcBH+c7c4xiWoAW5UNcsB9TRgXwy ioQfLgQkdkCf1Xr0e1YF74CnvLiOc1iY1kehYjuBCl/7IiDUdU6Gn2pJtf/AK6Oqp5xL +Tdw== X-Gm-Message-State: AOAM531UIorv4kbEjhuL3XiLEvpK/bY92V3OIhIOFRPE6Xe0orqAu18B dASwLaGE8hnzVI2MfU6Ax4W4Es7srohUwA== X-Received: by 2002:ad4:4629:: with SMTP id x9mr1451260qvv.58.1632502769084; Fri, 24 Sep 2021 09:59:29 -0700 (PDT) Received: from localhost.localdomain (cpe-24-74-129-96.carolina.res.rr.com. [24.74.129.96]) by smtp.gmail.com with ESMTPSA id r13sm7141104qkk.73.2021.09.24.09.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 09:59:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 01/27] linux-user: Add infrastructure for a signal trampoline page Date: Fri, 24 Sep 2021 12:59:00 -0400 Message-Id: <20210924165926.752809-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210924165926.752809-1-richard.henderson@linaro.org> References: <20210924165926.752809-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f2f; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2f.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , laurent@vivier.eu, Max Filippov 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/signal-common.h | 6 ++++++ linux-user/elfload.c | 18 ++++++++++++++++++ linux-user/signal.c | 3 +++ 3 files changed, 27 insertions(+) -- 2.25.1 diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h index 79511becb4..7457f8025c 100644 --- a/linux-user/signal-common.h +++ b/linux-user/signal-common.h @@ -20,6 +20,12 @@ #ifndef SIGNAL_COMMON_H #define SIGNAL_COMMON_H +/* Fallback addresses into sigtramp page. */ +extern abi_ulong default_sigreturn; +extern abi_ulong default_rt_sigreturn; + +void setup_sigtramp(abi_ulong tramp_page); + int on_sig_stack(unsigned long sp); int sas_ss_flags(unsigned long sp); abi_ulong target_sigsp(abi_ulong sp, struct target_sigaction *ka); diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 5f9e2141ad..459a26ef1d 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -7,6 +7,7 @@ #include "qemu.h" #include "user-internals.h" +#include "signal-common.h" #include "loader.h" #include "user-mmap.h" #include "disas/disas.h" @@ -17,6 +18,7 @@ #include "qemu/units.h" #include "qemu/selfmap.h" #include "qapi/error.h" +#include "target_signal.h" #ifdef _ARCH_PPC64 #undef ARCH_DLINFO @@ -28,6 +30,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 */ @@ -3249,6 +3255,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 2038216455..14d8fdfde1 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -35,6 +35,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,