From patchwork Sat Apr 30 13:29:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568129 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7220642map; Sat, 30 Apr 2022 06:55:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzK7DvSZozZb479QJHbyuEbn6/jggKNCJJoHT/Kqv8O/gAVNuuhe9+UUAbzPfFY7gpMbXiM X-Received: by 2002:a05:6214:ace:b0:458:1336:4d3 with SMTP id g14-20020a0562140ace00b00458133604d3mr3197218qvi.69.1651326959734; Sat, 30 Apr 2022 06:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326959; cv=none; d=google.com; s=arc-20160816; b=jqWJrrg3moLtEZWTujkEjfkNpdSR3qK9r6gqjoR7jMuW4k96ueY5VJ2zYIS343onOn smKu4miYzr5RQcUOqtKLQCmE6fiXgZsi11pTqT+EnMg9QPkhLJeEKqIoqG/TW3ZrNuSG G3pQGSCTIK6FOZZknFL5ktylFgSBPQMUGSgzuCh5J/19EIq396ZeCFQfBDGDDejIGMsi 43d0HYbv2JoMsDWED8JLQs1dRqfCUm/5H0pWr+XFoKGe6CSIRrFoMeJGzaNoH87/EL0R bYFd7SBOX4GcIgqCxbPt0bU5Rt3z85XlEteddoyc/7K5HTxIPJwziUh/DYhjF6Ffp24p JA/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=thg/qH430ddCqrwkV3ZntRtLEhaKDDdaC5slwVCyxTw=; b=yzC4mN9oeKC/XWEC5pXoNeqO+GLlfES9F20aR2uyY3vVpmBI9Mlmxbm3rx6UxbNfpt aI9fLq0FReHpOu1YyiWCJz3u6RNl15IeeNzyUSF1zqE1HbAZREOgTLGXr/+57SUtJHLY 584gMbSio5y/t0ZwHe2z3wgD3zbDo29BAKQzn65jP8RzqwuSXF8K7wXLWGGWlRms9FLr 5RbgyXynkv2og5ZeStWqHiAHBKZyVGzEIgdX+ZQNjquPAZnolOhE5cTR/UJKm5J2CDfG 87LxgszLs/mIxy+59o9gyMvKQ0NTDDRrdYmwuOmQvM5XLBInsrd+he+cWiBzJdR19YwR fNKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mPh9mY9L; 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=fail (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 y13-20020a05620a44cd00b0069a14682517si4188342qkp.586.2022.04.30.06.55.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:55:59 -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=@linaro.org header.s=google header.b=mPh9mY9L; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknZn-0001Ya-9i for patch@linaro.org; Sat, 30 Apr 2022 09:55:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAl-0004yz-Jo for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:08 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:40949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAj-0006L0-FX for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:07 -0400 Received: by mail-pf1-x42b.google.com with SMTP id i24so9053287pfa.7 for ; Sat, 30 Apr 2022 06:30:03 -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=thg/qH430ddCqrwkV3ZntRtLEhaKDDdaC5slwVCyxTw=; b=mPh9mY9L3eJP8WP8gDAI7ZVxpjFgvM3bxaU4wAeXpnGakUlzfFMgwRp5S/9CzPXVpx LqM1nRe5KrI4VeYBcHFJyj0tn6+ubj7y1uuGqgoXwbBSqjXCdsN/SNxBRoyBdr4kNWFF 49JhCEH1cvFyb02je6jCJCcrPpgUykAOQHBEdLWnL1fo5OsWmVMjiOu5/4tI1EUgFt0V bSOANX0dMqFWlM2DaxrYdJcPv6QqPFGSr9Ym14yF6VEV65Oof5ErrX/5T2lKp0OtOVyP 6zupC6Blt264sMG3DrOiRdrpes+09BT8lqqePL78jE0qEt8kOKaRYK67Lg4WCoy1Y9pH LG1A== 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=thg/qH430ddCqrwkV3ZntRtLEhaKDDdaC5slwVCyxTw=; b=5SRy/oveA69EtTCzsv6f0wuXTBOLL8UZALlXxwTrpcjtoexte6XHEQrIM9QL2qw5+M dVbJPW7Wtl7N7TQoShZXf3KHyj6NAnepbvSmzLs0TCJw2hQ+pYIGuIQbK7N3lkvUtchG y+OJ2MumsCBLr2n66iXq2DQGpYHXS1aNJS0L3iyU7EimLs6GeqU/J5RuQt7uA3SfupSl 0PugpOJ8wf/3UgQRYYf/NgYl8RnsvqW1LZcnnN1BMr+yPfp7SQayd2MQe0g5CmTAFtqj 3WFpq72iNgJ51TFTl0+U96vD4WtS57LkNi8vYYeND/5e1e7uL/AX3KmB5FI0itbfVagq HnAw== X-Gm-Message-State: AOAM531odTU/OzcBYr1FKXsr/W6mx4A+/DP4M7NHmU5XiYAJSf8FM3Dd xm+CAUZ7ZpDZJ+wsqsDCLxm0PYBFBUWITg== X-Received: by 2002:a63:1d5f:0:b0:39d:b5e4:ae24 with SMTP id d31-20020a631d5f000000b0039db5e4ae24mr3067945pgm.502.1651325403077; Sat, 30 Apr 2022 06:30:03 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 29/43] semihosting: Split out semihost_sys_rename Date: Sat, 30 Apr 2022 06:29:18 -0700 Message-Id: <20220430132932.324018-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_RENAME to a reusable function. This doesn't use GuestFD, but it does reuse validate_strlen() from semihost_sys_open. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 4 +++ semihosting/arm-compat-semi.c | 21 +------------ semihosting/guestfd.c | 57 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index c31a48598a..2bdf02429b 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -75,4 +75,8 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len); +void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index d460754ea0..143c8689f5 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -480,26 +480,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "rename,%s,%s", - arg0, (int)arg1 + 1, arg2, (int)arg3 + 1); - } else { - char *s2; - - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - s2 = lock_user_string(arg2); - if (!s2) { - unlock_user(s, arg0, 0); - goto do_fault; - } - ret = rename(s, s2); - unlock_user(s2, arg2, 0); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); - } + semihost_sys_rename(cs, common_semi_cb, arg0, arg1 + 1, arg2, arg3 + 1); break; case TARGET_SYS_CLOCK: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 17d43e83d3..03e516535a 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -657,3 +657,60 @@ void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, host_remove(cs, complete, fname, fname_len); } } + +static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + int olen, nlen; + + olen = validate_strlen(cs, oname, oname_len); + if (olen < 0) { + complete(cs, -1, -olen); + return; + } + nlen = validate_strlen(cs, nname, nname_len); + if (nlen < 0) { + complete(cs, -1, -nlen); + return; + } + + gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen); +} + +static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *ostr, *nstr; + int ret; + + ret = validate_lock_user_string(&ostr, cs, oname, oname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + ret = validate_lock_user_string(&nstr, cs, nname, nname_len); + if (ret < 0) { + unlock_user(ostr, oname, 0); + complete(cs, -1, -ret); + return; + } + + ret = rename(ostr, nstr); + complete(cs, ret, ret ? errno : 0); + unlock_user(ostr, oname, 0); + unlock_user(nstr, nname, 0); +} + +void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + if (use_gdb_syscalls()) { + gdb_rename(cs, complete, oname, oname_len, nname, nname_len); + } else { + host_rename(cs, complete, oname, oname_len, nname, nname_len); + } +}