From patchwork Mon May 27 00:49:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 799196 Delivered-To: patch@linaro.org Received: by 2002:a5d:6a47:0:b0:354:fb4b:99cd with SMTP id t7csp1658345wrw; Sun, 26 May 2024 17:54:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWq5X0SxLg7Uhyz2E3pYssfLw2PzTSPrtHdeOsvkrwHZa0c1K9HeSx/Wq8M58wMTFB41EoZzCXqZZq4nnN5Oyo+ X-Google-Smtp-Source: AGHT+IFeLpKMW2pqIRZZeT77uIol1Yzq9IejxeWqUaHE9J9oB62F4n1bKhkUqEoqhvD6Xvo/3yah X-Received: by 2002:a05:6102:58c8:b0:47b:a44d:1ca5 with SMTP id ada2fe7eead31-48a385361a5mr8336107137.10.1716771251055; Sun, 26 May 2024 17:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716771251; cv=none; d=google.com; s=arc-20160816; b=xjv6015RG1EXg/8AIX3E7URyJePzfQVPVXXKW+Xl6QzHas51n+DHgALGTt9UZBuWIK Lw0BO8SB/mDY930qGnSBRkGBNgKKuksp3u8fMt9sU3smkbWWDxYyGgW/2nVHBIf67MOw pQK2CxjOJSs9dI3nH4HsM0tnDwt6qNecmGnjUeT6Wmv56VXPV4Vbp2Vf+B8PO0sDFD0T PD5csRSgyU6TjgPDJzJIEeFSbzMr8n1nwG680bJgeylIWz0vqVKdUPZtYd3NX4AqMdQe sYvMR3+QO0l9dbr0W/lyuNVj2agb4YzHTQ1ArCosQbG1VmFYzLUk1WGv2baYLQoO/hBF kmvQ== 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:cc:to :from:dkim-signature; bh=A/3mRVbjkwDF9eBMMUHlCcFHLaNSo0keoR5CYS7AGJ4=; fh=OTkfrEnbNDInppsfj4HB8z6V33zCj7LOct256XBfW6M=; b=GcMfwgvbBfQN+Y51cIiYp4AYtz/M+KZTFDo2/dxFBt4aqbiIzZJoOQlmFfaqOlBWe8 gZ8lDEk2X75TNSh/ulablJsuCgSwl2SCOXHrjAgmnXCzdfG4gwDgcH+W1APMl6vwrhOa L4htR7fwxq+0HbgADBOT4VfKJKZnhAPXtQvMzjrOPt+uteEpfHRtCC+6Wzrblee+YIlb B6rSJ79g4uxhKshuVEqTpJx1ugWhiOEVlBDm6WlwF32Dk2PTaHAzUGCF9fiybvmJiNoK hlCmECrg0DlnnSml/C0aFj4p/3GwUaNGXISlvF9LcYeUzgpguZH0t84Ko/vgUBusejPr lCWw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b4tx9VX2; 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 af79cd13be357-794abcab645si681240785a.142.2024.05.26.17.54.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 26 May 2024 17:54: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=pass header.i=@linaro.org header.s=google header.b=b4tx9VX2; 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 1sBOZM-0007HH-I8; Sun, 26 May 2024 20:50:32 -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 1sBOZJ-0007Cq-94 for qemu-devel@nongnu.org; Sun, 26 May 2024 20:50:29 -0400 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sBOZA-0003ga-Im for qemu-devel@nongnu.org; Sun, 26 May 2024 20:50:24 -0400 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-24ca21014ccso1196450fac.1 for ; Sun, 26 May 2024 17:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716771018; x=1717375818; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A/3mRVbjkwDF9eBMMUHlCcFHLaNSo0keoR5CYS7AGJ4=; b=b4tx9VX2ipo3QWJaCnvPeV8jHd8yj1SiW2CVowcTU/pl05dR1wZRAxJ4b0A1aoz78s Qx/8U4UVQJI4uuFO0Tse14J3qSIbBN3rdBnJbIL+zw1aAVxjBfsxCkz/km3W+/+rwFSe OKT2CUUM5N/py7AuR1uE63mlxnYcpDwh4AIma4D1GAblyPcrEVg7AD7nm05hCrddMVH8 jqBrXEGQSuR3EyB6SWnMlJ/A3Pzjrwp7kvdrztiJxGfbxFJxeyHbqhubldZNXQImY7zp k+1zofvqLl4Vu/vNQtb6I1DKFFnjLRSWp1Q14ZzK17COZVFBJbG5yn25NQ6/ItrXhDGA sZ/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716771018; x=1717375818; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A/3mRVbjkwDF9eBMMUHlCcFHLaNSo0keoR5CYS7AGJ4=; b=UsO1NYG6zmEr+RLLSSEBpBbHqG19etmpyx00tB2VAtzJdZGtGS/7Wu/4aiiNkBxFnn nD2lWsePvwJd6dhYn7h0wfNqaoDS517lqX0mQ/SpWSRYBmo8cwxZ1H283eNk5/B7rSyj QNSNZzQuVw7jvzkwlxrcRFjaIDUhny4fHjD0aFEgxgvqYxTer3mrBIu5jFFK5AD6eb9U btJEC27S+xO9CAT7yo3UAa7zk4sqvLwsAiuWVcVgyamaGaGnn3bMSJEx/EehmPjAk6Pi dAOcj8qWvHfKMfLZqOAomcrBoXowfIGp1I2jv2CVsICo/uhKbu2AV+4eKfGWBJPfaBtB GZ9A== X-Gm-Message-State: AOJu0Yx9OLcOdEpULJP9qO9iOmMtu4dAWwPy5D6XEapOmHQWsFDu0VNm O0u+NTt8lNiCxfc5G9ZcxqZ55StgguctACyRDmSdMlKb2wVacEX59dT+14xnnzStehuzFljOPEt H X-Received: by 2002:a05:6870:e256:b0:24f:ef6b:353e with SMTP id 586e51a60fabf-24fef6b7416mr2348778fac.36.1716771018523; Sun, 26 May 2024 17:50:18 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f8fd6d7598sm3942958b3a.220.2024.05.26.17.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 17:50:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Paolo Bonzini Subject: [PULL 20/28] linux-user/i386: Return boolean success from restore_sigcontext Date: Sun, 26 May 2024 17:49:53 -0700 Message-Id: <20240527005001.642825-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240527005001.642825-1-richard.henderson@linaro.org> References: <20240527005001.642825-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::30; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x30.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, T_SCC_BODY_TEXT_LINE=-0.01 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. Reviewed-by: Paolo Bonzini 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 6763b4bda8..9e6d883ea1 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -564,12 +564,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)); @@ -617,29 +617,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 */ @@ -665,8 +663,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; @@ -690,7 +689,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; }