From patchwork Tue Jul 12 20:53:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 589806 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp682390max; Tue, 12 Jul 2022 14:07:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sEgqQ8j5KTWrc04Diwra4vI3yUIwU7LMdCCoEiqhV0xPTScebLhx0QwGFi2tAMIX0Zy/Au X-Received: by 2002:a05:6214:4106:b0:473:399a:de6b with SMTP id kc6-20020a056214410600b00473399ade6bmr186340qvb.124.1657660055924; Tue, 12 Jul 2022 14:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657660055; cv=none; d=google.com; s=arc-20160816; b=oKB543F9uv/6x/eL4ng/uFPoOkEsrIF/dcBbas4yLOko+K2oksrsP6wKaeJP3ImU33 t0kAy630Al35toBA+5ioI9nh/ptshd5trZMMhjxjWnu8WySpmRlKfG0jwWPe44xhxqyV 7m4TyuK7qYNElrRbu8K3nouEYLUXdEx587IqdZAjoTeHTqOzsNCnLQ01aLt89+L25w73 FEAVDegpYXhvpY++AXLKtjDFvM/n2QcuBlxch/Xae8sm3VqA9XS2++bfkyHUVfk3qD9W V/8d1BVzdKTDaR2L5xw29+ldsjJfttdiYktSWH9X76HVFQ7A8ViXXsHfOLo7HL6Kvb0r FqUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=from:reply-to: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:dkim-signature; bh=MkJbeZ2YzCPPLGp8kgmOOD9tSwj1sJlRAj5pJts4/Ms=; b=Ojaalk5MwxPNZD3p5BmMF/h8J1aoTAA/4yxu83LF5r5wI2Mtk3Gt5AZp6p2HnC8pzJ zhJj6C8P5y8MPOjDgDEp5GF2nY3Zq23gHwFEKVyCW4wwO0+24rW298mHorafvnYstJ0r 0ehBcRqMW+YfcW0XMfHtbf6S/W3fFHq1FQvBWdKPCb9TuoUH2gQRk378lDDtt2Ix5Qqi mxhsAZro0JJGKEwSi2lFiIlF367v1V8JGhPL18Gar8CVkohh+N8ohYQDm5ziDG0f9gZx GvER+IEjFdcAug0ivFLDRqU0oGZSGLgUz77zLsfqKLe9yXL9dfZJzjUy4wrfhTAwCS0i PAuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=P1MxcxvG; 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=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id dx14-20020a05620a608e00b006b5a6f9c226si1366897qkb.314.2022.07.12.14.07.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2022 14:07:35 -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=@gmail.com header.s=20210112 header.b=P1MxcxvG; 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=nongnu.org Received: from localhost ([::1]:60374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBN6V-00055Q-Ir for patch@linaro.org; Tue, 12 Jul 2022 17:07:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBMuB-0006sa-K9 for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:51 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:37876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBMuA-0007Cw-5V for qemu-devel@nongnu.org; Tue, 12 Jul 2022 16:54:51 -0400 Received: by mail-wr1-x42c.google.com with SMTP id r10so6670483wrv.4 for ; Tue, 12 Jul 2022 13:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MkJbeZ2YzCPPLGp8kgmOOD9tSwj1sJlRAj5pJts4/Ms=; b=P1MxcxvGewwYqY8CxeIi4RA8yTtuHJ0qoDjGLOcwx9QCguT1BteIfhIwZLLmLLZIEN rDMhjffbZe16wLsPouSqd3eB+fkr7GAdTscFM8byaxAOQSrw5WYT5k4nBu1UbGRloY+N t+XJMnDUek4ZBCLCN3Yqp9zNR3CXx4VsXHNdGWucdB7/eo0EXnEw+BsV3oxcQHs2vjg1 tGNbk7mvsNybNglMHwIw8eziKXDV8j+RdlDvWYbX9me1h9y4OUKIoOypzkuC47EL8nmZ ntv0x5rYDfqsV4vQfdmPS4qE/Es5BtIKAT1+aD/oK7yiMxdtCoLjbkh3wFIzCDY6aVdE zAHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=MkJbeZ2YzCPPLGp8kgmOOD9tSwj1sJlRAj5pJts4/Ms=; b=POx4nLW2+cmifmygPfWjzORx1nTpTwxZWW3sC2RmXqzOmVreriui2aS77rtmYFQIbc YQdtdyvdMP3oKYWPZ9D3ZbBrOp8O/kMOHqek9c2aXsespxbCRj2PmChlvya2EaBK/LoR XcAu0Qtqg629bpZ8VmdOBlYrbQZOAZk6Viln8YvIoO7CIi82AtUKtHg4e/6pqBw3G6Pc /iTYUPm5JV/DCPvo//HCJOg4wdlD1gvBhYnR3sQExxTaPwNQAUAm7jSn1o8FRXaE/bWI MSGAU6+59NdRaz3Wi+KGPzyS3oKxNCWgtbc4iKhrPCV4BwtNjbObNlFCoYjRIPDqzzZU 5VWA== X-Gm-Message-State: AJIora8cpqem4/fx6KCwuiKz2MopeEAJIzrqZbH2hLDbJKXjdHwjVtvZ RoTYpHTGl0pkfzT4q9tpsTbgWepzc/+lji4m X-Received: by 2002:a5d:5a9d:0:b0:21b:8247:7ec4 with SMTP id bp29-20020a5d5a9d000000b0021b82477ec4mr23461268wrb.561.1657659289195; Tue, 12 Jul 2022 13:54:49 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id v130-20020a1cac88000000b003a046549a85sm14939wme.37.2022.07.12.13.54.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Jul 2022 13:54:48 -0700 (PDT) To: qemu-devel@nongnu.org Cc: Aurelien Jarno , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Aleksandar Rikalo , Richard Henderson Subject: [PULL 11/12] target/mips: Simplify UHI_argnlen and UHI_argn Date: Tue, 12 Jul 2022 22:53:46 +0200 Message-Id: <20220712205347.58372-12-f4bug@amsat.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220712205347.58372-1-f4bug@amsat.org> References: <20220712205347.58372-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= From: Richard Henderson 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 Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220628111701.677216-8-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- 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: