From patchwork Sat May 21 00:03:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574942 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2684239mab; Fri, 20 May 2022 18:05:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwScz8fKFyhqG/l2nhV6tMKUQQ8kyll3D+O3mwv/m06H0sAfJK+ERkyxzIBgG6hdODPssBm X-Received: by 2002:a05:6214:226f:b0:461:e91b:4fdd with SMTP id gs15-20020a056214226f00b00461e91b4fddmr9911518qvb.68.1653095130538; Fri, 20 May 2022 18:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653095130; cv=none; d=google.com; s=arc-20160816; b=qC5t1GFEx0qx9ZuVeB/DDkYgboV7mPtugo2waVrW1jMNwuM5ZaoGh6fm3WjOaS8vG1 w7S/4DdiB8EyPdQwTtXi4+xDTu7wgQ/By1X2Us7SJbj8IbUSPgmQcGWnx7ZQ73HyQ04k v0Ru5Baw50t6trxGo5TvFUCr5BBGSAfJftl8xWrGXp5tQiLvFnd953POR4qYb881x8Ba qid5nfhmQ82ggpj31ncfuoDO9AW9TOn55wG2KJQ0bYiT/bZ/jmgx8OZ6bO/G74C608a3 zwzDMv5BlLdcyVsSLkUPUr4wXnSGS4RDVgJA1OlUOKmu4dZcRi5zbtgz2L7hoyDB+rkT Wnzg== 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=LN6XpMNK1B7AUGbjroKLaQGdSs8x64FTUaroN/g+tus=; b=gcQRQEAIjWtS065egzPRPQ/peBfc0GWMjRGJk1oCJM2O3n/UY90MGemX9CxJ0/za1h L1vC6uGqHSfacZ4mDlbaLkJnlrs5l+5jie2AHW1YISvK7ETvIKawyVUEBmtjpHKq0fYH qicWNzVpiuHH/yYZKklYjAOqr0eUosLge4trISWX11LmHqqwg0Aist9Hxqew73DUI47S 7lHH7OTjSU5j1f6oKdaYLrxtxhQ/7j6z6ihsCH9nCbkQYjL3EvYAQFQYKp+l45fFKf0V pg8xbhEq4cH6K3VdkP5IIY4LbGV16YQJMiK/ei0tcaAwtM6nhM0eBKX2Qti2pbhCouvO UGYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="aAfH0ZA/"; 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 15-20020ad45baf000000b004621edca200si414904qvq.184.2022.05.20.18.05.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 18:05: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="aAfH0ZA/"; 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]:48960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDYg-0008Ny-1H for patch@linaro.org; Fri, 20 May 2022 21:05:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc6-0008CK-WD for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:41561) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbp-00042D-OB for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:50 -0400 Received: by mail-pl1-x635.google.com with SMTP id s14so8556604plk.8 for ; Fri, 20 May 2022 17:04:38 -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=LN6XpMNK1B7AUGbjroKLaQGdSs8x64FTUaroN/g+tus=; b=aAfH0ZA/X9yVbGcmtAb4roHMq6C/zyYZBRaZ4/5ntSTdXT58Njth2UTwhct/5iGeVj LqqAez6GB1r28d5HOeCsb3EKKu4ipdWfwXOV7XocjQ52rm7Db00r6ZIzG4/zvpfLUz7r DL3txqX0gn2kigtJX2CDP83ddmc40KuNZ938fleTKc9lkZRjOHAL/GEvRznYLkiiFLY1 ZfjV8hfqOZn/v+T/nMR7XBZkXuVmEj+skob2jcfryrp8uNmM9ZaStHcbxdHDNyFoYUWL H45YRhCsYZpsTQ2z4JI90EkdVl210ZmRGszBSIyl4AWATdrwubQVtxPoSBib8mhS+t8M EVoQ== 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=LN6XpMNK1B7AUGbjroKLaQGdSs8x64FTUaroN/g+tus=; b=EjCXGQV5VSVv4JGu4DW+a+70YfFKCB2wPQGPGmugh2rLuzU0KUGiRNn7FSm1+cK6ko YpjzNhLEBzxVMkKQ8de4sVKGfQ1EGDUKjqEPPb6fwkz6GOTnjsbpeEFKtF0ldOOo5ogU cSY4L8eedTte5cSApF8BelcD2qi62CXynUq/sGfPIZfQxtUVByocnfyZV5qs3UaYeuhM XX8Her/VpWRrRSXCr1SDCOadT/gVuVbLaILlfn11+V/S/D5tRxf12hDl88ZqzovElSgy MEYEMUQbya7DSwaFTrW53N+jTuGYyBs/oTVo4gBUmQZl9ivLaO8cumHbqPo0jdlmd06k YhWA== X-Gm-Message-State: AOAM532Unca39wVT/02Ta3t0TaZ2nVQvyWff9kKKHp5a5clOSnkOx7sw EAONpjoTxccstQUopfiz201+ID0m/8tmZw== X-Received: by 2002:a17:90b:3a89:b0:1de:bad4:b614 with SMTP id om9-20020a17090b3a8900b001debad4b614mr14181225pjb.139.1653091477058; Fri, 20 May 2022 17:04:37 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 31/49] semihosting: Split out semihost_sys_remove Date: Fri, 20 May 2022 17:03:42 -0700 Message-Id: <20220521000400.454525-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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 --- 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 5dd8c800cc..b4320939a1 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -470,18 +470,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 1425156bf6..3464896281 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -163,6 +163,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. */ @@ -307,6 +319,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_for_gdb() : 0); + unlock_user(p, fname, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -552,3 +582,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); + } +}