From patchwork Tue Jun 28 04:53:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585508 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp454793mab; Mon, 27 Jun 2022 22:58:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sYgx0JcrXT7nWXPZ7eP4FWK9tZfN1Y4ijnBXnYg3okNl7zK6zP2enguwIxiCsXuTXn9UD/ X-Received: by 2002:a05:620a:46a3:b0:6a6:e7a3:2cc7 with SMTP id bq35-20020a05620a46a300b006a6e7a32cc7mr10338710qkb.80.1656395935104; Mon, 27 Jun 2022 22:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656395935; cv=none; d=google.com; s=arc-20160816; b=a5hLcEU7GEKXq4lo0V37Fxy8rgAun4HU0z5dXtfsMJE8tOwUk3STDlh2kVDZIXBX+y ePowvI5F8rs/GiKbKiKzjS9tbcHnyHW7eUU95BcxgUqF+vXApuNA7+JfIRQiPbZmRvp9 KFz4RjsFp9TxCysFW3IZkwfrvFEuq9ob5sLsp1tpPwdbimU2q76ztaaxQdSy+j85Wk7f OkFsEWte8wB/Mv2yBslzZI9hhGUHFWnkhhWCuB8mJCZVr6jBMEdR6eNTqSHXpPPqk2Mw OEpkr952B0wKwPpHnKfh1bCbqr/NQ/yp8EekFXuCgPdzcdcyhAz+ASkXl6iyCIag5kcS bsVg== 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=RK5M0Iz9OI0w9+qLU0kfHIVs85xFEebhwh/ygRwPj/8=; b=dSN4eb1Twe2zHNIOJc68yIeqf1dnavxtHZlfI889mCAz35l/WXHpJrm+cEA8gipirY U5P0dDopjj/o9XbbCM+G+WdiKQKJ7NFptmUXv7YEkkZ4qJKbc+GSw5woQcpvSnuGH9H+ NkkcAYN/ITNcjz/iu/Q/5gOMEwAKon1mV33iSNm42WYxC2xpYklBOhHtFMYPx0se4a6C 0dy5I5sY1QBUXo7MP50GojY9JNiIe7t6T64scob5J4UqGaNVFm3Dcwc39x9/zp2Bs5Og PHkE5unoyUvqY5H4aWCvntgt8ntT/gJll/Z6BDNSbUzpAdA6rClpwzC24yT5TZZJZzQG POdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=klzn4Mv4; 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 az43-20020a05620a172b00b006af46175023si1552504qkb.654.2022.06.27.22.58.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:58:55 -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=klzn4Mv4; 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]:44836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64FS-0001Ya-DN for patch@linaro.org; Tue, 28 Jun 2022 01:58:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63F3-0002Jb-Gx for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:25 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:41695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63F1-0008IZ-EF for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:24 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 23so11058486pgc.8 for ; Mon, 27 Jun 2022 21:54:23 -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=RK5M0Iz9OI0w9+qLU0kfHIVs85xFEebhwh/ygRwPj/8=; b=klzn4Mv43gJL6TxdLCxg6gbINvGlfcE3+9h1sQ9wuSeZv1JHa80ZIdtqN/2lIyJL3F ZN7k96iXz2rJ9XXGoFgTguWT5G9UPEn3QZc9PjwrMDr/DNjIx5sGt5+Bd9FqTiaDCX0H +bLapgOMzHLaT9Sd9Uq6VKzZSDL4IAY4aHfqtwHyJW52HIpbLfZ1Fedh0XEj4kNLUOJn 9kSgrG/gKEoN0dq8w1569yrkZQBe0C6xqLByICgj8XxwnOa4fRdH5IQxvb2kIikdE9BZ DDC2KSKB+jS5DY6/5Fe51HwZfSciQczakkg7dRbRIQJbNkBO/8uRNvMnvzXoEQEuxTsk deLQ== 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=RK5M0Iz9OI0w9+qLU0kfHIVs85xFEebhwh/ygRwPj/8=; b=pxQIGm4xy5DsOiuHPVppGx2fuLmF1dZpeUMMjNRoCwkPTB9MKOgTqVlbgLCN7hejFx v9VZ6KLuEHsK6NSPQ/nUpdj6kWetftYuCDizQ/vfJ1vOsK3R9NIf9ZrnmZL7/aZFFNev PMsoe+umGMvBoPloH2DVHZJ+RQ13xa51cVf8LeXoN8ZQSSsntocABcztrViEFvM6tPIM xbLEcA/EGfnkHHpMszgiY+wz0xNzpiaqRnK2C5Ih5jk0R2t5/kMruR6e05B2MmmRiQfw rWP37vIZTcslyZPK9rQI+SectrqLR4KLr69VICKr1sgaRFIDI2BiFvWg0VU9Oghqhf3C 1MaA== X-Gm-Message-State: AJIora8bGS53atArUtuaqzdZII+a0xJHyxP+1xdzjgFCJ6aRM13e2b8K +B61wyuBDBNtCen5cav7XZNzm1ZzvVMr8Q== X-Received: by 2002:a05:6a00:893:b0:51e:77ab:8874 with SMTP id q19-20020a056a00089300b0051e77ab8874mr2692434pfj.21.1656392062081; Mon, 27 Jun 2022 21:54:22 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 06/60] semihosting: Add target_strlen for softmmu-uaccess.h Date: Tue, 28 Jun 2022 10:23:09 +0530 Message-Id: <20220628045403.508716-7-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::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.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 interface of the user-only function of the same name. Use probe_access_flags for the common case of ram, and cpu_memory_rw_debug for the uncommon case of mmio. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v3: Use probe_access_flags (pmm) --- include/semihosting/softmmu-uaccess.h | 3 ++ semihosting/uaccess.c | 49 +++++++++++++++++++++++++++ 2 files changed, 52 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..d6997e3c65 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -8,6 +8,7 @@ */ #include "qemu/osdep.h" +#include "exec/exec-all.h" #include "semihosting/softmmu-uaccess.h" void *softmmu_lock_user(CPUArchState *env, target_ulong addr, @@ -23,6 +24,54 @@ void *softmmu_lock_user(CPUArchState *env, target_ulong addr, return p; } +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) +{ + int mmu_idx = cpu_mmu_index(env, false); + size_t len = 0; + + while (1) { + size_t left_in_page; + int flags; + void *h; + + /* Find the number of bytes remaining in the page. */ + left_in_page = TARGET_PAGE_SIZE - (addr & ~TARGET_PAGE_MASK); + + flags = probe_access_flags(env, addr, MMU_DATA_LOAD, + mmu_idx, true, &h, 0); + if (flags & TLB_INVALID_MASK) { + return -1; + } + if (flags & TLB_MMIO) { + do { + uint8_t c; + if (cpu_memory_rw_debug(env_cpu(env), addr, &c, 1, 0)) { + return -1; + } + if (c == 0) { + return len; + } + addr++; + len++; + if (len > INT32_MAX) { + return -1; + } + } while (--left_in_page != 0); + } else { + char *p = memchr(h, 0, left_in_page); + if (p) { + len += p - (char *)h; + return len <= INT32_MAX ? (ssize_t)len : -1; + } + addr += left_in_page; + len += left_in_page; + 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. */