From patchwork Sun Nov 14 10:35:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 519132 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp4155080imj; Sun, 14 Nov 2021 02:38:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUaOaWO1VHS7CRbseaAIcPtPnjxA/AkDg0qDOFr7f5r0ia9ZMn4g5JnqGAAqYbhe7P8CWw X-Received: by 2002:a05:6122:a13:: with SMTP id 19mr44782292vkn.17.1636886303568; Sun, 14 Nov 2021 02:38:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636886303; cv=none; d=google.com; s=arc-20160816; b=P4FpuyC3EF9BdzDshQUU0FaRHeUzEj3TVd5UOjGCI2UHSUw/inn1vLOwUMJ1QAJ0bN Hiq2LCEjqPSH8b0G8h2s9QddoC0UgpzZMwniVtsP8wrnVgODa8NQ1PZ0qMsOzoAo/My8 N28waAk6oyZn38vwlNBrmShqLtifdCeGlwvHuUhpPmfvKfKYCIlL0pez0dkw1eI8OlUD jsfRbUSjM2h3dtffqNTSzpY/sZ6HiSM+aXh6NTlNk2jDsN5iMsOSb7cVN1sYuQU3TxE8 3KJc4XyzR/3cvB8m4U4vsfLLr4jLI6uw8a/n1bDwPn8bCZ7pZWFzFS0PytRDhkRh2RII nx+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=5YdY/iarwR1o7rlm4TvNfomS0+BmE8A5jrB21UT6FG8=; b=IJvCYbiqa10nDwPfH5TL6vbmLZHMuhkxxuEZb800tFHwbltepj2Na7cs5sNpKvbSIg NvLHpCQTMKP9zdKj2Dbc0lAAuKUHHW6RP0k22qwWIARfRIhl1gsIQ+gRdfQ5C1g/d+jo 5D/zTWs4+t1vD6QhOzrvxRkOi6fMkNGZB1mb6btyQ1MHC6DTcF8qQf3dmwJKQkW3nN/W NQrIzoq0bzmodiReUs/tY5/pZBkrT06XZLMFMBEEzAgBuPqlvhAS/wdhnlCT6NvdJ55e YDWsQXKcriPo+AMGfckG+mPn0KiZoGJ2h9cYepVUJ1uBbvGMkn58tXskI2j4d60Z2fe8 2MhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JKCQtHZG; 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 t4si10025495uaj.247.2021.11.14.02.38.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Nov 2021 02:38:23 -0800 (PST) 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=JKCQtHZG; 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]:53720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmCtz-0006WT-0c for patch@linaro.org; Sun, 14 Nov 2021 05:38:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmCrd-0003zr-3z for qemu-devel@nongnu.org; Sun, 14 Nov 2021 05:35:57 -0500 Received: from [2a00:1450:4864:20::42b] (port=47034 helo=mail-wr1-x42b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmCra-0000gx-05 for qemu-devel@nongnu.org; Sun, 14 Nov 2021 05:35:56 -0500 Received: by mail-wr1-x42b.google.com with SMTP id u1so24326950wru.13 for ; Sun, 14 Nov 2021 02:35:53 -0800 (PST) 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=5YdY/iarwR1o7rlm4TvNfomS0+BmE8A5jrB21UT6FG8=; b=JKCQtHZGZiZI7JvFBzjSbr3tKlBgjRCMIUBBKQsMjZ6EibxNLTphlT5TsYA2zLeOIV WH9j4CpL6gwW/J0tN0hZ5mHDyfcU5LKyaQpT21DthvnG9mQ2DNxZQYNlIZXXa/AjFhgP pzdY5R8UY78g/Kaj39BIsn+t9Yt5JbetP2Fm15SN4nIgehdWuQ8vJaq1kyvQ6w/XtamD yA2gkFlWW2UlzDNUiFvJrXqX2RAeEQePLR/nYD0ENuNDkDg4r0laanXBa0a6ff3jf234 kGgoRmMQ94pOx2J9W1QmubsRqiIdn+Qms8xJ91TZW9BmdEbaXpU/lmzG+juvmxLDKt8p 9+nA== 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=5YdY/iarwR1o7rlm4TvNfomS0+BmE8A5jrB21UT6FG8=; b=C3T+ICPDIg/5LmbyvWM7lQ336eSpqIBbGbEbqLvzNqLdJDfWaDnC7KloMD6j+57WAH XXtVVIS0JpqL1VuDZklJrC8I5HYnijANG0bKrSwwJax4zqdGa0cPqWXREseEFenb29Ov PaSoSHO3+YU/xYT4PI1org5AHJqwi63T4kD+XyVyywxvF7lddjjPxJbus0c+BO9g/1ze 1oByIw7VUdCGDkFFXqV4FdL+LyjUtI6eI5FY8p99EOQ5Y1iS82nqq4YK8iQUr5fN+bvd Ae+8P76sTU/hcPEfV5IJcddyFgP1GrrCVxdVgeqHplpO7BX7WR+O/lm85186/ts2CTjO +2hA== X-Gm-Message-State: AOAM530inYlBLkSPlI7FjvB2UsQrrFzT0z5qc142dBQpOdeJLvlzHBlG NuZDiz0uK6aK09TI0hP5er5LMJ9U2e6U9JCdzYQ= X-Received: by 2002:a5d:4143:: with SMTP id c3mr37689146wrq.254.1636886152627; Sun, 14 Nov 2021 02:35:52 -0800 (PST) Received: from localhost.localdomain (60.red-95-126-179.staticip.rima-tde.net. [95.126.179.60]) by smtp.gmail.com with ESMTPSA id x1sm10638852wmc.22.2021.11.14.02.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Nov 2021 02:35:52 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 1/4] linux-user: Split out do_getdents, do_getdents64 Date: Sun, 14 Nov 2021 11:35:36 +0100 Message-Id: <20211114103539.298686-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211114103539.298686-1-richard.henderson@linaro.org> References: <20211114103539.298686-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42b (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Retain all 3 implementations of getdents for now. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/syscall.c | 325 +++++++++++++++++++++++-------------------- 1 file changed, 172 insertions(+), 153 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 544f5b662f..a2f605dec4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8137,6 +8137,176 @@ static int host_to_target_cpu_mask(const unsigned long *host_mask, return 0; } +#ifdef TARGET_NR_getdents +static int do_getdents(abi_long arg1, abi_long arg2, abi_long arg3) +{ + int ret; + +#ifdef EMULATE_GETDENTS_WITH_GETDENTS +# if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 + struct target_dirent *target_dirp; + struct linux_dirent *dirp; + abi_long count = arg3; + + dirp = g_try_malloc(count); + if (!dirp) { + return -TARGET_ENOMEM; + } + + ret = get_errno(sys_getdents(arg1, dirp, count)); + if (!is_error(ret)) { + struct linux_dirent *de; + struct target_dirent *tde; + int len = ret; + int reclen, treclen; + int count1, tnamelen; + + count1 = 0; + de = dirp; + target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!target_dirp) { + return -TARGET_EFAULT; + } + tde = target_dirp; + while (len > 0) { + reclen = de->d_reclen; + tnamelen = reclen - offsetof(struct linux_dirent, d_name); + assert(tnamelen >= 0); + treclen = tnamelen + offsetof(struct target_dirent, d_name); + assert(count1 + treclen <= count); + tde->d_reclen = tswap16(treclen); + tde->d_ino = tswapal(de->d_ino); + tde->d_off = tswapal(de->d_off); + memcpy(tde->d_name, de->d_name, tnamelen); + de = (struct linux_dirent *)((char *)de + reclen); + len -= reclen; + tde = (struct target_dirent *)((char *)tde + treclen); + count1 += treclen; + } + ret = count1; + unlock_user(target_dirp, arg2, ret); + } + g_free(dirp); +# else + struct linux_dirent *dirp; + abi_long count = arg3; + + dirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!dirp) { + return -TARGET_EFAULT; + } + ret = get_errno(sys_getdents(arg1, dirp, count)); + if (!is_error(ret)) { + struct linux_dirent *de; + int len = ret; + int reclen; + de = dirp; + while (len > 0) { + reclen = de->d_reclen; + if (reclen > len) { + break; + } + de->d_reclen = tswap16(reclen); + tswapls(&de->d_ino); + tswapls(&de->d_off); + de = (struct linux_dirent *)((char *)de + reclen); + len -= reclen; + } + } + unlock_user(dirp, arg2, ret); +# endif +#else + /* Implement getdents in terms of getdents64 */ + struct linux_dirent64 *dirp; + abi_long count = arg3; + + dirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!dirp) { + return -TARGET_EFAULT; + } + ret = get_errno(sys_getdents64(arg1, dirp, count)); + if (!is_error(ret)) { + /* + * Convert the dirent64 structs to target dirent. We do this + * in-place, since we can guarantee that a target_dirent is no + * larger than a dirent64; however this means we have to be + * careful to read everything before writing in the new format. + */ + struct linux_dirent64 *de; + struct target_dirent *tde; + int len = ret; + int tlen = 0; + + de = dirp; + tde = (struct target_dirent *)dirp; + while (len > 0) { + int namelen, treclen; + int reclen = de->d_reclen; + uint64_t ino = de->d_ino; + int64_t off = de->d_off; + uint8_t type = de->d_type; + + namelen = strlen(de->d_name); + treclen = offsetof(struct target_dirent, d_name) + namelen + 2; + treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long)); + + memmove(tde->d_name, de->d_name, namelen + 1); + tde->d_ino = tswapal(ino); + tde->d_off = tswapal(off); + tde->d_reclen = tswap16(treclen); + /* + * The target_dirent type is in what was formerly a padding + * byte at the end of the structure: + */ + *(((char *)tde) + treclen - 1) = type; + + de = (struct linux_dirent64 *)((char *)de + reclen); + tde = (struct target_dirent *)((char *)tde + treclen); + len -= reclen; + tlen += treclen; + } + ret = tlen; + } + unlock_user(dirp, arg2, ret); +#endif + return ret; +} +#endif /* TARGET_NR_getdents */ + +#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) +static int do_getdents64(abi_long arg1, abi_long arg2, abi_long arg3) +{ + struct linux_dirent64 *dirp; + abi_long count = arg3; + int ret; + + dirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!dirp) { + return -TARGET_EFAULT; + } + ret = get_errno(sys_getdents64(arg1, dirp, count)); + if (!is_error(ret)) { + struct linux_dirent64 *de; + int len = ret; + int reclen; + de = dirp; + while (len > 0) { + reclen = de->d_reclen; + if (reclen > len) { + break; + } + de->d_reclen = tswap16(reclen); + tswap64s((uint64_t *)&de->d_ino); + tswap64s((uint64_t *)&de->d_off); + de = (struct linux_dirent64 *)((char *)de + reclen); + len -= reclen; + } + } + unlock_user(dirp, arg2, ret); + return ret; +} +#endif /* TARGET_NR_getdents64 */ + #if defined(TARGET_NR_pivot_root) && defined(__NR_pivot_root) _syscall2(int, pivot_root, const char *, new_root, const char *, put_old) #endif @@ -10227,162 +10397,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, #endif #ifdef TARGET_NR_getdents case TARGET_NR_getdents: -#ifdef EMULATE_GETDENTS_WITH_GETDENTS -#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 - { - struct target_dirent *target_dirp; - struct linux_dirent *dirp; - abi_long count = arg3; - - dirp = g_try_malloc(count); - if (!dirp) { - return -TARGET_ENOMEM; - } - - ret = get_errno(sys_getdents(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent *de; - struct target_dirent *tde; - int len = ret; - int reclen, treclen; - int count1, tnamelen; - - count1 = 0; - de = dirp; - if (!(target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) - return -TARGET_EFAULT; - tde = target_dirp; - while (len > 0) { - reclen = de->d_reclen; - tnamelen = reclen - offsetof(struct linux_dirent, d_name); - assert(tnamelen >= 0); - treclen = tnamelen + offsetof(struct target_dirent, d_name); - assert(count1 + treclen <= count); - tde->d_reclen = tswap16(treclen); - tde->d_ino = tswapal(de->d_ino); - tde->d_off = tswapal(de->d_off); - memcpy(tde->d_name, de->d_name, tnamelen); - de = (struct linux_dirent *)((char *)de + reclen); - len -= reclen; - tde = (struct target_dirent *)((char *)tde + treclen); - count1 += treclen; - } - ret = count1; - unlock_user(target_dirp, arg2, ret); - } - g_free(dirp); - } -#else - { - struct linux_dirent *dirp; - abi_long count = arg3; - - if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) - return -TARGET_EFAULT; - ret = get_errno(sys_getdents(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent *de; - int len = ret; - int reclen; - de = dirp; - while (len > 0) { - reclen = de->d_reclen; - if (reclen > len) - break; - de->d_reclen = tswap16(reclen); - tswapls(&de->d_ino); - tswapls(&de->d_off); - de = (struct linux_dirent *)((char *)de + reclen); - len -= reclen; - } - } - unlock_user(dirp, arg2, ret); - } -#endif -#else - /* Implement getdents in terms of getdents64 */ - { - struct linux_dirent64 *dirp; - abi_long count = arg3; - - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { - return -TARGET_EFAULT; - } - ret = get_errno(sys_getdents64(arg1, dirp, count)); - if (!is_error(ret)) { - /* Convert the dirent64 structs to target dirent. We do this - * in-place, since we can guarantee that a target_dirent is no - * larger than a dirent64; however this means we have to be - * careful to read everything before writing in the new format. - */ - struct linux_dirent64 *de; - struct target_dirent *tde; - int len = ret; - int tlen = 0; - - de = dirp; - tde = (struct target_dirent *)dirp; - while (len > 0) { - int namelen, treclen; - int reclen = de->d_reclen; - uint64_t ino = de->d_ino; - int64_t off = de->d_off; - uint8_t type = de->d_type; - - namelen = strlen(de->d_name); - treclen = offsetof(struct target_dirent, d_name) - + namelen + 2; - treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long)); - - memmove(tde->d_name, de->d_name, namelen + 1); - tde->d_ino = tswapal(ino); - tde->d_off = tswapal(off); - tde->d_reclen = tswap16(treclen); - /* The target_dirent type is in what was formerly a padding - * byte at the end of the structure: - */ - *(((char *)tde) + treclen - 1) = type; - - de = (struct linux_dirent64 *)((char *)de + reclen); - tde = (struct target_dirent *)((char *)tde + treclen); - len -= reclen; - tlen += treclen; - } - ret = tlen; - } - unlock_user(dirp, arg2, ret); - } -#endif - return ret; + return do_getdents(arg1, arg2, arg3); #endif /* TARGET_NR_getdents */ #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) case TARGET_NR_getdents64: - { - struct linux_dirent64 *dirp; - abi_long count = arg3; - if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) - return -TARGET_EFAULT; - ret = get_errno(sys_getdents64(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent64 *de; - int len = ret; - int reclen; - de = dirp; - while (len > 0) { - reclen = de->d_reclen; - if (reclen > len) - break; - de->d_reclen = tswap16(reclen); - tswap64s((uint64_t *)&de->d_ino); - tswap64s((uint64_t *)&de->d_off); - de = (struct linux_dirent64 *)((char *)de + reclen); - len -= reclen; - } - } - unlock_user(dirp, arg2, ret); - } - return ret; + return do_getdents64(arg1, arg2, arg3); #endif /* TARGET_NR_getdents64 */ #if defined(TARGET_NR__newselect) case TARGET_NR__newselect: From patchwork Sun Nov 14 10:35:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 519134 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp4156555imj; Sun, 14 Nov 2021 02:40:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeStgx0rXgwDyZySJgDn8SeUQB9bJrowc6uDU1NOiM61sinEyDwcjF4m5MQAsf13ojeHIg X-Received: by 2002:a9f:3086:: with SMTP id j6mr45801309uab.83.1636886402851; Sun, 14 Nov 2021 02:40:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636886402; cv=none; d=google.com; s=arc-20160816; b=XHJIL39Q2+VYe15W/2bk+A8PgKEmVL7b0863e4Uea2uRA3tPQJvx+EkSdfWgl2U4Lk 6TcXeasNmSefJymCaTf1fqhb7xQWurHpHexjxeRC05g42HGWW0lDj9fY8D+soQDzbIdC n5HSZWLAQnnUWvTBkoVoMgCV3vxX49pm5Jk/dM3j6ibQ/PwwlG+qS4lMwocm/+sIUhUY grsdCU7DSqv8cgamtn8O4VCnvvcojbKUJzMwAAdpmdyg5H7a1A0Zi5RLVWE2LUUfLnL+ fdqyzk+fepva7zfLAOayFR+cxhcs3VxuRsj8Ih6+gMTq26wrMutmYk0/uunqfvJfA7B5 kexg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=NgWRpb6eD25eDJnCmvoWcYOQSpkeHkzdEszyRb0jyTc=; b=ixS+NN50cYWN53RsDZumxWzoap0HA9GwKFCjju3WgGRa8s3eGRk3xhA+gJ/NE25Yyt znJlg2dzD3+YAIBEjBjZ7rPy5gUzPWn1f1Zog9bgPZrGBsoAg7+Fl/+Pd2T0octgRy6K 7xxV5AFkXYcE9mFwswknEiPH8scTmuNtGG87yGMI5bVA+HLDtm+ZvniPjD5rCdkeysdg uw78BSS0RbTPXW/dVSkl3/l+DIxYB7ileoJi6ngQFIVCD7978XFqefn+lnf2zltI/3qo nHEdiPAVkvNYvK9mAZ2j/u2P5tX3Cf7o08qGdAc1acCoB+LS/RlRQb3RNnUNFoJDlgQU vvCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iuVh9ewO; 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 r18si24377255vso.431.2021.11.14.02.40.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Nov 2021 02:40:02 -0800 (PST) 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=iuVh9ewO; 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]:58046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmCva-0000xJ-CI for patch@linaro.org; Sun, 14 Nov 2021 05:40:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmCre-00041k-Ce for qemu-devel@nongnu.org; Sun, 14 Nov 2021 05:35:58 -0500 Received: from [2a00:1450:4864:20::32e] (port=46759 helo=mail-wm1-x32e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmCrc-0000hI-Jy for qemu-devel@nongnu.org; Sun, 14 Nov 2021 05:35:57 -0500 Received: by mail-wm1-x32e.google.com with SMTP id b184-20020a1c1bc1000000b0033140bf8dd5so10034117wmb.5 for ; Sun, 14 Nov 2021 02:35:56 -0800 (PST) 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=NgWRpb6eD25eDJnCmvoWcYOQSpkeHkzdEszyRb0jyTc=; b=iuVh9ewOEFnuBGoHg6sSFSQ9Flwe1EIVXnfLvz2ebuB8sXv0YosLdSza32PUl7Et58 hHzag+KHlCQuA3I9ddrX/hCkfZE+Ov3IDl0SLvkMMdWTMdyFByU52B72r0XE539fuaLz r0dqJdkAGWZ6ew0Rt4sgMTYNwje/6tmlRO7d4WcCDM7q00RNk9g0roT/DSBNe2SNtuC0 ajgy/fbE9pOv7iu81P1Bs6jG1GEub7JfI7NscbPbCTlatGYKJEX/hfT5ZYmHhw+Qv9dJ v4izP4cCeMV/q9NK2Ulmkb+hWPGmg8PznLtyfGJEyNeex9mQgA6sxDW/W3u9100yOUTH 33+A== 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=NgWRpb6eD25eDJnCmvoWcYOQSpkeHkzdEszyRb0jyTc=; b=h0pNn1LZr9TAZl4UpHHNJ3fHYfQJmQPKly+Pbtd5DCpeV9xglTfut9u1E9YEsgeYID zYoolf7BtaLEGGEoTDKg9CxXGbl9XQWfOAOhtCjBScHNCJGhl0mlgrymTHl4HOByuiiU 4ogJmziqpYlJkgy86ea3BRs+Wfjh5bWoaq8FQPFeqb6zyAWP/Yef62+KYL4z6SzUd1lD +L8YUKPk4POCP1s3daKYnEnPdFRq9PD9+gML9u6TScpdCRgQg18muOBC1RPPvDuTZkAL XzqaRpbUUk3/MGzsVfSAYkUWQ6+z8JzUu0UmlUZSvh2pYCiI8+2rNvFvwotGFJdxJ6TU zE6w== X-Gm-Message-State: AOAM531DWcyhEg8smmsx6olHHN/FGCo5G/LAxMIVfrwZfQu3Gg8MW5fo agUtiXkC52q8tHJQ9iwiJqg6o6UOsaiB8Z2cF2A= X-Received: by 2002:a7b:c756:: with SMTP id w22mr33524909wmk.34.1636886155300; Sun, 14 Nov 2021 02:35:55 -0800 (PST) Received: from localhost.localdomain (60.red-95-126-179.staticip.rima-tde.net. [95.126.179.60]) by smtp.gmail.com with ESMTPSA id x1sm10638852wmc.22.2021.11.14.02.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Nov 2021 02:35:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 2/4] linux-user: Always use flexible arrays for dirent d_name Date: Sun, 14 Nov 2021 11:35:37 +0100 Message-Id: <20211114103539.298686-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211114103539.298686-1-richard.henderson@linaro.org> References: <20211114103539.298686-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32e (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We currently use a flexible array member for target_dirent, but use incorrectly fixed length arrays for target_dirent64, linux_dirent and linux_dirent64. This requires that we adjust the definition of the VFAT READDIR ioctls which hard-code the 256 namelen size into the ioctl constant. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/syscall_defs.h | 6 +++--- linux-user/syscall.c | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index a5ce487dcc..98b09ee6d6 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -441,7 +441,7 @@ struct target_dirent64 { int64_t d_off; unsigned short d_reclen; unsigned char d_type; - char d_name[256]; + char d_name[]; }; @@ -2714,7 +2714,7 @@ struct linux_dirent { long d_ino; unsigned long d_off; unsigned short d_reclen; - char d_name[256]; /* We must not include limits.h! */ + char d_name[]; }; struct linux_dirent64 { @@ -2722,7 +2722,7 @@ struct linux_dirent64 { int64_t d_off; unsigned short d_reclen; unsigned char d_type; - char d_name[256]; + char d_name[]; }; struct target_mq_attr { diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a2f605dec4..499415ad81 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -197,8 +197,10 @@ //#define DEBUG_ERESTARTSYS //#include -#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2]) -#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2]) +#define VFAT_IOCTL_READDIR_BOTH \ + _IOC(_IOC_READ, 'r', 1, (sizeof(struct linux_dirent) + 256) * 2) +#define VFAT_IOCTL_READDIR_SHORT \ + _IOC(_IOC_READ, 'r', 2, (sizeof(struct linux_dirent) + 256) * 2) #undef _syscall0 #undef _syscall1 From patchwork Sun Nov 14 10:35:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 519131 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp4153954imj; Sun, 14 Nov 2021 02:36:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxFNeAU60K6oL7qp3YRXxHfw0d76/mcNbcpvxE8dkR5zz53ooSMASOjkTKUXNk6AiUahn2 X-Received: by 2002:a1f:a857:: with SMTP id r84mr45068916vke.0.1636886215313; Sun, 14 Nov 2021 02:36:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636886215; cv=none; d=google.com; s=arc-20160816; b=aNWBFK7Nj7M4mLgfklRFQNPaVXXqwcmNQCXp33lom//v9BrUbjyXw487e5EiMCXQrf tB+imOHJ5iUiesX830DLV3BgAJBpomCtl/F+XAhWgWrRgB9sE0cq7vaBhK4ERjdL7Ahe cZlf8wmo6crKOxKsPcpm0DaP2ijmTcAePaYdY8V7xZSMiFSRo/nfeLDawBY99wntaie6 +b7i212z6trNVNo6T2CSl/f7LAjVG5xTv/vP2wOutEiWjHaBZBeNAK23W0yb6Bt6AU4Y +b9NgEBE36pDzLkJONnTBuSLUcqVLJdwVEqvJWHCmfwq58G4JxYEpFZQcUgcpv9Yulw4 YqTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=eGSHLpNAu9g6Np9tb4uVWnbjp2oiYs6nIhg97qpdgNI=; b=U5BIENBCxfBxJTd9/nMbvuxcFAR2azxbWukqh2oJ50yAkTAsF1wH7KDPoL/CS5GQ0Q nAM3D1fdDRoQ5mG6Efj61JRSqu5yUOgHp0g9UubMIM59oGW1fpk31BvhhPwQ/qGDOwQV dIe6b9D5gDk+2otcj4zoUbXEI4t+VSKTfv9sdRygsA9bFIeuCZsrHejN0zylYle19Hy5 u+3CuhXkqZdBUCkLum5aJ10ZKR/8iVISnhH8lKt23T/BsMx4Uhk+hbpttoERrk1GzGcX KtGBmjWu4tAKp/ruHzWkfVoVZkRhCZw3WdEuvGmIntLZxbassa9hj+sUhvEBPQMW4bhc QRjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c5cx+mdk; 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 n18si17846848ual.10.2021.11.14.02.36.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Nov 2021 02:36:55 -0800 (PST) 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=c5cx+mdk; 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]:50162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmCsY-00048W-Qh for patch@linaro.org; Sun, 14 Nov 2021 05:36:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmCrg-00045C-3u for qemu-devel@nongnu.org; Sun, 14 Nov 2021 05:36:00 -0500 Received: from [2a00:1450:4864:20::331] (port=36453 helo=mail-wm1-x331.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmCre-0000hN-Dz for qemu-devel@nongnu.org; Sun, 14 Nov 2021 05:35:59 -0500 Received: by mail-wm1-x331.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso13343348wml.1 for ; Sun, 14 Nov 2021 02:35:58 -0800 (PST) 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=eGSHLpNAu9g6Np9tb4uVWnbjp2oiYs6nIhg97qpdgNI=; b=c5cx+mdkgENL6oiRjLGjcOir6Dn3CM6yGVBHa3Hm+muVdmQiwKQjnLw/GcMY0jFlwJ B0ZBAfg9l6lr5CpYZpKguULVYASkxiLw67gAU80TDugStnIBWDhVFcjnpmYhXirsVIZQ D0x3XHBWsydI18nJC6G0N0nu5fpCWYl+86oN3Hl21XRv4xzrE59TBwJzSbp2olzPogte x4Yvi8ssMtL3jEzkh2WE4yfwSF97hDdylUVzKu0t5mF7b04lb78HS7Uzr/kh1/piTEvO Kgsti14/NpQ5P9rbCd/L+tRVaF6DtPVKh0SZi5OW5nVNSHZzqMAm7Fo+CMeCSHsdgdL2 N5OA== 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=eGSHLpNAu9g6Np9tb4uVWnbjp2oiYs6nIhg97qpdgNI=; b=anTXaxd7ns7TC1WyDIay15Of1QTKyW7zwRVuJQj0woAct/vLAlslfjjkT/I743CZqG 83ZgAxHeWmheL6nIe5l+6rCTIk6hnJxcZSr3pLUAhioBFqYQ5YYsfzdEV6JAg7fd7AhW IiZ7xXaUW5DayzmBWkg021bewD7INujbWc7BuF8YJQibfVGqzrGCOt8d8/AzhlhZnx7x urPoqkLqZZk7s8Cka0zPG1CH/sqZCNajbghEGQodZ1PGRbJnGFuC5HNqJ7dF2YFxAyyM tcmg9iIGd76Cy0t6q6YP93nT0ch6SOGTu+p6Wve9NKyu9XAKWJ1HHq7WEQUWuzA/0MAA o20g== X-Gm-Message-State: AOAM533l645APMu4oM8FEIqFUXu+WZzy+7ukl/iI97E+QE08Muf7X+lq cxsUb9ZqMnBimbKQKysuxhBsveFgGuLQbhOzTYw= X-Received: by 2002:a7b:ce8c:: with SMTP id q12mr32997166wmj.91.1636886156605; Sun, 14 Nov 2021 02:35:56 -0800 (PST) Received: from localhost.localdomain (60.red-95-126-179.staticip.rima-tde.net. [95.126.179.60]) by smtp.gmail.com with ESMTPSA id x1sm10638852wmc.22.2021.11.14.02.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Nov 2021 02:35:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 3/4] linux-user: Fix member types of target_dirent64 Date: Sun, 14 Nov 2021 11:35:38 +0100 Message-Id: <20211114103539.298686-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211114103539.298686-1-richard.henderson@linaro.org> References: <20211114103539.298686-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::331 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The host uint64_t (etc) does not have the correct alignment constraint as the guest: use abi_* types. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/syscall_defs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 98b09ee6d6..41aaafbac1 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -437,9 +437,9 @@ struct target_dirent { }; struct target_dirent64 { - uint64_t d_ino; - int64_t d_off; - unsigned short d_reclen; + abi_ullong d_ino; + abi_llong d_off; + abi_ushort d_reclen; unsigned char d_type; char d_name[]; }; From patchwork Sun Nov 14 10:35:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 519133 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp4155195imj; Sun, 14 Nov 2021 02:38:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQKXQGZzZjeLN1uygOLLSp8DRu7nemr2f+sALYsirSdhJzUxBpNK98oBnwZk3JnAP0ZFkC X-Received: by 2002:a9f:3d85:: with SMTP id c5mr45457405uai.12.1636886313109; Sun, 14 Nov 2021 02:38:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636886313; cv=none; d=google.com; s=arc-20160816; b=v4pdrieA8m06BZYziGBOD0gS0a/httpYkAFxm3I2TCj2E52j8/WySwRU944QAv70ce mv2FvGlX3iHfh7Eu2IrIeEIP+NwKOvvgcbMuPkwCAijgwBelD/200vu3Ca1eUrsBweHm cWvOdUnlqSoxPmEPTMVg924A9ezkrogfoR/29Ns3LfZmdTB5Ygvvk5vLKrZ+qwd6DOkB YPs+ueSamrCOvY4eJNvL/u5WTapp5o6OGbZ6V8JAkIoXX2pRyErq3TwgE4doGC1szBir FfeONS3yb2DopT1ja/tYrW+YWLQCucprFNPMkMxSXbKQkDTUq2BYdTM0y4khChlA10cB +N1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=u7NrqkDveBa4hwrZ13pQ52EsKuNUzd3UgVxFiV4cVYA=; b=IUacZHhwET+sUWxIUR34XV47FJEtcAPIy7Of9ZChhdT+/8Q4C9Y0RLYrcpAn1Q4uYP FoF+D/oEn8IKkkSREU2xK2o128Hr2bwUrzEJVwccPi0nd4pnlTW77oa3koZymPU1YTKx Ae9AzgTJgeV+9WTKA3S8oMYrCLdZ6IO4K9EX5RrmyBCxweACQnDLdt79tFCT7Dr0qPln UkxjLTk2q2tyZwuLjpcFRrQ/ZFzWU/+RG54PhJxNVdErcK9pcNFC6OnGObqLKZwd5iQl DFMYO3db6noy+JSEIIT/2Yz2ALF8LiEFLOqJuoaGkpanCv55+y/jUXp12yep22RIj1NA A5wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ntw3qQ6U; 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 y3si15386591vsi.94.2021.11.14.02.38.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Nov 2021 02:38:33 -0800 (PST) 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=Ntw3qQ6U; 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]:54458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmCu8-00071M-GW for patch@linaro.org; Sun, 14 Nov 2021 05:38:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmCri-000499-5j for qemu-devel@nongnu.org; Sun, 14 Nov 2021 05:36:02 -0500 Received: from [2a00:1450:4864:20::32c] (port=40831 helo=mail-wm1-x32c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmCrf-0000hg-Nw for qemu-devel@nongnu.org; Sun, 14 Nov 2021 05:36:01 -0500 Received: by mail-wm1-x32c.google.com with SMTP id az33-20020a05600c602100b00333472fef04so12613351wmb.5 for ; Sun, 14 Nov 2021 02:35:59 -0800 (PST) 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=u7NrqkDveBa4hwrZ13pQ52EsKuNUzd3UgVxFiV4cVYA=; b=Ntw3qQ6U0qQqTLEFjLdJs9M+lCBWSV899Wc+QJ+B7DY1UVlP2u6wugd2kztg1AaSpc zyIPdugHdeq9t4gO+asPe/kmsSvlOBD+LCUypyv7a2JwRXq1gRKeaNX+9LQ280xRM7D8 aMSU/1HZr9vhYMQv4Z2MSWDlI62wN/T2twRO0ZoEzMnS4tskoqF9DEFUbnR4RNdV7ncm dRbCLbx8xY8qExhqmDsYIBoV9ddZsMOb9Pj8rh/3RAVBXdZz2PYbfO0YXYnKvpFq/yIz ujyCXR7qfixWFj7pjUj7WJ/bka6z/QxabFUv5VCZ5CkRHjVG/qu5JQPLxwmdwwXm9m1U dJeA== 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=u7NrqkDveBa4hwrZ13pQ52EsKuNUzd3UgVxFiV4cVYA=; b=F938HgEmcKX6WmbYam8//MIBEl6yYHbBP0a8JYTh1/5zhx+IFzGr8KF4HRdw9zsGUK 40r19LRBkSyNQVG2rWiu7ABLiQR49U4g0+K3oRYDBt8IYyW9GJwwPZiHDaimLpci+WKV 963t7z1zte7+czq9w8FbcaCjhv8H5gSS/GiN495Tm5MFQcFj9n1XA4vF9VJEK9tueZZP HOoexibTjabhQ3Xk3CLRKMjrBqpWpm5/SkdNCHD1rGYCSDCldJf867EXK+t1aLU0Pjk5 OJMcKeDeGT0QW44T0K94q15IN1UDe0YKVUu4tIttLkLImySzZtNjFJ1Ex8sdvXT335SF +Ckw== X-Gm-Message-State: AOAM533VjK7BYxO/sOS2MJQuM/RKRgZTralJqZBzUyIBG8Gsp+OhRkqr /W7ZxfhSfKd6AUbK8NWANkjhfoVjjzrJqN89ONw= X-Received: by 2002:a7b:c194:: with SMTP id y20mr34037745wmi.61.1636886158283; Sun, 14 Nov 2021 02:35:58 -0800 (PST) Received: from localhost.localdomain (60.red-95-126-179.staticip.rima-tde.net. [95.126.179.60]) by smtp.gmail.com with ESMTPSA id x1sm10638852wmc.22.2021.11.14.02.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Nov 2021 02:35:57 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 4/4] linux-user: Rewrite do_getdents, do_getdents64 Date: Sun, 14 Nov 2021 11:35:39 +0100 Message-Id: <20211114103539.298686-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211114103539.298686-1-richard.henderson@linaro.org> References: <20211114103539.298686-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32c (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Always allocate host storage; this ensures that the struct is sufficiently aligned for the host. Merge the three host implementations of getdents via a few ifdefs. Utilize the same method for do_getdents64. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/704 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/syscall.c | 259 ++++++++++++++++++++----------------------- 1 file changed, 121 insertions(+), 138 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 499415ad81..f1cfcc8104 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8140,172 +8140,155 @@ static int host_to_target_cpu_mask(const unsigned long *host_mask, } #ifdef TARGET_NR_getdents -static int do_getdents(abi_long arg1, abi_long arg2, abi_long arg3) +static int do_getdents(abi_long dirfd, abi_long arg2, abi_long count) { - int ret; + g_autofree void *hdirp = NULL; + void *tdirp; + int hlen, hoff, toff; + int hreclen, treclen; + off64_t prev_diroff = 0; -#ifdef EMULATE_GETDENTS_WITH_GETDENTS -# if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 - struct target_dirent *target_dirp; - struct linux_dirent *dirp; - abi_long count = arg3; - - dirp = g_try_malloc(count); - if (!dirp) { + hdirp = g_try_malloc(count); + if (!hdirp) { return -TARGET_ENOMEM; } - ret = get_errno(sys_getdents(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent *de; - struct target_dirent *tde; - int len = ret; - int reclen, treclen; - int count1, tnamelen; +#ifdef EMULATE_GETDENTS_WITH_GETDENTS + hlen = sys_getdents(dirfd, hdirp, count); +#else + hlen = sys_getdents64(dirfd, hdirp, count); +#endif - count1 = 0; - de = dirp; - target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!target_dirp) { - return -TARGET_EFAULT; - } - tde = target_dirp; - while (len > 0) { - reclen = de->d_reclen; - tnamelen = reclen - offsetof(struct linux_dirent, d_name); - assert(tnamelen >= 0); - treclen = tnamelen + offsetof(struct target_dirent, d_name); - assert(count1 + treclen <= count); - tde->d_reclen = tswap16(treclen); - tde->d_ino = tswapal(de->d_ino); - tde->d_off = tswapal(de->d_off); - memcpy(tde->d_name, de->d_name, tnamelen); - de = (struct linux_dirent *)((char *)de + reclen); - len -= reclen; - tde = (struct target_dirent *)((char *)tde + treclen); - count1 += treclen; - } - ret = count1; - unlock_user(target_dirp, arg2, ret); + hlen = get_errno(hlen); + if (is_error(hlen)) { + return hlen; } - g_free(dirp); -# else - struct linux_dirent *dirp; - abi_long count = arg3; - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { + tdirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!tdirp) { return -TARGET_EFAULT; } - ret = get_errno(sys_getdents(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent *de; - int len = ret; - int reclen; - de = dirp; - while (len > 0) { - reclen = de->d_reclen; - if (reclen > len) { + + for (hoff = toff = 0; hoff < hlen; hoff += hreclen, toff += treclen) { +#ifdef EMULATE_GETDENTS_WITH_GETDENTS + struct linux_dirent *hde = hdirp + hoff; +#else + struct linux_dirent64 *hde = hdirp + hoff; +#endif + struct target_dirent *tde = tdirp + toff; + int namelen; + uint8_t type; + + namelen = strlen(hde->d_name); + hreclen = hde->d_reclen; + treclen = offsetof(struct target_dirent, d_name) + namelen + 2; + treclen = QEMU_ALIGN_UP(treclen, __alignof(struct target_dirent)); + + if (toff + treclen > count) { + /* + * If the host struct is smaller than the target struct, or + * requires less alignment and thus packs into less space, + * then the host can return more entries than we can pass + * on to the guest. + */ + if (toff == 0) { + toff = -TARGET_EINVAL; /* result buffer is too small */ break; } - de->d_reclen = tswap16(reclen); - tswapls(&de->d_ino); - tswapls(&de->d_off); - de = (struct linux_dirent *)((char *)de + reclen); - len -= reclen; - } - } - unlock_user(dirp, arg2, ret); -# endif -#else - /* Implement getdents in terms of getdents64 */ - struct linux_dirent64 *dirp; - abi_long count = arg3; - - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { - return -TARGET_EFAULT; - } - ret = get_errno(sys_getdents64(arg1, dirp, count)); - if (!is_error(ret)) { - /* - * Convert the dirent64 structs to target dirent. We do this - * in-place, since we can guarantee that a target_dirent is no - * larger than a dirent64; however this means we have to be - * careful to read everything before writing in the new format. - */ - struct linux_dirent64 *de; - struct target_dirent *tde; - int len = ret; - int tlen = 0; - - de = dirp; - tde = (struct target_dirent *)dirp; - while (len > 0) { - int namelen, treclen; - int reclen = de->d_reclen; - uint64_t ino = de->d_ino; - int64_t off = de->d_off; - uint8_t type = de->d_type; - - namelen = strlen(de->d_name); - treclen = offsetof(struct target_dirent, d_name) + namelen + 2; - treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long)); - - memmove(tde->d_name, de->d_name, namelen + 1); - tde->d_ino = tswapal(ino); - tde->d_off = tswapal(off); - tde->d_reclen = tswap16(treclen); /* - * The target_dirent type is in what was formerly a padding - * byte at the end of the structure: + * Return what we have, resetting the file pointer to the + * location of the first record not returned. */ - *(((char *)tde) + treclen - 1) = type; - - de = (struct linux_dirent64 *)((char *)de + reclen); - tde = (struct target_dirent *)((char *)tde + treclen); - len -= reclen; - tlen += treclen; + lseek64(dirfd, prev_diroff, SEEK_SET); + break; } - ret = tlen; - } - unlock_user(dirp, arg2, ret); + + prev_diroff = hde->d_off; + tde->d_ino = tswapal(hde->d_ino); + tde->d_off = tswapal(hde->d_off); + tde->d_reclen = tswap16(treclen); + memcpy(tde->d_name, hde->d_name, namelen + 1); + + /* + * The getdents type is in what was formerly a padding byte at the + * end of the structure. + */ +#ifdef EMULATE_GETDENTS_WITH_GETDENTS + type = *((uint8_t *)hde + hreclen - 1); +#else + type = hde->d_type; #endif - return ret; + *((uint8_t *)tde + treclen - 1) = type; + } + + unlock_user(tdirp, arg2, toff); + return toff; } #endif /* TARGET_NR_getdents */ #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) -static int do_getdents64(abi_long arg1, abi_long arg2, abi_long arg3) +static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count) { - struct linux_dirent64 *dirp; - abi_long count = arg3; - int ret; + g_autofree void *hdirp = NULL; + void *tdirp; + int hlen, hoff, toff; + int hreclen, treclen; + off64_t prev_diroff = 0; - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { + hdirp = g_try_malloc(count); + if (!hdirp) { + return -TARGET_ENOMEM; + } + + hlen = get_errno(sys_getdents64(dirfd, hdirp, count)); + if (is_error(hlen)) { + return hlen; + } + + tdirp = lock_user(VERIFY_WRITE, arg2, count, 0); + if (!tdirp) { return -TARGET_EFAULT; } - ret = get_errno(sys_getdents64(arg1, dirp, count)); - if (!is_error(ret)) { - struct linux_dirent64 *de; - int len = ret; - int reclen; - de = dirp; - while (len > 0) { - reclen = de->d_reclen; - if (reclen > len) { + + for (hoff = toff = 0; hoff < hlen; hoff += hreclen, toff += treclen) { + struct linux_dirent64 *hde = hdirp + hoff; + struct target_dirent64 *tde = tdirp + toff; + int namelen; + + namelen = strlen(hde->d_name) + 1; + hreclen = hde->d_reclen; + treclen = offsetof(struct target_dirent64, d_name) + namelen; + treclen = QEMU_ALIGN_UP(treclen, __alignof(struct target_dirent64)); + + if (toff + treclen > count) { + /* + * If the host struct is smaller than the target struct, or + * requires less alignment and thus packs into less space, + * then the host can return more entries than we can pass + * on to the guest. + */ + if (toff == 0) { + toff = -TARGET_EINVAL; /* result buffer is too small */ break; } - de->d_reclen = tswap16(reclen); - tswap64s((uint64_t *)&de->d_ino); - tswap64s((uint64_t *)&de->d_off); - de = (struct linux_dirent64 *)((char *)de + reclen); - len -= reclen; + /* + * Return what we have, resetting the file pointer to the + * location of the first record not returned. + */ + lseek64(dirfd, prev_diroff, SEEK_SET); + break; } + + prev_diroff = hde->d_off; + tde->d_ino = tswap64(hde->d_ino); + tde->d_off = tswap64(hde->d_off); + tde->d_reclen = tswap16(treclen); + tde->d_type = hde->d_type; + memcpy(tde->d_name, hde->d_name, namelen); } - unlock_user(dirp, arg2, ret); - return ret; + + unlock_user(tdirp, arg2, toff); + return toff; } #endif /* TARGET_NR_getdents64 */