From patchwork Wed Jun 8 05:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 579815 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp5799592max; Tue, 7 Jun 2022 22:32:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFQSw4KdDLUv4vizIuQ5kmAQMKANsNpt847xQaX0kD1LCJ2xiZsP5QTrCY9Lqh1UOgsZQh X-Received: by 2002:a05:620a:404d:b0:6a7:d3d:df9b with SMTP id i13-20020a05620a404d00b006a70d3ddf9bmr158514qko.530.1654666350546; Tue, 07 Jun 2022 22:32:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666350; cv=none; d=google.com; s=arc-20160816; b=JkoAHc+IYIEyKbD4r9RRoEZj0F+1pKKCeMQfKNV5UHrhDHd3rgyDRwiu/X5YhdwEPQ c1LOuEPhosqbHYC/ULwYyyUECy3deUZahckqtwfCqlz/3YWl6+1t9Nkr5t7vCGu+4F2I nWL6aeOGKGSTWo5kDLMkwyzCzIOWnxDwmM/bZFBPKRxOc8cpYcz5IkpOD0MYSTDDY9qH HV0urD1W6tMOYrCze7ozWEx9apN1Pz7mTTHe2cHVf4rtsMuee6Y08Kyuv4dWB4UA0XUk 1T4UulFBEjrYX6sJIhuT6ngc4QB1yjcRoVE/XbZ17pfwJ5ADuKfVGv4LrXI60h8rvn0i r/2g== 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=qIoo0LzyvHSUbYXwQZj3nHuBOs19Duk2E4Vx8ekmqlk=; b=lSk2AQKxIvYHWCE2nsf8deLXZr/e4L6kNDrU4JD65oSX5aAm4lOt/SgfqRtfC+6zZI UCOgjJyrd5kMJJKFX01xU4HRYmj4HHu1XA5x4GkrXwxdYieZp+9tXARRq95KA1Ba6TB+ lPD9EmqTQ4/Zs+aUMWJCVk3N3tfY6mviGG+SQkh60k+JsqbSEiFbmKjlYXzboW2bSMt0 RzNGfSBxCjAcOM7TceBXhB5qNREqwc2mJKxz4pasH8FR0VxxDfUEBrq3RyyMRbsWL8Bh dph0weV4FFh28EolLXJCEMQFjV0B8X/Oq2gd0dWv/LRh05Idkj5U04nwb1Gz5Z2mLSoW JZ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q6r5wPFT; 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 b123-20020a379981000000b006a701dd36d9si524474qke.649.2022.06.07.22.32.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Jun 2022 22:32:30 -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=q6r5wPFT; 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]:52008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyoIw-0003Np-5Z for patch@linaro.org; Wed, 08 Jun 2022 01:32:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyo6p-0006zg-Nf for qemu-devel@nongnu.org; Wed, 08 Jun 2022 01:19:59 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:34584) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyo6n-00023x-5Y for qemu-devel@nongnu.org; Wed, 08 Jun 2022 01:19:59 -0400 Received: by mail-pf1-x436.google.com with SMTP id c196so17413536pfb.1 for ; Tue, 07 Jun 2022 22:19:56 -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=qIoo0LzyvHSUbYXwQZj3nHuBOs19Duk2E4Vx8ekmqlk=; b=q6r5wPFTvsqXnIBveexZxvp4k6gm/9xxQXvVVoMje8uveB2lxPwPsG49B9BexbOwbe 4yjy4sOopC+2wb+JYmzrXXMbYTwc1odjZWsV1McE6X0OPyg/oLOSHd/9ug3jgCS+Rkvz Srtp+XCA/QbqDRML/R+diJO242a9/eRWwTv/EshsHDM8cdCfofvLyvpTzLUPW4X04Pn+ E5rqktwNLSrAEOGdUmouiotxF5pC6BOxg5T9C20DbAkWMXeS8fIRkcM6TW9nKuTwXSBz 2XXdDvWi+9yPBt385RoXvxUX9OyQGU3N/sLX/WaWdh94Cv7pgSljWuCbNKy5EWAKHXXg gbQw== 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=qIoo0LzyvHSUbYXwQZj3nHuBOs19Duk2E4Vx8ekmqlk=; b=xTQpgEk8Sa42TrBYYnLO0CAIzcNFT1A7tmEBqzZRekEubCYrozSQV55Fk/3yvSX2PV Bg05LOZaE4FJxXQNNcZTUDOV6WWGRKfbUFjgjk2pryvXdiPr4JTYUWg3RL/ZA2AhrPa1 EEcy4tZM/dMEEeO8QI6JH+sAYgdPgyBDns9VEpm1OL40xHWrCMJNvzBpDVa4/hRzIHlw FeE3L84gf7R0OcnhRGiVWhpxq1RUmpc5+7gPPYGFBlRkL+hrWUh4x+vQMbRxfoC2X3uV 39KbXKqpVwRFkLE3+A+822rAd7rGBPauyGZ580rXDNrGatLMvIxFpS95Ousn5X8Gf+Nl ETgg== X-Gm-Message-State: AOAM531P3dmokzNBBypVNIPGshOT61vBiO92xXV7X2bhLTP2/IkbhzYW bkIrJHywLFp5F4U/GOSq1MYauaX3DR48zQ== X-Received: by 2002:a63:210e:0:b0:3fd:9c07:7670 with SMTP id h14-20020a63210e000000b003fd9c077670mr14256096pgh.222.1654665595764; Tue, 07 Jun 2022 22:19:55 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:c626:2f70:ac99:7c97]) by smtp.gmail.com with ESMTPSA id k8-20020a170902d58800b001641244d051sm13378807plh.257.2022.06.07.22.19.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:19:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: f4bug@amsat.org Subject: [PATCH v4 10/11] target/mips: Simplify UHI_argnlen and UHI_argn Date: Tue, 7 Jun 2022 22:19:44 -0700 Message-Id: <20220608051945.802339-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220608051945.802339-1-richard.henderson@linaro.org> References: <20220608051945.802339-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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" With semihosting_get_arg, we already have a check vs argc, so there's no point replicating it -- just check the result vs NULL. Merge copy_argn_to_target into its caller. Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 44 ++++++++++++++---------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index ae4b8849b1..b54267681e 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -198,21 +198,6 @@ static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int err) uhi_cb(cs, ret, err); } -static int copy_argn_to_target(CPUMIPSState *env, int arg_num, - target_ulong vaddr) -{ - int strsize = strlen(semihosting_get_arg(arg_num)) + 1; - char *dst = lock_user(VERIFY_WRITE, vaddr, strsize, 0); - if (!dst) { - report_fault(env); - } - - strcpy(dst, semihosting_get_arg(arg_num)); - - unlock_user(dst, vaddr, strsize); - return 0; -} - #define GET_TARGET_STRING(p, addr) \ do { \ p = lock_user_string(addr); \ @@ -285,18 +270,31 @@ void mips_semihosting(CPUMIPSState *env) gpr[2] = semihosting_get_argc(); break; case UHI_argnlen: - if (gpr[4] >= semihosting_get_argc()) { - gpr[2] = -1; - return; + { + const char *s = semihosting_get_arg(gpr[4]); + gpr[2] = s ? strlen(s) : -1; } - gpr[2] = strlen(semihosting_get_arg(gpr[4])); break; case UHI_argn: - if (gpr[4] >= semihosting_get_argc()) { - gpr[2] = -1; - return; + { + const char *s = semihosting_get_arg(gpr[4]); + target_ulong addr; + size_t len; + + if (!s) { + gpr[2] = -1; + break; + } + len = strlen(s) + 1; + addr = gpr[5]; + p = lock_user(VERIFY_WRITE, addr, len, 0); + if (!p) { + report_fault(env); + } + memcpy(p, s, len); + unlock_user(p, addr, len); + gpr[2] = 0; } - gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]); break; case UHI_plog: