From patchwork Sat May 21 00:03:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574779 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2659882mab; Fri, 20 May 2022 17:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynfE6ddquwtCbc8wQjQKAMhu/4oztFh1skKNHKxuDW3DBGb9iICo/k/8UaJvkNgqbc/LuL X-Received: by 2002:a05:620a:4506:b0:6a0:8003:99d0 with SMTP id t6-20020a05620a450600b006a0800399d0mr8064228qkp.728.1653091667260; Fri, 20 May 2022 17:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091667; cv=none; d=google.com; s=arc-20160816; b=mUCqPmosjNkJEoo6MDAvUTyg4CB3fttH96pY8gnhMq9pgKXXkzK3JNDM5SH7IEpvHs //trMFfH28Zz7dKB0CBn6GjgHknVnOyz3MpexBUeoCb9xSPc+h8NBbAkF19X5bZLWuFg Om4aB4GwtuciGPq1Kn3KI34REV2WO0HIP0lqS1jkJoKUbIZuJloDLMUJzXR4FmVy4rrE cR30vTb0aImSesmpTzqVdddTxL4Q2i2Gp54LhMdAZXP+03guPlgLTCOEHWy2j2z9X21O lZCa74UhBVzlOPffJ/ocl8n0MFMdZljnhQwhc6Jv59m0HtdiBGK7P3SrdTcln9PGACx3 pPLA== 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=2OyP2Wnw9umWfxtpbUetMIm1XRFLbapKewV58Lgr8fc=; b=ppe/I69FO69c8GFMtkmxfZRVYY/jB7FHKg3SsW0ItTMeBAmRNKKgxIgO6XgL1ZmA+w 3uXHkGVA8QVwt4V/OXydZVKp8Q99yr0F8zLvu9Y29VJwzQ2veirqIc5M/y94q6Bwezl0 gm93ViopbKzqYM+cwXVtP2Wjc+9L2P9VEbVozAj8Bp6x9yN/uCoE7LQ14pXH2pc7r2Ha xvsMybZj6ZZXalYyMXz3wPc+EWUG0SVNydN1Dx6bl1xf7vAz1e43Z3fMkX1YMqlq4yfu BuIB8IEqQ/CmZoVqqj9VvgzZ6woEVxdx/J2zoBinmoVM2zxGCpKNm9dy8bIT/f2XSy4S /GMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vl7I20wH; 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 h7-20020a0562140da700b0045667133e6bsi410825qvh.400.2022.05.20.17.07.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:07:47 -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=Vl7I20wH; 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]:53804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCeo-00084z-SL for patch@linaro.org; Fri, 20 May 2022 20:07:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbN-00080X-Mq for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:14 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:44659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbK-0003yV-9P for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:12 -0400 Received: by mail-pl1-x633.google.com with SMTP id q4so8553498plr.11 for ; Fri, 20 May 2022 17:04:09 -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=2OyP2Wnw9umWfxtpbUetMIm1XRFLbapKewV58Lgr8fc=; b=Vl7I20wHocej6ezd+GOhft8MprLJBf9xVnw8ipS9GDYNOuoT+MHgc+N247SsfEqbxP Q1ZIkyYZUJt6DPPjlz+rEWUJwNgF9FNgp7kKe4eFJ4RV41T1/Uz8wqttXA6LQw5GiHvY j7c6k+KtcDnUtS8KEDVPoZAXrXciR05F7mWaOio3VLIG+ccDLieB5TJyXhamRXlnReYc JDAHpdBhe64aJVLX4GO4l0m5toGLm7r+upvS0rkneXJssuOndMhjoQf+t/FjoMfSVm23 rjDQRWMZArEmzoRkdXWFf5kUQmWJ8zV/kFKaxqyDX72JKY2s+Dr7S2Mwt0TQNkBU75AC lMPg== 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=2OyP2Wnw9umWfxtpbUetMIm1XRFLbapKewV58Lgr8fc=; b=opOrmB3m6WrWP+N+G18m3BHfYhbbleNxv42Hk7ZsqUN4Pk7LC8bQ+pZqv6rfRAqHgZ 2h7leq8EIjCKvpQGL3IKgq8PNIIf7Xh+A987mVa1DbYvgRthaWcert8M+qFVdpYwAXZd uRI/Zp/WZu2gx5I4qtHcY+2oXnD+iTaGBt6V8KiB6vLk/v45apR6SDRGd1JYZEAzHL3v lqBNFLzfzvP7LFPrQ9QR/sUKoBAzjANacWUhXB2sUZx8jW6Mk89zpqJzg/Nne/DbB6bO EmGYlbwQd2aJpi0lWm5ho4NBnRFRepbZUtg0gccC2Pr0F/6zLs4My6E8kgM88L9T2Pu7 aBpQ== X-Gm-Message-State: AOAM532Cv/stYndlvSK4Y9/ygDXT9cAFzmtDhGPdwYCwgq5lNZD81ErK mpKhJIigoszE4Q2574gHBkhHaQmB19Jhkg== X-Received: by 2002:a17:902:a387:b0:15e:f63f:237f with SMTP id x7-20020a170902a38700b0015ef63f237fmr12010647pla.32.1653091448990; Fri, 20 May 2022 17:04:08 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 05/49] semihosting: Add target_strlen for softmmu-uaccess.h Date: Fri, 20 May 2022 17:03:16 -0700 Message-Id: <20220521000400.454525-6-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::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- 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..51019b79ff 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 = -(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. */