From patchwork Tue Apr 9 05:02:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787186 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57816wrs; Mon, 8 Apr 2024 22:06:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWWekKVIjhgKzQZCmYk6sZP0uEoOd8StwdToiZCiIrgBFfiAaJtL8ApMUUCEBWPJ2378es5ZiKMcTSt47nM9nmx X-Google-Smtp-Source: AGHT+IFykNwOCRzRdTUHfYqC4Noj0QtuAAJyhGT9/60aQAkWxR2SLR9okHSuW19Fr/1h7AkGs7fK X-Received: by 2002:a05:620a:13f9:b0:78d:6a00:c49e with SMTP id h25-20020a05620a13f900b0078d6a00c49emr3094700qkl.16.1712639208556; Mon, 08 Apr 2024 22:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639208; cv=none; d=google.com; s=arc-20160816; b=boQAZc0aaa/KYta2N1faVFROfY77URFGxZomEuOSl6N4kjtAA2jJ+A85QJ6jgmFKNk qwihQ6yTI1TCoAZZPA7uFJ5GGLbkSho8RbWsqYXBzYyiPTEDEPHnx/b2xIuzzYtvZCDo yRWis9t7Q3JMb/HvKTn6bODCmX29dsozXZ+RzDLvWwUoxldVR0fr5Hy90lQTeZy66A7T Nhz579EeChbvSTOYzzd/r6rZmS60rtAGVV6PPtWAFOQnWH+gFoQ+VYLYJI6/qH/LMUGC XF3NUIHlawHXKNDuN3qpPr8x/WV9kGWRfHnxEaXD4pkuVFCjE/mg514NNvUSqCF3T7L5 fdtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=ywDEWaMPHCkZHNZHZvDhBEB+D4W5S61RGKLaVoHCr7o=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=gGDZenfMbMNHT7JEDSspkcZV9z7aJofvvUvBeSW3C781HnKuW2jLp58eQUN/Bz0u8R 4ucemmoXci5rRn4QsY3EwMF6zctnayQaKjBOdBNMCSgGt1rYsaf/C3UW51k5nWyoCG0v A8GrJvmlDWLXuJ0VJqXBQPqNNH2uV+oy8jOyOCcp6/cuCW+nXi5+PJrIQ8ejuj7dDLOg 7k40xKvO5kubUQmC0sFH4GPRZt93IpkdbvaQb+0POuOTzDRRVlmyy1P2k2zRn+mtaWS1 605HdA2nbQXAzwWPa28cmqVbaAaSi7jF/B5LnbWbc6/JYVt3oIosNAJtCxa9k0g1N7hz gfdQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CF2bkEmh; 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=pass (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 e18-20020a05620a209200b0078d5d4df212si6084508qka.396.2024.04.08.22.06.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:06: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=pass header.i=@linaro.org header.s=google header.b=CF2bkEmh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ru3du-0003DK-7E; Tue, 09 Apr 2024 01:03:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ru3ds-0003D8-Lm for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:32 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dr-0005LT-2c for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:32 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6ed04c91c46so3408112b3a.0 for ; Mon, 08 Apr 2024 22:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639010; x=1713243810; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ywDEWaMPHCkZHNZHZvDhBEB+D4W5S61RGKLaVoHCr7o=; b=CF2bkEmh2up95Lwedu0z6rIg10INFCUnGDgZL3GsGZWRYwjkgpHbfrgDKoCfih+RWX 9PCNICrWKyrWp0hH34ENm0rjQmSJWU6TrEOg9lmlQXP2E2Wj2BH5+V9U4+r4v5ViEWp9 3GsBhO9/g1Ac9d0MgsSVE5dC27Or33Ep5ikHBlq/22/Ij8uRz268CtISFIzG0nEgIA/J 0GtNmk91oOEloPjiaCPdKQaNB/VcM0z6BlCRhVzzJzPFFniu+ajuUECkCLrjEiLW1Ef4 f3wvh2cbzm/S3/Alnn+zR85XFO0P0FHqtVuRPvNjgT9JU5nCy3ckDetA3VbDjQHGC/bt XZhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639010; x=1713243810; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ywDEWaMPHCkZHNZHZvDhBEB+D4W5S61RGKLaVoHCr7o=; b=MkffxL8TLAny2bxAGFG1dy1dhTj3PVmUSt9TX9m7uB7H5ZAfzhN+ywk+0iBGteX1GB bc5GXp2y2bSnuE9u2rd2VhcGouqIkgUrALKM9xA0S+xmX1FJcp+eAC9qb011T5Q2LO/P Igo/gde08inzNyV0c5vicLMqM6PIiSOhzmgBRuR/3tcgJra1k6SMemmftUW8M0DI02JS yftsGE0Ob+/N8BzSeW+ncjwV4lHbFYAB8ep51g3wvNaOqlU/TKz1eQikCw08Nd/u/pYE KTkNcijUimSw4388zeW/s2cMPTZyYZxhsXRpfuqNdyIc9E1l4vZc+cAFDaHvc7DILHGR vDMg== X-Gm-Message-State: AOJu0YzR3csnmsZJY7tsDZVzHXoxdybo7xI2DxsBbs1SjslZRtZRX2Jh x1lE+E647jZJV83kSghkqyegD47qvFOwRi/6k+2fzZUcGeCTk1GIzRcd/OghLI1/PBk5IsrVuJ3 c X-Received: by 2002:a05:6a00:852:b0:6ec:f28b:659f with SMTP id q18-20020a056a00085200b006ecf28b659fmr14320620pfk.3.1712639009803; Mon, 08 Apr 2024 22:03:29 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 20/28] linux-user/i386: Return boolean success from restore_sigcontext Date: Mon, 8 Apr 2024 19:02:54 -1000 Message-Id: <20240409050302.1523277-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Invert the sense of the return value and use bool. Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 51 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index f8cc0cff07..1571ff8553 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -563,12 +563,12 @@ static int xrstor_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxsave, return 0; } -static int -restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) +static bool restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) { - int err = 1; abi_ulong fpstate_addr; unsigned int tmpflags; + struct target_fpstate *fpstate; + bool ok; #ifndef TARGET_X86_64 cpu_x86_load_seg(env, R_GS, tswap16(sc->gs)); @@ -616,29 +616,27 @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) // regs->orig_eax = -1; /* disable syscall checks */ fpstate_addr = tswapl(sc->fpstate); - if (fpstate_addr != 0) { - struct target_fpstate *fpstate; - if (!lock_user_struct(VERIFY_READ, fpstate, fpstate_addr, - sizeof(struct target_fpstate))) { - return err; - } -#ifndef TARGET_X86_64 - if (!(env->features[FEAT_1_EDX] & CPUID_FXSR)) { - cpu_x86_frstor(env, fpstate_addr, 1); - err = 0; - } else { - err = xrstor_sigcontext(env, &fpstate->fxstate, - fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); - } -#else - err = xrstor_sigcontext(env, fpstate, fpstate_addr); -#endif - unlock_user_struct(fpstate, fpstate_addr, 0); - } else { - err = 0; + if (fpstate_addr == 0) { + return true; } + if (!lock_user_struct(VERIFY_READ, fpstate, fpstate_addr, + sizeof(struct target_fpstate))) { + return false; + } +#ifndef TARGET_X86_64 + if (!(env->features[FEAT_1_EDX] & CPUID_FXSR)) { + cpu_x86_frstor(env, fpstate_addr, 1); + ok = true; + } else { + ok = !xrstor_sigcontext(env, &fpstate->fxstate, + fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); + } +#else + ok = !xrstor_sigcontext(env, fpstate, fpstate_addr); +#endif + unlock_user_struct(fpstate, fpstate_addr, 0); - return err; + return ok; } /* Note: there is no sigreturn on x86_64, there is only rt_sigreturn */ @@ -664,8 +662,9 @@ long do_sigreturn(CPUX86State *env) set_sigmask(&set); /* restore registers */ - if (restore_sigcontext(env, &frame->sc)) + if (!restore_sigcontext(env, &frame->sc)) { goto badframe; + } unlock_user_struct(frame, frame_addr, 0); return -QEMU_ESIGRETURN; @@ -689,7 +688,7 @@ long do_rt_sigreturn(CPUX86State *env) target_to_host_sigset(&set, &frame->uc.tuc_sigmask); set_sigmask(&set); - if (restore_sigcontext(env, &frame->uc.tuc_mcontext)) { + if (!restore_sigcontext(env, &frame->uc.tuc_mcontext)) { goto badframe; }