From patchwork Tue Jun 28 04:53:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585527 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp482178mab; Mon, 27 Jun 2022 23:44:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uRaC+dkTgkIWhpFfXORu2lsj00Y3nYUnIcEHRXaPWEPSZQ0bE8WBLKE2TiCgh4KbDG2ojh X-Received: by 2002:ac8:5e4a:0:b0:305:aeb:2efe with SMTP id i10-20020ac85e4a000000b003050aeb2efemr12103800qtx.664.1656398669500; Mon, 27 Jun 2022 23:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656398669; cv=none; d=google.com; s=arc-20160816; b=e3HuDm40LkKTkNqjjnoy8+YEs7I//bjJDY0wMclrDfYu0JrLOg716E5aSEMCbvkq9G 1szcRwERybd1K0MlCOR6KZMCjPvMXidztrTF9zuw0vfZjjay7zlux+ZZfAdUV+j5J25N cWE8Aabzzzsu8ZMlCoNIwPKk7QTGGKcH7cDAwF4LIOPgcsvFbgI43+iatpLBv1tpc4/g 2mUZkn5Da89bpYOvN8ioUW95JoSaZ+3b0A8OyBA7NLBByH64DcJxab+RkzWpL6ZkjCFS NdH7mWyhShSWMBJ9YRwU7NAYJmxhvx41TEiDFsL6P+6Q0+tN7gNRu0UnO5AnVPgPwbcL NQnQ== 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=qJ6ZZZSlz1PZaI3jEWDbIt6ncn6Ih8ucdkzmvg+FD4w=; b=fUqwyrISXbZwt1ZuLZ7Xz7ZC8Kr8XD801TBJXsnU197hcClSmGegsrnnpN87jkgwOf Dwwpw0t6FYki3ZzOviOfhgYBSop+DbUL2+EDtn2TfbQNyKFcDbFVx0G+IJDvYyrXa0ch QdodEe4GWOzLfxWSklcvP10PCQjJA0+Es0qCmrJi8v6QajNK0FlnKDhzzVV905dYFiBu fZ2S3tTmn1txtdG8OPWPA54Ugly//uPmw0JsrBElZanPyk94nYzL9uiZeXgh8jjxL1gH ns4I/euKqk7vjJJ853onog3KGU7slypyd+X3t6OznWgp+NxbPBhvdqOpZIlD1nT//65u di5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SRhbol8Q; 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 n186-20020a37a4c3000000b006ab8e886693si6163701qke.578.2022.06.27.23.44.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:44:29 -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=SRhbol8Q; 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]:43848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64xY-0001G7-R3 for patch@linaro.org; Tue, 28 Jun 2022 02:44:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63GG-0003qe-6u for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:40 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:35784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63GE-0000Gd-A8 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:39 -0400 Received: by mail-pl1-x629.google.com with SMTP id o18so10051393plg.2 for ; Mon, 27 Jun 2022 21:55:37 -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=qJ6ZZZSlz1PZaI3jEWDbIt6ncn6Ih8ucdkzmvg+FD4w=; b=SRhbol8Qd+JYSMjw8eSHKdrb+4gmhXVC0W6OZHlQHE8FJuCyU8FeXcCQ8/GG9VL/FC q77zL1O0wGAu3ObFrZsLK45uGJvmY/Iab1YERORRcHmq7P7cwidBeA3pIdEFBxlT6HmV HRAQOUWYjDosADvQ+7wDfrHaZX0lsD9nA3ilRjSxYYGwVxNW97w+BBZPUdhgf2V/XScI I0WRbuGY8Jeo23WSK0WyqoVGfRxDQ9EzndjYPAecR/FKlsJY6fAuFM6IXxhCOBwz8vnp Cyd4QJIjPVjfwt/k9Nzxcl4RtfLNcEwXQTWa2cvllzjSkDgUk8X4o1pTccGhq0UR2g7D xl6w== 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=qJ6ZZZSlz1PZaI3jEWDbIt6ncn6Ih8ucdkzmvg+FD4w=; b=Avws7zcWBZerPKPTQpV3BDBZV8fuxwTT86W1uhvilJSZEk5oSqbyHFep8iHbyCLT96 ASGpp1rZ9gXz5xKLyAdiWUANelnFqCz41+OdaTGULVuU3EeanY3Vgwr9NnSkfv4KlfgC sQpfzheb4wNow8z+4A5Et5jPgYxKnelZpQcK2T8t4eonZeAJRaOrewx0Ns+naZaR5aMP kI08Uln/jif4XvHhLgIIj3HVmPWIHt0FZcaN31Aa3Wt8+3g2fghaisQtXqQcsF0sQTl1 t0ctF2YV0iGFHZsmSysdVfv0h4kCizmW8eMSRm7AhCcdO3S7E74Q16MfRUxrSqLD80nn ntpA== X-Gm-Message-State: AJIora+QEwtklo2JfRq73N8gXHapweG4XvKCZHoVriXY5XPKIwsy9Scr LfvpZyNgvWcDPtz9f9arBN8K0xvfHDsRSw== X-Received: by 2002:a17:902:e749:b0:16a:2839:9e5 with SMTP id p9-20020a170902e74900b0016a283909e5mr3104269plf.48.1656392136939; Mon, 27 Jun 2022 21:55:36 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 36/60] semihosting: Split out semihost_sys_rename Date: Tue, 28 Jun 2022 10:23:39 +0530 Message-Id: <20220628045403.508716-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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" Split out the non-ARM specific portions of SYS_RENAME to a reusable function. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 4 +++ semihosting/arm-compat-semi.c | 21 +------------ semihosting/syscalls.c | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 748a4b5e47..21430aa0ef 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -52,4 +52,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_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index f4ce3851a4..14d37ac9da 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -492,26 +492,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/syscalls.c b/semihosting/syscalls.c index 5ec4e8f827..223916b110 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -145,6 +145,26 @@ static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "unlink,%s", 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); +} + /* * Host semihosting syscall implementations. */ @@ -307,6 +327,32 @@ static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(p, fname, 0); } +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); +} + /* * Static file semihosting syscall implementations. */ @@ -562,3 +608,14 @@ void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, host_remove(cs, complete, fname, 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) +{ + 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); + } +}