From patchwork Tue Jun 28 04:53:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585554 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp530028mab; Tue, 28 Jun 2022 01:01:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbKq8nhvkhP6GZbudV3qHvHTPQ1AeaVBi/1L/auSLv7o1yxaGwkyShmGcWRg7hJvr+fHwi X-Received: by 2002:a05:622a:1a14:b0:319:c590:cdd9 with SMTP id f20-20020a05622a1a1400b00319c590cdd9mr7710206qtb.23.1656403289915; Tue, 28 Jun 2022 01:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656403289; cv=none; d=google.com; s=arc-20160816; b=u1gdhvYis0fEJgEL8RFuu5+W1g+WMD5QivRFBgNyOzdqUn9bs3x43KId1LVoyEMEb3 0wkKVrRm09xCVZ+KADvlh3xRcTo+30uYizAc+4wuwc4wGIgCXPkWokSTawfdfIPtaCcT Kvgs55CcFk92J3AXrVezLi++GBMtqCPSL5DJx/noKN/vS7HQPe/289QXF8bpRKXT13Rs wR8YqYxwT13mihrXpYkzIUSp6OFhlr0f+6Oj1/QHYvTZXsco2DFGBDRtB/tmEMnWCWpr NYB9Hz7j5aO7jzBYg8KuMyLsYqAQbv7q6srqPKsyLWQXqTfKs5IFNN8fcxSrQs2LIOjO D15w== 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=XnFWwBa1I9VJoksIMHyZzDE5/cUcTWTNeSlLEr2nKGs=; b=sqp9IIiWGMnLBTOaRTxTj2Z4mZVXWV8I9X5qMlWtiQO0NC6/eV9TthvfVmZFHswup4 nb4xwd4rDp//lRWSwCVO78zS3TA1wZhhMpjDWrJCTAF+qI43jAIydIlgIXUCIhfP5W0n Ylj4l5Q8sHslu/r5//V4qoGaV9rKsY5hULwhUdSpR+aYXApSoLXqWK2fBDIPrljyFfOd jJA8ZuC8xYkoezE+QuGPRuMzBFHuk+YsAMu4k6hkZBC+0uEQ4g0MC1USjMpPRbLeHqYQ a30e/6wI2WRZCtBATfYqgq+ZItrlqf9q3iQqCFfLnyusAwMDW3MeXxdSiU2fru6gotMX nR9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="VIw/+1no"; 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 q10-20020a05621419ea00b004644918d50bsi6842004qvc.148.2022.06.28.01.01.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:01: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="VIw/+1no"; 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]:59850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66A5-0001as-D6 for patch@linaro.org; Tue, 28 Jun 2022 04:01:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63GH-0003vs-TT for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:42 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:39504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63GG-0000Gk-9b for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:41 -0400 Received: by mail-pj1-x102d.google.com with SMTP id b12-20020a17090a6acc00b001ec2b181c98so14638271pjm.4 for ; Mon, 27 Jun 2022 21:55: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=XnFWwBa1I9VJoksIMHyZzDE5/cUcTWTNeSlLEr2nKGs=; b=VIw/+1noFjzd2DXm5WGJmLaqSAX8Nuv8x+Ze4SLQgbA5tG3LPUG2j0qF6/SRFB/N/l o9UPqFOGovgfukdQOJUeFmGSik6UfrH7SVqpCazMn80VSGbPz7E5eTiwRxB+puvaArWP ZAA614ADrxhGvfI4bS8dPOlNUKcZD+grqLSdp1W+TZjznz6StHACyriQIYp7cZSozKKS QZOet/XLyNqVIwsdkX7iPkYw8gpmpjRHA4yao4ZUB1JKxdUcTrRCjZeEbqnsBsXUYgnq lbdpfskyajW8DKCZfhOxJB6k7yFRMhFJcAQTeS9AIXC1UJ/QLUNxOtp/XqjfxtdLZkE6 90TQ== 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=XnFWwBa1I9VJoksIMHyZzDE5/cUcTWTNeSlLEr2nKGs=; b=aUeRuUM8vsZp/EBKp0W3F3oBihpu/6nln5LPCuy7LLoV7V4b5pKHHsfFg+ICWJwX/a QeN8SGdQ9K9YNsv5pxhp0fZ4Sk30B3m/AVniPfYF7eJCi4cV7d8vY4mQJjvT1Z9QeuoY 7l2brl/bNNZGBICrojMv2wilDOXvBGYbUXqfcPSDLsq7XAE8b7D2jrrd982Pz56YfDtY GUxQpZpsYUHipol/QVocIATKJKoYPJw6iGckbjOqnvTZaVJvRgPBTXa2Ky5JRmR0k8Np gRY1ndTl7+YVDdOZp6sarwQnbAnx2JRP2GoNHH/5KfEs1WK4MmdZBzBiL8z7XKhw1cbM eCDw== X-Gm-Message-State: AJIora+2KMHmkYHyvfmZuf3ra7aMtsyYb/3lnccaSUQNFr86+HwXsx8z 0qfyPMOVdRvmBo9+eHBymWfJH+F470rZBg== X-Received: by 2002:a17:90a:b703:b0:1dd:1e2f:97d7 with SMTP id l3-20020a17090ab70300b001dd1e2f97d7mr24902310pjr.62.1656392139103; Mon, 27 Jun 2022 21:55:39 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 37/60] semihosting: Split out semihost_sys_system Date: Tue, 28 Jun 2022 10:23:40 +0530 Message-Id: <20220628045403.508716-38-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::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.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_SYSTEM to a reusable function. Reviewed-by: Luc Michel 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 14d37ac9da..7ab6afd7fc 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -507,17 +507,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 223916b110..de846ced32 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -165,6 +165,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. */ @@ -353,6 +365,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 : 0); + unlock_user(p, cmd, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -619,3 +649,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); + } +}