From patchwork Mon Nov 8 02:37:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1552111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=YGWO53z+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnbBg4w7tz9s0r for ; Mon, 8 Nov 2021 13:47:55 +1100 (AEDT) Received: from [::1] (port=50442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjuhM-0006Kn-BG for incoming@patchwork.ozlabs.org; Sun, 07 Nov 2021 21:47:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjueY-0002uo-SO for qemu-devel@nongnu.org; Sun, 07 Nov 2021 21:45:02 -0500 Received: from [2607:f8b0:4864:20::72f] (port=46767 helo=mail-qk1-x72f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjueW-0005f7-ND for qemu-devel@nongnu.org; Sun, 07 Nov 2021 21:44:58 -0500 Received: by mail-qk1-x72f.google.com with SMTP id bl12so14232235qkb.13 for ; Sun, 07 Nov 2021 18:44:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WsLO8A98ncSHQryH3E3fZBiVJ7KQ5mOAWvNz0c/T7dg=; b=YGWO53z+o1XmBeUaPSWMq8n3DZaDliqtrPGhfdE80SFHDp0ZDCXJd79biPp+EYSgyh FuS5okEc7ovyt772eazNE9nDfyv95NCiI/gQKrmjSBS8thM+b9ObDx7lNgP8rZCYZJ2I nmTT+AWb9wCLKSwmkpBbBKjX9wBE+DcNWpkEQxYcnTkoheTIoNtmL//AUJT4bfx6y5dU Zme/JFhGQ3OCI1zDbbDXDoakXUkoI0TflH5uNQmAFeysYedWkwdR2wTONLxxCHac+O+B mgaF/Rcl2T/3pyl+vlY74G14rLOioK9ZGX/PM9d9YyO80C3nXQBsNYv6kH0gC/df2Hyt PUcw== 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=WsLO8A98ncSHQryH3E3fZBiVJ7KQ5mOAWvNz0c/T7dg=; b=VK56VeoHXp1AHW3Lm6C+RlOvitOGGjMLos0uSZSlGeuIYXmDzfypgAaDpemYGNhVW5 JxgKUOG8kU+IfPdvqudTg7yW6MiWnkZ2z5PiekDmuq7XblwV/A6RgmlfxLqCVY6+6+zR Pve5Cvttgs0Ep5LgiOYZYby6q89rR2o8MI1ReGHmLn+JretQNKGoQBbmYFD9UNXrmpAc LAe/8R9eE1N/i8S2ZUbPGOwPpPVXDQHvWrJY5ycGt+2qIEcs2j7Qz8+Rii7gpFj1Nwbf WlzfuUAFF0wnmVynLG1kPxfTkbeLGzuygd2VMJ5hmXNKxkFgMdFhKqn4HsuFzVN1rf0d 3/QA== X-Gm-Message-State: AOAM5308baTTRbr9jGil7wE9T0H6eRGfB2mTRM1ANgyGXYTzcuYdxqSy FMeS09tv1bVsZ8tXFhakyKS4GI+sGpkAuw== X-Google-Smtp-Source: ABdhPJzJgioSpEy06jYbtwchInH/3tfw/HVh+7e5/uXGRzAhWlLOmb67/SfsjNlGztyYGveulUfXow== X-Received: by 2002:a05:6638:d16:: with SMTP id q22mr22220981jaj.35.1636339091423; Sun, 07 Nov 2021 18:38:11 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id m2sm9030284iow.6.2021.11.07.18.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 18:38:10 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [RFC 1/4] linux-user: Add host_signal_set_pc to set pc in mcontext Date: Sun, 7 Nov 2021 19:37:35 -0700 Message-Id: <20211108023738.42125-2-imp@bsdimp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211108023738.42125-1-imp@bsdimp.com> References: <20211108023738.42125-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::72f (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::72f; envelope-from=imp@bsdimp.com; helo=mail-qk1-x72f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , Laurent Vivier , Warner Losh , Philippe Mathieu-Daude Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a new function host_signal_set_pc to set the next pc in an mcontext. The caller should ensure this is a valid PC for execution. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/host/aarch64/host-signal.h | 5 +++++ linux-user/host/alpha/host-signal.h | 5 +++++ linux-user/host/arm/host-signal.h | 5 +++++ linux-user/host/i386/host-signal.h | 5 +++++ linux-user/host/mips/host-signal.h | 5 +++++ linux-user/host/ppc/host-signal.h | 5 +++++ linux-user/host/riscv/host-signal.h | 5 +++++ linux-user/host/s390/host-signal.h | 5 +++++ linux-user/host/sparc/host-signal.h | 9 +++++++++ linux-user/host/x86_64/host-signal.h | 5 +++++ 10 files changed, 54 insertions(+) diff --git a/linux-user/host/aarch64/host-signal.h b/linux-user/host/aarch64/host-signal.h index 0c0b08383a..9770b36dc1 100644 --- a/linux-user/host/aarch64/host-signal.h +++ b/linux-user/host/aarch64/host-signal.h @@ -35,6 +35,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) return uc->uc_mcontext.pc; } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.pc = pc; +} + static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) { struct _aarch64_ctx *hdr; diff --git a/linux-user/host/alpha/host-signal.h b/linux-user/host/alpha/host-signal.h index e080be412f..f4c942948a 100644 --- a/linux-user/host/alpha/host-signal.h +++ b/linux-user/host/alpha/host-signal.h @@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) return uc->uc_mcontext.sc_pc; } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.sc_pc = pc; +} + static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) { uint32_t *pc = (uint32_t *)host_signal_pc(uc); diff --git a/linux-user/host/arm/host-signal.h b/linux-user/host/arm/host-signal.h index efb165c0c5..6c095773c0 100644 --- a/linux-user/host/arm/host-signal.h +++ b/linux-user/host/arm/host-signal.h @@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) return uc->uc_mcontext.arm_pc; } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.arm_pc = pc; +} + static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) { /* diff --git a/linux-user/host/i386/host-signal.h b/linux-user/host/i386/host-signal.h index 4c8eef99ce..abe1ece5c9 100644 --- a/linux-user/host/i386/host-signal.h +++ b/linux-user/host/i386/host-signal.h @@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) return uc->uc_mcontext.gregs[REG_EIP]; } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.gregs[REG_EIP] = pc; +} + static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) { return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe diff --git a/linux-user/host/mips/host-signal.h b/linux-user/host/mips/host-signal.h index ef341f7c20..c666ed8c3f 100644 --- a/linux-user/host/mips/host-signal.h +++ b/linux-user/host/mips/host-signal.h @@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) return uc->uc_mcontext.pc; } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.pc = pc; +} + #if defined(__misp16) || defined(__mips_micromips) #error "Unsupported encoding" #endif diff --git a/linux-user/host/ppc/host-signal.h b/linux-user/host/ppc/host-signal.h index a491c413dc..1d8e658ff7 100644 --- a/linux-user/host/ppc/host-signal.h +++ b/linux-user/host/ppc/host-signal.h @@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) return uc->uc_mcontext.regs->nip; } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.regs->nip = pc; +} + static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) { return uc->uc_mcontext.regs->trap != 0x400 diff --git a/linux-user/host/riscv/host-signal.h b/linux-user/host/riscv/host-signal.h index 3b168cb58b..a4f170efb0 100644 --- a/linux-user/host/riscv/host-signal.h +++ b/linux-user/host/riscv/host-signal.h @@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) return uc->uc_mcontext.__gregs[REG_PC]; } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.__gregs[REG_PC] = pc; +} + static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) { /* diff --git a/linux-user/host/s390/host-signal.h b/linux-user/host/s390/host-signal.h index 26990e4893..a524f2ab00 100644 --- a/linux-user/host/s390/host-signal.h +++ b/linux-user/host/s390/host-signal.h @@ -16,6 +16,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) return uc->uc_mcontext.psw.addr; } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.psw.addr = pc; +} + static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) { uint16_t *pinsn = (uint16_t *)host_signal_pc(uc); diff --git a/linux-user/host/sparc/host-signal.h b/linux-user/host/sparc/host-signal.h index 5e71d33f8e..e301c2c1ea 100644 --- a/linux-user/host/sparc/host-signal.h +++ b/linux-user/host/sparc/host-signal.h @@ -20,6 +20,15 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) #endif } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ +#ifdef __arch64__ + uc->uc_mcontext.mc_gregs[MC_PC] = pc; +#else + &uc->uc_mcontext.gregs[REG_PC] = pc; +#endif +} + static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) { uint32_t insn = *(uint32_t *)host_signal_pc(uc); diff --git a/linux-user/host/x86_64/host-signal.h b/linux-user/host/x86_64/host-signal.h index 883d2fcf65..c71d597eb2 100644 --- a/linux-user/host/x86_64/host-signal.h +++ b/linux-user/host/x86_64/host-signal.h @@ -15,6 +15,11 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc) return uc->uc_mcontext.gregs[REG_RIP]; } +static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc) +{ + uc->uc_mcontext.gregs[REG_RIP] = pc; +} + static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) { return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe From patchwork Mon Nov 8 02:37:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1552110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=busTclar; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hnb9706bBz9s0r for ; Mon, 8 Nov 2021 13:46:34 +1100 (AEDT) Received: from [::1] (port=45884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjug4-0003AQ-Ju for incoming@patchwork.ozlabs.org; Sun, 07 Nov 2021 21:46:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjudR-0001OE-5k for qemu-devel@nongnu.org; Sun, 07 Nov 2021 21:43:49 -0500 Received: from [2607:f8b0:4864:20::431] (port=43788 helo=mail-pf1-x431.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjudL-0005Wy-5b for qemu-devel@nongnu.org; Sun, 07 Nov 2021 21:43:46 -0500 Received: by mail-pf1-x431.google.com with SMTP id n85so10092365pfd.10 for ; Sun, 07 Nov 2021 18:43:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6njyoagLzejw2BckyvHuei2jPUql+1Ifyt4czYHcUBg=; b=busTclarjut2YOuUtezDzLAdSVBnLhvGLvhGwvc/02GPqPUXiWU54xIWe7xxe6nn5M iLvMB3bPsGYl6fRC9NA4ogS9XaA/HdVW993sgz0+yg3I+A/hBgutlhqA17qddFaF+9Ok OjAerWoiWLOhHQfH0K10NoEmEMmacuDS+V7ZJXmF+gpEieEsuHUiD9QhnSdCL6iyY8Tz 9yEzjbY89AOnE4N+qP4MK2iuV4y2wn+U/KM+0N9mvhALJ0n479EY2bbQMnngljt0Jfd4 p9yiT2Ipf+MPXPwKhIVyDYXqAbjukgZOdLdRc9a09M4io7krBwVeVScc3tUDJrTZj1bF 36vA== 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=6njyoagLzejw2BckyvHuei2jPUql+1Ifyt4czYHcUBg=; b=BZd0/byTYJZYLccl3ml3YDkCQ/vQrz4RbiMQ0IQjMP/5L3idkNcAzrgMiJKTDMc5Sv +QvgJbo8jmR/skWXG+3+IF/y97LBue1xtGWmajgjOrFS3+tCchL2n4p6BN3UD1RROKzq aDOd+i2NqTC+eZeCuyb2yG6nr34PRsd+E5HzsBhyTPjuac9/mE6Fj3P9QtdHjk/9Mt0U 4Vr8tRHMLeMjJ2DFSX2f5nnFLZDVT7G6G9myUhWM4XkBO/5raTLo5FsbwpnTVSefcw4X fep4Ez8YvI3ruXAOJ15X7ZvOiwvVAsZP1YbBlcjf/Fnr9xAPFDtNdQnstHOBXXijOqzE 2/WA== X-Gm-Message-State: AOAM533Y71xupevq51ZBo4ZjlC/QG95TtfuMIvAhF5mysjalJulUK651 efomU0nynRGTeCdqRKNiVUcq58QrtBkd0Q== X-Google-Smtp-Source: ABdhPJxFhA/2YANXTk8VvOEzdPRxjmCqsRVjIbUdqydlFjMV/gDLl4uc27puKpF0A+1TBHjIiq24ZA== X-Received: by 2002:a05:6e02:178f:: with SMTP id y15mr45425331ilu.126.1636339092547; Sun, 07 Nov 2021 18:38:12 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id m2sm9030284iow.6.2021.11.07.18.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 18:38:12 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [RFC 2/4] linux-user/signal.c: Create a common rewind_if_in_safe_syscall Date: Sun, 7 Nov 2021 19:37:36 -0700 Message-Id: <20211108023738.42125-3-imp@bsdimp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211108023738.42125-1-imp@bsdimp.com> References: <20211108023738.42125-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::431 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::431; envelope-from=imp@bsdimp.com; helo=mail-pf1-x431.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , Laurent Vivier , Warner Losh , Philippe Mathieu-Daude Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" All instances of rewind_if_in_safe_syscall are the same, differing only in how the instruction point is fetched from the ucontext and the size of the registers. Use host_signal_pc and new host_signal_set_pc interfaces to fetch the pointer to the PC and adjust if needed. Delete all the old copies of rewind_if_in_safe_syscall. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/host/aarch64/hostdep.h | 20 -------------------- linux-user/host/arm/hostdep.h | 20 -------------------- linux-user/host/i386/hostdep.h | 20 -------------------- linux-user/host/ppc64/hostdep.h | 20 -------------------- linux-user/host/riscv/hostdep.h | 20 -------------------- linux-user/host/s390x/hostdep.h | 20 -------------------- linux-user/host/x86_64/hostdep.h | 20 -------------------- linux-user/signal.c | 18 +++++++++++++++++- 8 files changed, 17 insertions(+), 141 deletions(-) diff --git a/linux-user/host/aarch64/hostdep.h b/linux-user/host/aarch64/hostdep.h index a8d41a21ad..39299d798a 100644 --- a/linux-user/host/aarch64/hostdep.h +++ b/linux-user/host/aarch64/hostdep.h @@ -15,24 +15,4 @@ /* We have a safe-syscall.inc.S */ #define HAVE_SAFE_SYSCALL -#ifndef __ASSEMBLER__ - -/* These are defined by the safe-syscall.inc.S file */ -extern char safe_syscall_start[]; -extern char safe_syscall_end[]; - -/* Adjust the signal context to rewind out of safe-syscall if we're in it */ -static inline void rewind_if_in_safe_syscall(void *puc) -{ - ucontext_t *uc = puc; - __u64 *pcreg = &uc->uc_mcontext.pc; - - if (*pcreg > (uintptr_t)safe_syscall_start - && *pcreg < (uintptr_t)safe_syscall_end) { - *pcreg = (uintptr_t)safe_syscall_start; - } -} - -#endif /* __ASSEMBLER__ */ - #endif diff --git a/linux-user/host/arm/hostdep.h b/linux-user/host/arm/hostdep.h index 9276fe6ceb..86b137875a 100644 --- a/linux-user/host/arm/hostdep.h +++ b/linux-user/host/arm/hostdep.h @@ -15,24 +15,4 @@ /* We have a safe-syscall.inc.S */ #define HAVE_SAFE_SYSCALL -#ifndef __ASSEMBLER__ - -/* These are defined by the safe-syscall.inc.S file */ -extern char safe_syscall_start[]; -extern char safe_syscall_end[]; - -/* Adjust the signal context to rewind out of safe-syscall if we're in it */ -static inline void rewind_if_in_safe_syscall(void *puc) -{ - ucontext_t *uc = puc; - unsigned long *pcreg = &uc->uc_mcontext.arm_pc; - - if (*pcreg > (uintptr_t)safe_syscall_start - && *pcreg < (uintptr_t)safe_syscall_end) { - *pcreg = (uintptr_t)safe_syscall_start; - } -} - -#endif /* __ASSEMBLER__ */ - #endif diff --git a/linux-user/host/i386/hostdep.h b/linux-user/host/i386/hostdep.h index 073be74d87..ce7136501f 100644 --- a/linux-user/host/i386/hostdep.h +++ b/linux-user/host/i386/hostdep.h @@ -15,24 +15,4 @@ /* We have a safe-syscall.inc.S */ #define HAVE_SAFE_SYSCALL -#ifndef __ASSEMBLER__ - -/* These are defined by the safe-syscall.inc.S file */ -extern char safe_syscall_start[]; -extern char safe_syscall_end[]; - -/* Adjust the signal context to rewind out of safe-syscall if we're in it */ -static inline void rewind_if_in_safe_syscall(void *puc) -{ - ucontext_t *uc = puc; - greg_t *pcreg = &uc->uc_mcontext.gregs[REG_EIP]; - - if (*pcreg > (uintptr_t)safe_syscall_start - && *pcreg < (uintptr_t)safe_syscall_end) { - *pcreg = (uintptr_t)safe_syscall_start; - } -} - -#endif /* __ASSEMBLER__ */ - #endif diff --git a/linux-user/host/ppc64/hostdep.h b/linux-user/host/ppc64/hostdep.h index 98979ad917..0c290dd904 100644 --- a/linux-user/host/ppc64/hostdep.h +++ b/linux-user/host/ppc64/hostdep.h @@ -15,24 +15,4 @@ /* We have a safe-syscall.inc.S */ #define HAVE_SAFE_SYSCALL -#ifndef __ASSEMBLER__ - -/* These are defined by the safe-syscall.inc.S file */ -extern char safe_syscall_start[]; -extern char safe_syscall_end[]; - -/* Adjust the signal context to rewind out of safe-syscall if we're in it */ -static inline void rewind_if_in_safe_syscall(void *puc) -{ - ucontext_t *uc = puc; - unsigned long *pcreg = &uc->uc_mcontext.gp_regs[PT_NIP]; - - if (*pcreg > (uintptr_t)safe_syscall_start - && *pcreg < (uintptr_t)safe_syscall_end) { - *pcreg = (uintptr_t)safe_syscall_start; - } -} - -#endif /* __ASSEMBLER__ */ - #endif diff --git a/linux-user/host/riscv/hostdep.h b/linux-user/host/riscv/hostdep.h index 2ba07456ae..7f67c22868 100644 --- a/linux-user/host/riscv/hostdep.h +++ b/linux-user/host/riscv/hostdep.h @@ -11,24 +11,4 @@ /* We have a safe-syscall.inc.S */ #define HAVE_SAFE_SYSCALL -#ifndef __ASSEMBLER__ - -/* These are defined by the safe-syscall.inc.S file */ -extern char safe_syscall_start[]; -extern char safe_syscall_end[]; - -/* Adjust the signal context to rewind out of safe-syscall if we're in it */ -static inline void rewind_if_in_safe_syscall(void *puc) -{ - ucontext_t *uc = puc; - unsigned long *pcreg = &uc->uc_mcontext.__gregs[REG_PC]; - - if (*pcreg > (uintptr_t)safe_syscall_start - && *pcreg < (uintptr_t)safe_syscall_end) { - *pcreg = (uintptr_t)safe_syscall_start; - } -} - -#endif /* __ASSEMBLER__ */ - #endif diff --git a/linux-user/host/s390x/hostdep.h b/linux-user/host/s390x/hostdep.h index 4f0171f36f..d801145854 100644 --- a/linux-user/host/s390x/hostdep.h +++ b/linux-user/host/s390x/hostdep.h @@ -15,24 +15,4 @@ /* We have a safe-syscall.inc.S */ #define HAVE_SAFE_SYSCALL -#ifndef __ASSEMBLER__ - -/* These are defined by the safe-syscall.inc.S file */ -extern char safe_syscall_start[]; -extern char safe_syscall_end[]; - -/* Adjust the signal context to rewind out of safe-syscall if we're in it */ -static inline void rewind_if_in_safe_syscall(void *puc) -{ - ucontext_t *uc = puc; - unsigned long *pcreg = &uc->uc_mcontext.psw.addr; - - if (*pcreg > (uintptr_t)safe_syscall_start - && *pcreg < (uintptr_t)safe_syscall_end) { - *pcreg = (uintptr_t)safe_syscall_start; - } -} - -#endif /* __ASSEMBLER__ */ - #endif diff --git a/linux-user/host/x86_64/hostdep.h b/linux-user/host/x86_64/hostdep.h index a4fefb5114..9c62bd26bd 100644 --- a/linux-user/host/x86_64/hostdep.h +++ b/linux-user/host/x86_64/hostdep.h @@ -15,24 +15,4 @@ /* We have a safe-syscall.inc.S */ #define HAVE_SAFE_SYSCALL -#ifndef __ASSEMBLER__ - -/* These are defined by the safe-syscall.inc.S file */ -extern char safe_syscall_start[]; -extern char safe_syscall_end[]; - -/* Adjust the signal context to rewind out of safe-syscall if we're in it */ -static inline void rewind_if_in_safe_syscall(void *puc) -{ - ucontext_t *uc = puc; - greg_t *pcreg = &uc->uc_mcontext.gregs[REG_RIP]; - - if (*pcreg > (uintptr_t)safe_syscall_start - && *pcreg < (uintptr_t)safe_syscall_end) { - *pcreg = (uintptr_t)safe_syscall_start; - } -} - -#endif /* __ASSEMBLER__ */ - #endif diff --git a/linux-user/signal.c b/linux-user/signal.c index 81c45bfce9..dafdf46b93 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -793,7 +793,23 @@ int queue_signal(CPUArchState *env, int sig, int si_type, return 1; /* indicates that the signal was queued */ } -#ifndef HAVE_SAFE_SYSCALL +#ifdef HAVE_SAFE_SYSCALL +/* These are defined by the safe-syscall.inc.S file */ +extern char safe_syscall_start[]; +extern char safe_syscall_end[]; + +/* Adjust the signal context to rewind out of safe-syscall if we're in it */ +static inline void rewind_if_in_safe_syscall(void *puc) +{ + ucontext_t *uc = (ucontext_t *)puc; + uintptr_t pcreg = host_signal_pc(uc); + + if (pcreg > (uintptr_t)safe_syscall_start + && pcreg < (uintptr_t)safe_syscall_end) { + host_signal_set_pc(uc, (uintptr_t)safe_syscall_start); + } +} +#else static inline void rewind_if_in_safe_syscall(void *puc) { /* Default version: never rewind */ From patchwork Mon Nov 8 02:37:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1552108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=w9LuMrJ1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hnb835wsYz9s0r for ; Mon, 8 Nov 2021 13:45:39 +1100 (AEDT) Received: from [::1] (port=43932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjufB-0001o7-LW for incoming@patchwork.ozlabs.org; Sun, 07 Nov 2021 21:45:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjudd-0001jF-Lf for qemu-devel@nongnu.org; Sun, 07 Nov 2021 21:44:05 -0500 Received: from [2607:f8b0:4864:20::731] (port=45791 helo=mail-qk1-x731.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjudb-0005Yo-PW for qemu-devel@nongnu.org; Sun, 07 Nov 2021 21:44:01 -0500 Received: by mail-qk1-x731.google.com with SMTP id n15so14243446qkp.12 for ; Sun, 07 Nov 2021 18:43:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UsOSCtGoBAQxcg5JxOa/5YjOm67k4i+bTjj+7kzrnNs=; b=w9LuMrJ1LOJo3Bfr/YUWkhlGMr6JTdgZyvfSHUHfHO3P9EMsXIFolPjUvYwoG9vgjr bNX51vXhcP2UrT/WQP2NpAhojkd3mDxBd+/lih+k3UFkECYa33Co2JgumYpOr4BffEzT JzDFmZMo1YUAQ7osP5gZq2f+ciSGOJntAyALZ1CpQtIstptDR/KRNVqcdbNtY8UpTg6k 5JtdCSeTGziv3RortQ/jaHZv/IWXQCa2QVFJ7VtqR/pyyAzmb9IhNxoHDmWVnie4Ybvd l9UjYeF84DP6ffFr+G7yZ+oSbNB3AKMFr7OmIZXI0kyeCkSTxXnwZ4cPdfC4QLiaqnj/ jyRQ== 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=UsOSCtGoBAQxcg5JxOa/5YjOm67k4i+bTjj+7kzrnNs=; b=hyAN6bL+7jPzcD7FwNQsGdTz32XfcGXOrjp7ALZXFdVcc6n0gOaXKNCS+roJ8D9LLq EI7LhX7aEg+uHfONAz4Zn183sV9VR3dlM8V/ZaaADWaLZN+T/SyabbDXmJqoaUqeru29 07BJ8wxAoL7pbdPmINKF1x0TbtV56t775uv/Zo/zQaLM2LSJBCdrBPLd3RuXqp9yQDi6 J9blmRtgsWcTvEM1bAMYMtP7/HRZOIi2dr//uaSnJNGe894RnmdAF9ICPAVx/0Hg99F2 ezO8hMthDvZrl1iBhGQ/pyci2P9IhofufPzL0Nh7qZX3WzjGegvvGtX+xl+tjXsI+hoy N/ow== X-Gm-Message-State: AOAM531stJ8y0hsJbvIFelodoqM82EaR6XRvXD/SpoT+LpXqhVHn18Dp WZdPV1iwYtglYECuHGeAcqMBf/8YepLoUA== X-Google-Smtp-Source: ABdhPJwfwmYorrbfMHuc3HW0G10OPjWRYuzY6HcoB2bGXx2XiYY1XGwbelO21SE5BnyBf8hJl5VEyQ== X-Received: by 2002:a05:6638:14c2:: with SMTP id l2mr8438156jak.45.1636339093287; Sun, 07 Nov 2021 18:38:13 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id m2sm9030284iow.6.2021.11.07.18.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 18:38:12 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [RFC 3/4] linux-user/safe-syscall.inc.S: Move to common-user Date: Sun, 7 Nov 2021 19:37:37 -0700 Message-Id: <20211108023738.42125-4-imp@bsdimp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211108023738.42125-1-imp@bsdimp.com> References: <20211108023738.42125-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::731 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::731; envelope-from=imp@bsdimp.com; helo=mail-qk1-x731.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , Laurent Vivier , Warner Losh , Philippe Mathieu-Daude Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Move all the safe_syscall.inc.S files to common-user. They are almost identical between linux-user and bsd-user to re-use. Signed-off-by: Warner Losh --- {linux-user => common-user}/host/aarch64/safe-syscall.inc.S | 0 {linux-user => common-user}/host/arm/safe-syscall.inc.S | 0 {linux-user => common-user}/host/i386/safe-syscall.inc.S | 0 {linux-user => common-user}/host/ppc64/safe-syscall.inc.S | 0 {linux-user => common-user}/host/riscv/safe-syscall.inc.S | 0 {linux-user => common-user}/host/s390x/safe-syscall.inc.S | 0 {linux-user => common-user}/host/x86_64/safe-syscall.inc.S | 0 meson.build | 1 + 8 files changed, 1 insertion(+) rename {linux-user => common-user}/host/aarch64/safe-syscall.inc.S (100%) rename {linux-user => common-user}/host/arm/safe-syscall.inc.S (100%) rename {linux-user => common-user}/host/i386/safe-syscall.inc.S (100%) rename {linux-user => common-user}/host/ppc64/safe-syscall.inc.S (100%) rename {linux-user => common-user}/host/riscv/safe-syscall.inc.S (100%) rename {linux-user => common-user}/host/s390x/safe-syscall.inc.S (100%) rename {linux-user => common-user}/host/x86_64/safe-syscall.inc.S (100%) diff --git a/linux-user/host/aarch64/safe-syscall.inc.S b/common-user/host/aarch64/safe-syscall.inc.S similarity index 100% rename from linux-user/host/aarch64/safe-syscall.inc.S rename to common-user/host/aarch64/safe-syscall.inc.S diff --git a/linux-user/host/arm/safe-syscall.inc.S b/common-user/host/arm/safe-syscall.inc.S similarity index 100% rename from linux-user/host/arm/safe-syscall.inc.S rename to common-user/host/arm/safe-syscall.inc.S diff --git a/linux-user/host/i386/safe-syscall.inc.S b/common-user/host/i386/safe-syscall.inc.S similarity index 100% rename from linux-user/host/i386/safe-syscall.inc.S rename to common-user/host/i386/safe-syscall.inc.S diff --git a/linux-user/host/ppc64/safe-syscall.inc.S b/common-user/host/ppc64/safe-syscall.inc.S similarity index 100% rename from linux-user/host/ppc64/safe-syscall.inc.S rename to common-user/host/ppc64/safe-syscall.inc.S diff --git a/linux-user/host/riscv/safe-syscall.inc.S b/common-user/host/riscv/safe-syscall.inc.S similarity index 100% rename from linux-user/host/riscv/safe-syscall.inc.S rename to common-user/host/riscv/safe-syscall.inc.S diff --git a/linux-user/host/s390x/safe-syscall.inc.S b/common-user/host/s390x/safe-syscall.inc.S similarity index 100% rename from linux-user/host/s390x/safe-syscall.inc.S rename to common-user/host/s390x/safe-syscall.inc.S diff --git a/linux-user/host/x86_64/safe-syscall.inc.S b/common-user/host/x86_64/safe-syscall.inc.S similarity index 100% rename from linux-user/host/x86_64/safe-syscall.inc.S rename to common-user/host/x86_64/safe-syscall.inc.S diff --git a/meson.build b/meson.build index 26c58123e9..6f7acc8936 100644 --- a/meson.build +++ b/meson.build @@ -2883,6 +2883,7 @@ foreach target : target_dirs if 'CONFIG_LINUX_USER' in config_target base_dir = 'linux-user' target_inc += include_directories('linux-user/host/' / config_host['ARCH']) + target_inc += include_directories('common-user/host/' / config_host['ARCH']) endif if 'CONFIG_BSD_USER' in config_target base_dir = 'bsd-user' From patchwork Mon Nov 8 02:37:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1552112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20210112.gappssmtp.com header.i=@bsdimp-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=iWiohcwS; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnbCK19Vxz9s0r for ; Mon, 8 Nov 2021 13:48:27 +1100 (AEDT) Received: from [::1] (port=52122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjuht-0007R6-I2 for incoming@patchwork.ozlabs.org; Sun, 07 Nov 2021 21:48:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjueo-00031C-Sb for qemu-devel@nongnu.org; Sun, 07 Nov 2021 21:45:16 -0500 Received: from [2607:f8b0:4864:20::729] (port=45012 helo=mail-qk1-x729.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjuem-0005iS-KW for qemu-devel@nongnu.org; Sun, 07 Nov 2021 21:45:14 -0500 Received: by mail-qk1-x729.google.com with SMTP id bj27so12616114qkb.11 for ; Sun, 07 Nov 2021 18:45:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QM8P6vA6pWnuv+Hy7+9bIDhpoDEGw1El8RwQH909eMg=; b=iWiohcwSc3a7WtOW5w5HIw+cG5KlcsMwzlCjiGDkG4zxZfVPbJ5SoWcsNTUcZ7UtHw 5T3twnTC9iNUyCAO/uHdAExMPiB6sU6eCrwmTDNmkqreFRTTwGNmcLX6RgGdjClVspRc 0GIAVpyQioo3QS6Tga/8kcc5y8njCXJyZzHQMgAy4Q59SKULjjap4CaCCeEfbvoRdKvP xLJZuPAVG1EPT3vQvYVxOj9FVr1c9Fy3tLfXXr+k7TX9VjaRCNnJdDQ4ZslBKzKlrKVc 6uo85SoXjnEVe14KWATv6cSYUNZYf0y3wHbO2q9zpBjwQtcXL98Bpi/MbOMVr1hrQO3V 2wiw== 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=QM8P6vA6pWnuv+Hy7+9bIDhpoDEGw1El8RwQH909eMg=; b=YENjTh40LKplfA3hR4opCa8GIR06oUOAjji5mwY8zpMnbi2auxNw28hiQiaEbDeDqV 9F3LYfAeGlozVsJSkhWpifVgQoVkdWYkriThfOS4qmIC5X8Xc5klVp0qFoU+pGSHqF+b 4IcxBxoVR3UIfr1492oGwWPQ+pohXp+V7D6N22rCQGOSAiOcZtUOCWNbNpddsVuk8GSZ kiVZ7QwRJlcFOx+ij570q5zJ4xI9bTeWDD1XT8/rfd9KATPjeSXKvvTcZEcZecJ9RkkN iQs2KYBWfp2M7PqsRk/1p+/omJF4UP5ARd9DWAYIVx7+8+O3JjDbEN45ZxKmgMKU55co c7Ug== X-Gm-Message-State: AOAM531y1gr9lvwOTP6xZ77MDjdHF7EhqlhjjcPgRO6I5i4NwAPZgVFY dvIkVpP2A05yQSx72XWIamwXW/sbLzzZLQ== X-Google-Smtp-Source: ABdhPJz3eYaDzxnJKgOLnqOX2xI4HrSS/nuKt8JbyTI0OKTntUMIO0ydh7/nEVDgbNCeW97P4i3LTA== X-Received: by 2002:a02:2a04:: with SMTP id w4mr21541594jaw.107.1636339094116; Sun, 07 Nov 2021 18:38:14 -0800 (PST) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id m2sm9030284iow.6.2021.11.07.18.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Nov 2021 18:38:13 -0800 (PST) From: Warner Losh To: qemu-devel@nongnu.org Subject: [RFC 4/4] common-user: Allow return codes to be adjusted after sytsem call Date: Sun, 7 Nov 2021 19:37:38 -0700 Message-Id: <20211108023738.42125-5-imp@bsdimp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211108023738.42125-1-imp@bsdimp.com> References: <20211108023738.42125-1-imp@bsdimp.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::729 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::729; envelope-from=imp@bsdimp.com; helo=mail-qk1-x729.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , Laurent Vivier , Warner Losh , Philippe Mathieu-Daude Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" All the *-users generally use the Linux style of negative return codes for errno. However, other systems, like FreeBSD, have a different convention. Allow those systems to insert code after the syscall that adjusts the return value of the system call to match the native linux format. Signed-off-by: Warner Losh --- common-user/host/aarch64/safe-syscall.inc.S | 1 + common-user/host/arm/safe-syscall.inc.S | 1 + common-user/host/i386/safe-syscall.inc.S | 1 + common-user/host/ppc64/safe-syscall.inc.S | 1 + common-user/host/riscv/safe-syscall.inc.S | 1 + common-user/host/s390x/safe-syscall.inc.S | 1 + common-user/host/x86_64/safe-syscall.inc.S | 1 + linux-user/safe-syscall.S | 1 + 8 files changed, 8 insertions(+) diff --git a/common-user/host/aarch64/safe-syscall.inc.S b/common-user/host/aarch64/safe-syscall.inc.S index bc1f5a9792..81d83e8e79 100644 --- a/common-user/host/aarch64/safe-syscall.inc.S +++ b/common-user/host/aarch64/safe-syscall.inc.S @@ -64,6 +64,7 @@ safe_syscall_start: svc 0x0 safe_syscall_end: /* code path for having successfully executed the syscall */ + ADJUST_SYSCALL_RETCODE ret 0: diff --git a/common-user/host/arm/safe-syscall.inc.S b/common-user/host/arm/safe-syscall.inc.S index 88c4958504..40e9a5e28d 100644 --- a/common-user/host/arm/safe-syscall.inc.S +++ b/common-user/host/arm/safe-syscall.inc.S @@ -78,6 +78,7 @@ safe_syscall_start: swi 0 safe_syscall_end: /* code path for having successfully executed the syscall */ + ADJUST_SYSCALL_RETCODE pop { r4, r5, r6, r7, r8, pc } 1: diff --git a/common-user/host/i386/safe-syscall.inc.S b/common-user/host/i386/safe-syscall.inc.S index 9e58fc6504..eb6b43bd81 100644 --- a/common-user/host/i386/safe-syscall.inc.S +++ b/common-user/host/i386/safe-syscall.inc.S @@ -75,6 +75,7 @@ safe_syscall_start: int $0x80 safe_syscall_end: /* code path for having successfully executed the syscall */ + ADJUST_SYSCALL_RETCODE pop %ebx .cfi_remember_state .cfi_adjust_cfa_offset -4 diff --git a/common-user/host/ppc64/safe-syscall.inc.S b/common-user/host/ppc64/safe-syscall.inc.S index 875133173b..974bd03f8d 100644 --- a/common-user/host/ppc64/safe-syscall.inc.S +++ b/common-user/host/ppc64/safe-syscall.inc.S @@ -75,6 +75,7 @@ safe_syscall_start: sc safe_syscall_end: /* code path when we did execute the syscall */ + ADJUST_SYSCALL_RETCODE ld 14, 16(1) /* restore r14 to its original value */ bnslr+ diff --git a/common-user/host/riscv/safe-syscall.inc.S b/common-user/host/riscv/safe-syscall.inc.S index 9ca3fbfd1e..a4bd5c5c72 100644 --- a/common-user/host/riscv/safe-syscall.inc.S +++ b/common-user/host/riscv/safe-syscall.inc.S @@ -66,6 +66,7 @@ safe_syscall_start: scall safe_syscall_end: /* code path for having successfully executed the syscall */ + ADJUST_SYSCALL_RETCODE ret 0: diff --git a/common-user/host/s390x/safe-syscall.inc.S b/common-user/host/s390x/safe-syscall.inc.S index 414b44ad38..4ba60fbed0 100644 --- a/common-user/host/s390x/safe-syscall.inc.S +++ b/common-user/host/s390x/safe-syscall.inc.S @@ -76,6 +76,7 @@ safe_syscall_start: jne 2f svc 0 safe_syscall_end: + ADJUST_SYSCALL_RETCODE 1: lg %r15,0(%r15) /* load back chain */ .cfi_remember_state diff --git a/common-user/host/x86_64/safe-syscall.inc.S b/common-user/host/x86_64/safe-syscall.inc.S index f36992daa3..e1ae6f83e6 100644 --- a/common-user/host/x86_64/safe-syscall.inc.S +++ b/common-user/host/x86_64/safe-syscall.inc.S @@ -72,6 +72,7 @@ safe_syscall_start: syscall safe_syscall_end: /* code path for having successfully executed the syscall */ + ADJUST_SYSCALL_RETCODE pop %rbp .cfi_remember_state .cfi_def_cfa_offset 8 diff --git a/linux-user/safe-syscall.S b/linux-user/safe-syscall.S index 42ea7c40ba..0d6dd19398 100644 --- a/linux-user/safe-syscall.S +++ b/linux-user/safe-syscall.S @@ -17,6 +17,7 @@ * so that this will pull in the right fragment for the architecture. */ #ifdef HAVE_SAFE_SYSCALL +#define ADJUST_SYSCALL_RETCODE /* No adjustment for linux */ #include "safe-syscall.inc.S" #endif