From patchwork Tue May 3 19:47:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568959 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9773273map; Tue, 3 May 2022 12:55:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9ujWkNLQsCnXx1QrOOK6F80Fh2wRKovApxy+FhAquLXrnW+rAJKg5MlRvFQsGA722fW13 X-Received: by 2002:a05:622a:5d0:b0:2e1:d430:a5c9 with SMTP id d16-20020a05622a05d000b002e1d430a5c9mr16468376qtb.639.1651607752331; Tue, 03 May 2022 12:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607752; cv=none; d=google.com; s=arc-20160816; b=SoRtCxszsCX4ikCqd7Wy/FyHT21lGEBrO8DD8UMOqmgKWgmBbncLBa0qrAb7rq78F3 bDdTRduP/DoIE4AIZRADK5UDYDJ2l8RNiqtwU2OHNZZXutcSYpsaDOgrpjGegIuZ/jdH VaJrDjHv2hUQd7I0uhK96eNBj31m0voivGB5GcLeTQpQfnLxOHZf1dKTMyNmnw9M9B4j QVoT1pFDY0VsgO+2fXCxx1quERYfoqVXIsQFCm3nCt4VJzWT5OM+yf01W6gvhGIxyFGn 8RzCuXskmFCIFxRmvlLNpy9wWVD9dvXYTA3bTjC9/49/Jms3gwSTV3L6geAYcSrmpuDC CK4Q== 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=B0IjewfhPoB21mUL+ukAhhgR2+vOUEMvAP9pcUk/okk=; b=rcLYNFFBIMPyJgzu/UquODk9ebR2bYWPDjPaBR/eXM2vHlGFlJu/Ej1ZbOTFUhp2I8 zKHiQl3agS1oUesMlu67KrV4zu3XzNtqx56qm0fRIdEQ2NW3pI+b3J36Fh+IKC72RRcN ak7SvagBmOh0RTAvy08NUEpt36Fg3MsF7w9ozUDAcA1Hhn5pOQTj2bhES0h162cDRSgJ cE4Ty2uym/uF92jXUW8CBdokiEe9C2VjFafhHCOaisx/qHSkM7FmsFcdPJUhxyeu5Q/w ApTVVvx+nkHp3zbqeXs/jFYYZdlt6faw82NA0lSNOESy7Jo1SnDvT6ojATf9SnDIUXkM igTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DQQOZkS4; 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 f11-20020a05622a104b00b002f367a700desi8190359qte.238.2022.05.03.12.55.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:55:52 -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=DQQOZkS4; 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]:57268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlych-0002Wv-L3 for patch@linaro.org; Tue, 03 May 2022 15:55:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyVx-0000zk-DN for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:53 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:42873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyVv-0003WZ-Op for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:53 -0400 Received: by mail-pg1-x536.google.com with SMTP id 202so4542546pgc.9 for ; Tue, 03 May 2022 12:48:51 -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=B0IjewfhPoB21mUL+ukAhhgR2+vOUEMvAP9pcUk/okk=; b=DQQOZkS4g5w1HAIASzVcGpUOvgy81o897RsNehNQ8S2/PsQMU7DRIfglJ/vPwK9SAe tDQM0CPLyfXBXnaRdPcAuQri3hZ+e/kiPhYsE/hdhz1NnYMv+K8M6JSGJkPdGPF9oHVR /OWs7YhNSyUFTm5neasruoE9RJDlN3Gan6ROcZQMwiHMKw/99ixxxWF/xWDLf/+Expj+ 0GdFSX6N6VahEF1h3NyyLYfpNJdcCeqK2Yndytr7Z8nmtwY4NX1D5cZlX5ybyMzuA3J4 x3Q8hGgZEi1hNHjOKqKmetkmeMYzYgNWKAi0A3F1RvDCP/8zhqR3SuZf2iRvolWUi16s ANLw== 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=B0IjewfhPoB21mUL+ukAhhgR2+vOUEMvAP9pcUk/okk=; b=6d7LutO5nNzoniDSmUlIiILi9p+xIQ0USDMXBwOFwV3PMJROFyGRGuqPulZMkzEtzS pHAlsGi9w5p0Y4RNU74WoE1nEwOCzGsTIg7uaxd//Rkn1moGcZwNp04IzCa+KF6cLo3E qSijyJyF4xJ2zpf6ejNH7lhKO+m7wGXquk3EqbEpu1xGTfFD3dk6MSNiRYId++f5a6aK LWuJZd0TvXV7XhrHLnwEp1xHKEZV4NnZ100LDsC5UkxCtzc0MyriffDNiE/c84FpsCY4 Zcx0cGa9NZq6Qin3D0tmR/HTxSs2hPmCLHAIsQG7Riv+muwTfBq8FSXQeT8eGzv4DZSo u1+w== X-Gm-Message-State: AOAM531tf0RmvnwdVVsvqlpqPp0+yA4wj8XQsl66KWy5sSDSaTaWHuF3 QpZdYOK6QhqAZs9ugbFH4htp1suVEutzkA== X-Received: by 2002:a05:6a00:1824:b0:50c:e939:118a with SMTP id y36-20020a056a00182400b0050ce939118amr17776383pfa.15.1651607330440; Tue, 03 May 2022 12:48:50 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 05/74] semihosting: Add target_strlen for softmmu-uaccess.h Date: Tue, 3 May 2022 12:47:34 -0700 Message-Id: <20220503194843.1379101-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220503194843.1379101-1-richard.henderson@linaro.org> References: <20220503194843.1379101-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.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" Mirror the user-only function of the same name. Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 3 +++ semihosting/uaccess.c | 29 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index 03300376d3..4f08dfc098 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -53,4 +53,7 @@ void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, target_ulong len); #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr); +#define target_strlen(p) softmmu_strlen_user(env, p) + #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 0d3b32b75d..3cd809122c 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -23,6 +23,35 @@ void *softmmu_lock_user(CPUArchState *env, target_ulong addr, return p; } +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) +{ + char buf[256]; + size_t len = 0; + + while (1) { + size_t chunk; + char *p; + + chunk = -(addr | TARGET_PAGE_MASK); + chunk = MIN(chunk, sizeof(buf)); + + if (cpu_memory_rw_debug(env_cpu(env), addr, buf, chunk, 0)) { + return -1; + } + p = memchr(buf, 0, chunk); + if (p) { + len += p - buf; + return len <= INT32_MAX ? (ssize_t)len : -1; + } + + len += chunk; + addr += chunk; + if (len > INT32_MAX) { + return -1; + } + } +} + char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { /* TODO: Make this something that isn't fixed size. */