From patchwork Sat May 21 00:03:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574935 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2678968mab; Fri, 20 May 2022 17:52:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0Wv/rh2MyFTPJ1Sp7L7IW5zPH4PKYEw57jduJdrKm15FnPE3fhEqoUC48VEiYEvNT7f0X X-Received: by 2002:ac8:5bd0:0:b0:2f3:bb55:4612 with SMTP id b16-20020ac85bd0000000b002f3bb554612mr9643980qtb.391.1653094376965; Fri, 20 May 2022 17:52:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094376; cv=none; d=google.com; s=arc-20160816; b=prw6pWQug5BACt7FZ8ScRm+BJ7Aq9JxiK9056thMfns15CjyF8n2SoD1GJf3rbcUS3 sPwB5ZCisC9Bh3PyE1gw2hV1ffwBKIztbhuTq/4F8y2hez91If89qo723kbwSW+Vib96 05EFjHo5szdo7PgLSDsRTNdznZ6UbbxwQBCG3E0wWOCBLRWlSFaoTElaYUQFFVhG1OqR KcuOL+lw0iG/y2dvWPUScTX0o6YvrqvF68vW8UwRzP1QvhRyJhjS2mAgtIiKPy9PpNoo UJEnvLa8JuBRJb+tzeOEoueAazJXhw24EDSjS74Hz0M6wNhGfZqQQW6dPa/sz62oMMbH fOqg== 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=y40sF2c9DbUtXmV2ndKv/KtYmK5ILHYoXK/oAxIJpeU=; b=YtyDpi2xczV6KFPTHBsh0DZJgp3eFWit8H9tbaAQZwm84191qvoT7FoX3o9yIMKw+f c9NdJWRWH9ZhYxmqRkE/jtFze6hUue+DcN0s1wFOustKLypAoKJvmL7ASzTGiTdgsiVt u9zSTKRESTqGqjfTuOQpC1p4ftSVkofRdm0eRlyk+SDKyM5DLBwtPvDdt/yQNyXjylNU 9pi5XzrNUfyZpdc1kTAnn7Z8qaaPGkW2XnOxGzfdSJy2caAvlV4ZD86DAwlZ8UMmATZA EwE7EGMP9RvRyGbeEN/pHGV7GcuD53gLzhOpEeytzqLm9H8ZmwBLCh8iralSztRkyNfe uVBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BqxuznKg; 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 b20-20020a05620a0cd400b0069fce27ef20si335248qkj.397.2022.05.20.17.52.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:52:56 -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=BqxuznKg; 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]:33538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDMW-0005fT-Iv for patch@linaro.org; Fri, 20 May 2022 20:52:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc7-0008CM-32 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:45013) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbt-00042P-HJ for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:53 -0400 Received: by mail-pf1-x431.google.com with SMTP id x143so8947462pfc.11 for ; Fri, 20 May 2022 17:04:39 -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=y40sF2c9DbUtXmV2ndKv/KtYmK5ILHYoXK/oAxIJpeU=; b=BqxuznKg/VbuPsfCIcm0NKZ85Z7QwCbuldtJ7bNQ2L4No5IWkrDpEBtB6R7D0I35Iy 341Mfu4ww6u3JE18zO9yWidk2180XWvEnpsFvYw+lE4Ir3SfkMKnG8EANKdbkL/vVyBM BxFkOmLLpTTPIxcpgQw3fayvWXdceQSXQaQSUK07VjrdM8UIMzW6dZ304J2yVwx/o6K7 EB/Oj9VgBIugcDyd9BIObv179CXrWkpWEGCk4jEZQRbkEDC31fsejaDSfjRyx4LNWQPQ uVZDSX7nsaLUjM5hlIXaSo1hPgrpMYdDvw5Y3ukMnl0It0b4kFGDANTztjQ6EvMtZ6ZV VbIw== 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=y40sF2c9DbUtXmV2ndKv/KtYmK5ILHYoXK/oAxIJpeU=; b=33VQQESq1hP74O07+2MJn7eTV9EJHOlMmk0JhP6RLQolBQJPxeu7lnp9sQJTMs8BJH dI3QtiZ+aGBa/T6yX+u4/keP9Rh7z2Gdjnpg49FGtEni9+IIcZLtoZvVvrtFNYfAo7F4 fyiPshlLVNrS4NwneWJVrZeUDQLKaOPCAf9+8VgOmvJr5af8oRJBHaeASCuQQkRrJIdX Jkc4JpOflsIBx4OekxCxLQ0Oecw4b6V9urC18deyKz4e43fQ4eqfJwC1fnwTMXzS+59e UC7yWkqIfYjsMoELn1fggdz7nthWusQdWu1rUIw1KnDjO2vwv9uDX/0kN8m/GgYAPH2j 5ulQ== X-Gm-Message-State: AOAM532GJRuyjZqo7QYLrRaahJTZcIaWbiN10SkRavTZCu7e/6udYsJx 54dxxxrq3vHPjXOHOUqV+ffae6JH7mhQtw== X-Received: by 2002:a63:210f:0:b0:3f6:24e6:bec with SMTP id h15-20020a63210f000000b003f624e60becmr10667186pgh.400.1653091478870; Fri, 20 May 2022 17:04:38 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 33/49] semihosting: Split out semihost_sys_system Date: Fri, 20 May 2022 17:03:44 -0700 Message-Id: <20220521000400.454525-34-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::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.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_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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_SYSTEM to a reusable function. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 12 +--------- semihosting/syscalls.c | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 21430aa0ef..c9f9e66be1 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -56,4 +56,7 @@ 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); +void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index f02131aebd..9cfa8a421c 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -493,17 +493,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "system,%s", arg0, (int)arg1 + 1); - break; - } - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret = system(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret == -1 ? errno : 0); + semihost_sys_system(cs, common_semi_cb, arg0, arg1 + 1); break; case TARGET_SYS_ERRNO: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 96d823e8b3..b6c395af22 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -195,6 +195,18 @@ static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen); } +static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + int len = validate_strlen(cs, cmd, cmd_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "system,%s", cmd, len); +} + /* * Host semihosting syscall implementations. */ @@ -383,6 +395,24 @@ static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(nstr, nname, 0); } +static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret; + + ret = validate_lock_user_string(&p, cs, cmd, cmd_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = system(p); + complete(cs, ret, ret == -1 ? errno_for_gdb() : 0); + unlock_user(p, cmd, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -649,3 +679,13 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, host_rename(cs, complete, oname, oname_len, nname, nname_len); } } + +void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + if (use_gdb_syscalls()) { + gdb_system(cs, complete, cmd, cmd_len); + } else { + host_system(cs, complete, cmd, cmd_len); + } +}