From patchwork Tue Jun 7 20:45: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: 579410 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp5564178max; Tue, 7 Jun 2022 15:23:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYRLLYKgdw9JeoYv52ye5AeE331Oz0dtILcZ3DOvnh+p1yVkkeNQaJXoCPCbcr318D0g86 X-Received: by 2002:a05:6214:d8b:b0:46b:a79a:2f2b with SMTP id e11-20020a0562140d8b00b0046ba79a2f2bmr8086368qve.36.1654640609272; Tue, 07 Jun 2022 15:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654640609; cv=none; d=google.com; s=arc-20160816; b=rUxYQU7jJsSG7hPlnan1xj4iHHa7KU1BpI22HOUvuD4LTrJsa1bvJ0bzce49JjuS2F ylIMNKFR3sqHasjInvMr7IsaOuZVJmlwTtAy3O3VLAsygx6rXj2H3M5I6F/LEe0XkCec jltUC+p9tyQjLt+7cgfwJCXVtn6F/EUNEGDwBiz+0uFMwhio4AdRPNVlLVpDalD4gyT8 pFFQl8jDLkU282oSAU8FgYQkTcaYz6eani+ivCaIkId7GpaqFjfxgJBr6uwbZupbm+uN KwljYyZf37Wp5og+yE/t28VShovMtettdpEFfPW3xk3eu+pH2cki82TOErHFjQWPvbz/ 6Isg== 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:to:from :dkim-signature; bh=4sagk9WK8UfUwwphTVx4M3L/8wzZLywpfR5arWi4wQI=; b=oTgNVBA9gIW1hIYOiBR13qPF2bVANXHHXW7FbXJQHD5w50HFExUVjqioxFiVSCwX4e LnhIhML7KCXx9LvC+/YQGTGWMOPoxKAZ4QgEZ/W4Ib3gseV52V6GVzLx13vSYSfMboWi t1AnqmZD1Id8YKc8kiOhwEXwUNNUUs+ShML3Y5lEtus/wUt3gaTFgZocpO++clo+FvkB 2xhLqjQ7x7euzGrCAzt96ys9leRRRVUjMKogdXaTgawfLLmqXtCmQbDJVG/V6hROXAA8 vWvCWv+c78HuS2LhwWPgLOanTOTv/4fPSU9N3AJK7vDxnIsgLMz7d7qSNgF5S6xbLETY LSZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MYyB1Oye; 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 a30-20020a05620a439e00b006a6c99de0dbsi2814581qkp.61.2022.06.07.15.23.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Jun 2022 15:23: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=MYyB1Oye; 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]:36016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyhbk-0005q8-O3 for patch@linaro.org; Tue, 07 Jun 2022 18:23:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyg5y-0007hi-8i for qemu-devel@nongnu.org; Tue, 07 Jun 2022 16:46:34 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:37656) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyg5w-0001Kf-DW for qemu-devel@nongnu.org; Tue, 07 Jun 2022 16:46:33 -0400 Received: by mail-pg1-x530.google.com with SMTP id h192so10191908pgc.4 for ; Tue, 07 Jun 2022 13:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4sagk9WK8UfUwwphTVx4M3L/8wzZLywpfR5arWi4wQI=; b=MYyB1Oye5aBfoZTGzUF24SryUceyVsyplnCPxZpRHyfy+Otl990DSUU7l1xcUeTWcX llLoqMsfUiWKF4TUeBj+71jN2vgJ2UehwWvIBnn4i1yN73y6XsFcT1XlAhcTldg/eIXZ RIxaeLyq4523VW7mETDg7GeC8LdQVeomFEqWJV+DbFJ6h/prvoyOFABornSVSaURVUMn ZX7/0/MJG7obymda+CP8TOy806kUz7QGw0pOM0xnY4TuZiuZMsw4ZHsoYost0FrKbDby gREXXMmDBPJq7XbhpHBQxZL7tvF0nyBWIj6eo7gWqFvYPgMciuxOQRtpZd9UQsACei5K Ofsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4sagk9WK8UfUwwphTVx4M3L/8wzZLywpfR5arWi4wQI=; b=51FHtrVYRab7t/YuGfpvqInRxt85VXNQyVmqS3tYH62APthSHDssqDP7QWOnComkED oOEJ3rKmI5+qVzwdLvYlMydflEFblpox/5T3yl7apnzyhJ4kCTmnxWtop+vVcwuLhenr kW4h4bHihNiRyVlY2YALMhpvq+u9pODSr0TfNXqxjvf8fUgDwOu/7tYjOlhOPT4z/9OS bu0xbCQxGvfIGfMASNMYzuVp4pEw0fjV5fkJVebg3+YbFo/vjcZwYjEMlffynbscc9IE 7noe97Vo7BMJusMEWo+SN6GpHc1abWFYsEfMnok/BQUI6I8UcGaZvwq8hGMmJ6Hw2e/R AhpA== X-Gm-Message-State: AOAM532CE3R9PdYT61TnlgRhpIu0SU3f/f1yRCXJoIwV3boLRPs0nXEh Z7WoQmkxVhV7outnuxKsJMFbLJ1+0Lc6KA== X-Received: by 2002:a05:6a00:2809:b0:51b:f239:d24d with SMTP id bl9-20020a056a00280900b0051bf239d24dmr20127354pfb.73.1654634790655; Tue, 07 Jun 2022 13:46:30 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3cf2:c634:5b19:25f6]) by smtp.gmail.com with ESMTPSA id r6-20020a170902be0600b00162037fbacdsm12971279pls.187.2022.06.07.13.46.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 13:46:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 35/53] semihosting: Split out semihost_sys_remove Date: Tue, 7 Jun 2022 13:45:39 -0700 Message-Id: <20220607204557.658541-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607204557.658541-1-richard.henderson@linaro.org> References: <20220607204557.658541-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.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_REMOVE to a reusable function. Signed-off-by: Richard Henderson Reviewed-by: Luc Michel --- include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 13 +---------- semihosting/syscalls.c | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 1ae5ba6716..748a4b5e47 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -49,4 +49,7 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, gdb_syscall_complete_cb flen_cb, int fd, target_ulong fstat_addr); +void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 81dd22e1c5..6c9d50176a 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -483,18 +483,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "unlink,%s", - arg0, (int)arg1 + 1); - break; - } - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret = remove(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); + semihost_sys_remove(cs, common_semi_cb, arg0, arg1 + 1); break; case TARGET_SYS_RENAME: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index fff9550c89..5ec4e8f827 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -133,6 +133,18 @@ static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr); } +static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "unlink,%s", fname, len); +} + /* * Host semihosting syscall implementations. */ @@ -277,6 +289,24 @@ static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret; + + ret = validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = remove(p); + complete(cs, ret, ret ? errno : 0); + unlock_user(p, fname, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -522,3 +552,13 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, g_assert_not_reached(); } } + +void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + if (use_gdb_syscalls()) { + gdb_remove(cs, complete, fname, fname_len); + } else { + host_remove(cs, complete, fname, fname_len); + } +}