From patchwork Mon Nov 22 08:23:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 519283 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp6621475imj; Mon, 22 Nov 2021 00:25:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzD46y9FIY7R8ylxLbbqOwzaHbjmGG2erToDk05IRBIkBO1yxlpr/mSMr7FxMXJgSjLOMfk X-Received: by 2002:a05:620a:27d0:: with SMTP id i16mr47483160qkp.440.1637569543149; Mon, 22 Nov 2021 00:25:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637569543; cv=none; d=google.com; s=arc-20160816; b=zCMFyTAhLs3eCDtfxacpPX02OScz/SuAgFw1bfwnsUrAUI8cSKgOJVxtZchbHpXji1 idoC+8myCaf7jYKYrAuKzzfGtNpY2zR0Yq6O0XWt3/ZHMVU1wxP/4xk/FhGldarXdFGw aRbuYk1KWcetMWQMHDnhzuPRs/Ca61bW5sLd4m6I7w1yZnVRSG9uLrPKyY/r13G1P00e F2lSuibNa/6JZ2Tf+d8SFHk+qY5mG+DhK88A41mX4rjKJpahT/5LQNiJDZuzVxwZ3aTu CKPJvXo3MmGCxE/623jh48KYvEOVCkGhzy5KxCTcVIsSfhQniXDbj93jTeT8xS25TvX/ o3uQ== 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; bh=jp/kfxSG7QFQNHBy93p6+UtmRcVvveapCnyF8HGdO2c=; b=Xyf1wJO1iSfcsifbsrFfvlmTPMtCUIwbHIKsPFBTiLGlM8mJu5YJ/u24p3lP861v2I blzIEbn+R6OkO7wCveyKNN3riKGiHywg/Hb2uSwVglY+pBCJMKAIZ3QZQrg/OKW/k5Ym FMn07DEiEu4PVqDgm/bnkli5Z8D/6h492NJSKpv2C9OoESXIow0E1CbkPlO9QyIBpyH0 rtP4sMi98y/ND9GykZICsqCwOhxEG1NATsdrYi8QuxdVXp4Eq1tfqeNwupAcDs6DnUrj qmg+fNQA9JE6MLD2rtEXp9wI2qf/eFwyRLok6pK/sgHjGp6eAG+mlBw4N6OuwIxbbD19 PiVg== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m17si16108180qtx.14.2021.11.22.00.25.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Nov 2021 00:25:43 -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; 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" Received: from localhost ([::1]:45520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mp4dy-0001br-OD for patch@linaro.org; Mon, 22 Nov 2021 03:25:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mp4bf-0001X1-Nr for qemu-devel@nongnu.org; Mon, 22 Nov 2021 03:23:22 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:36781) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mp4bd-00035E-9Y for qemu-devel@nongnu.org; Mon, 22 Nov 2021 03:23:19 -0500 Received: from quad ([82.142.2.234]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MSswA-1nDnVp3E9W-00UHW7; Mon, 22 Nov 2021 09:23:12 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 1/5] linux-user: Split out do_getdents, do_getdents64 Date: Mon, 22 Nov 2021 09:23:06 +0100 Message-Id: <20211122082310.377809-2-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211122082310.377809-1-laurent@vivier.eu> References: <20211122082310.377809-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:EXbD8RfDaifTz8whB2UETtGdgwPtd+pceXxR4nhay8jKwdPOsNZ yP3XOkJkwjK9wr5wElj+1muY8flQoSBZt7w3v3GOr8yoQp7Mv+vzjej4YVcqfPo57sBcaMG pOiFDLH7LwF6LCpIiiCYXzXO+91VFDM9wQhJ/Z8c2C6vivcBy5ZPDopVt3ppjAIHk/bLlTG HQfIOc9l3flOtJ4xximNA== X-UI-Out-Filterresults: notjunk:1;V03:K0:SONwfYRPFhI=:ud79adI9E08AE1AD+z2Gwv c25LuXBrbb15DHv9vRgYiVLD2X6Knv74F8A4xk0HquDeX1f07AS02gGGXJv+bubSaXrlM7h/b 2VelmIicLM0rxFw2nXI9FsAOcHfO5TqLQ/pSkWCyljfVz6UtodT1u3I3JaHLoyD9vWkUXQQvJ I79IP9SOYiPRTeawAFj/6gJqopHB4wqzZ077fGA68WmUzrFGpRG9VGKqmeYW5hcq523xIyTCN PgBfUin0fRTkrlHH8sqy5BksaWRSAYq0Au43GZUg4iGrEZbr2P+/ZAHCwZz/A8rx60ncX+qY0 XqSH/nsOIe6xEtiaQsZ9g7AZe683mVjZA71jpGolmBDwadhv3MwmE1yXp7m6KkXI9IewOVBtp fe3LUuYNJ5xGue1MBXCTJp9zb/T20TZXNB5QTs+xcyLLJkS0V2F7IVZ7x3wM2telKu/OJKLW/ OJmQr/6R3peHpeOInm+WEKVcfl9r1h/TFKdRNKF3TdwCVE91DLsFRxTU74iwIoe4wdE3tsOqc /5Sy3Bn5zCgX3QynX4nOmSHKU0QwN01TjGjeSdPxBWB91qBizp0hNV54EFCFd60XaZtwo8BDf AGoSGevCIqQBCeIh/qg3ko0uQNeMQmgFUiAWjFCVMgPd+05NApoaynJNl1ukkh9zAeGvcn/Jo aJt27qhlvAQUUUJojExmz+YSqZ6e+CynU+xPKneluiaxq3boe0vcfDvBypPwhwhqbf14= Received-SPF: none client-ip=212.227.126.130; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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: , Cc: Richard Henderson , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Retain all 3 implementations of getdents for now. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20211114103539.298686-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- 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 544f5b662ffe..a2f605dec4ca 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 Mon Nov 22 08:23:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 519282 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp6621463imj; Mon, 22 Nov 2021 00:25:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhpLlrv4AEdyDgpgSIeBhlyn5wxbd/9LWFlucQG4xGDiDbLwNQFbwSI2FbCPof3i/liYs5 X-Received: by 2002:ac8:5bcc:: with SMTP id b12mr29055185qtb.249.1637569541885; Mon, 22 Nov 2021 00:25:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637569541; cv=none; d=google.com; s=arc-20160816; b=hZCIr92gEpwlbcv7gIS9A03E4NtTl6pUUrMlzqmNJHQo0hHRLV39St+jZC8nwet2Iw LVfuBQpMdiG2Ai20KKhV9u7+rFBpUE1nb2U+MZz2lwkptLPsyoY7Ptx3Wr1Zo47mXtug et8n2SUADCmNjajL38Mbb/BkZBMl0a54UOy+9XGKzASer6uUmHZy0bDG/DUim8iJaZlE aK7CTL/h8EkZUb3tnEmO9HbxrSQgkGdQmpLgOAeoI2MfWjNRxSc9u4d57B1vi5vxE0u2 8jCSzsVIj9x+ChEVSqgs1sdiRCEIzqLtyzBW4wm5VxuwpLGXv2dH5uf3GffLewz2peyf g6gQ== 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; bh=fsgKsNrhBNorOtejxIyfgaXrHKR6wvWSQsI+3B9vqXc=; b=WUtNm083ADbIlfM90CIHtd5wdSbwSu8mF5yuMrIknysO2WaLyaop9ua4noNFvoj1pv KkfAsg7goFGxjUSUimBg7aC5XX/QgBdmXbBsI4azLGfu3dpmP9ti+OGSY/dg7zUyXdVi HM5fD/bOnqhU9b9smXI3fv246X+4nL2sxevhdb33eBqeWiZOUH6tpq6QZ+pw06G0AWx7 HQOYMNGfkesLZifey2fFx3bcb4uYmhnsPa1BR3KH4DmE2TWtpza6Ox1ZkqOAkbZ+98HH apM2368Ydyd1dl7gvMDTBv+NkyE+zYUy4s8qIA6fI06CZ79GLmIezs6zOlWypDBKZTpW NJ6g== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d140si12419016qkg.214.2021.11.22.00.25.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Nov 2021 00:25:41 -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; 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" Received: from localhost ([::1]:45530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mp4dx-0001cw-Gv for patch@linaro.org; Mon, 22 Nov 2021 03:25:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mp4bf-0001X0-7o for qemu-devel@nongnu.org; Mon, 22 Nov 2021 03:23:22 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:47439) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mp4bd-00035B-9b for qemu-devel@nongnu.org; Mon, 22 Nov 2021 03:23:19 -0500 Received: from quad ([82.142.2.234]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MsI8Y-1mUnfO2ePi-00tgid; Mon, 22 Nov 2021 09:23:12 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 2/5] linux-user: Always use flexible arrays for dirent d_name Date: Mon, 22 Nov 2021 09:23:07 +0100 Message-Id: <20211122082310.377809-3-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211122082310.377809-1-laurent@vivier.eu> References: <20211122082310.377809-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:5LpdvuPJWcOtcrY42LZkbzOsBSbBZDVTzI/2rMSSjBy4r8Lv3gW 4rZ3A8RzjGrDX1JB4WtNDu/IFUPjIwhbRucW8aprT0U6rkfxzIsSX3iIspv2qNc/lupGmb9 ZSwtM94pCYcQ/eZxr6mcvpdmE2L8NXUnrvFKpaa0jFsZIZZ9FS0ENzCzvakdBMqimW4Y1+P w6vKyZBeKDvRueeLa/kUw== X-UI-Out-Filterresults: notjunk:1;V03:K0:CP6ehPMzv1Q=:KcBQW7QM3/9e3+7nK50l8e pPan1fnD9/+3WqS4AoNixmwZ946C/BZcLNyoVHaHu9IHIeuATOpN0fxg4c9nMway7sufq6Jp8 rmr0vIlFltY0EG/U7X2fa/XhUCJf1OskvekArFLrY1J9MNQnsH8h9kmELy8OU7iEsrOTPI589 6dUoc555pjMVSG/T7TwxnEU/8vQEvrY9D3XEYg3ivRiV51bqNR0CzXUlf9aRX2XsuyJ4DrXtO rgHq3DEkHq64DVXEygFtB4RhK1U2wANG2kIylB9VuxnTh8ymKsbfot9YDY2U9i+k+LuiDxZ+5 JmTYjo+IRiGTTwbRUzim5kh4ZUbiKD9eptLhZl1lPnBENzKK84+Uso0Xejq9coaPV1Tq1bsM0 l40c/r+55ESY/vUJrPVcxcWDUdfruIrlAKq8UvHkusqsrYPKHmQ0W/A6TDjZcW4RoTJG5+o0j ZmLfNYkt1g0KY5u/GF2jTDLs0WE+qd5h+QLAd8SsGVftjyIXPsW9t5nDSi8NObRQCbRgXYgMm 3p2goHYWrmFQ2AjdAJ/nvdW+Rpj2hZKVX0bndWkZ740Scgf1F/4nWIf4CiEkUjN2/E+lQsA7l a7TKDXLkFKW60V5eEIoiaYSy0WT22YWFFFqMK6wmiBPICrsFjUvhfAL+huOhsZOPAUiIddmsN 6Xww1PlqlPfg5XxWq6cjJObeL4iYQP19TY2WjzZwLCyJ6Im4Huag676qojpq2CxICjpA= Received-SPF: none client-ip=212.227.126.130; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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: , Cc: Richard Henderson , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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é Message-Id: <20211114103539.298686-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 6 ++++-- linux-user/syscall_defs.h | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a2f605dec4ca..499415ad81b8 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 diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index a5ce487dcc38..98b09ee6d656 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 { From patchwork Mon Nov 22 08:23:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 519285 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp6626239imj; Mon, 22 Nov 2021 00:30:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRX8qBpJmnG74lw6rqv0DAzj6Ofi8mu7syjTDBb8/+/3JP6+HgxMoczETOBBaC6iWbdAnl X-Received: by 2002:ab0:6c44:: with SMTP id q4mr53257998uas.72.1637569857329; Mon, 22 Nov 2021 00:30:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637569857; cv=none; d=google.com; s=arc-20160816; b=uPBUZAYHiag7wikbTmybZij7Vp20mTepD1cq4XraEx2LZyY1FMBurp8JuFjGX7OtMX 9wFoNJ0mzaSvkx/opmd3ndL7etqemLrn29j0Bo1tsGVOfxXbhq4Gn+8PLHgtnMJWWxc3 ivDmUOZfgWwAG+FbTqqFdd5gvFruenvgepwvFqKpQ2MN9yzgiTVYZ6quCD2NXMUis+5Z XifJv5MPWwpaD9C5roQ8gkCVacRC7+0oo2liCfPvTtj0sg1BEvqId7JiFO5OjhO8t0gX cAFUvJbw/v1viR3JOGEmrarXBRq9vqggx+j6T3Ji5yWFVP8dodQk+p9u4Cvm1/uRcplB XdzQ== 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; bh=7HDn+pC4LYBv2blUraNmbZE4Wfj0jiPS4BigRtcZSwA=; b=XB67WZWvXaUH4zLMd8SYGFE/x2fShZVBQFSLYTyuBu/IdOCXR0J6/3ScKywThquSaf xsaEpKa2Wale/QSFAM+aFFnVYPEubavbj6J/OpsG1/gm8lk7+ZnxOn4ejRCW3x9M+lva gY4W6QM2MSNpuLX/66BE1vcdp/tnT0Cn7I4TugowGW577uZJKv1IEmfL7BwPUCAeN1QO r5HzWMI5VFcTFpCuBOwdaMKAVtMjjgf4VptSwcaXVE9FIOaQxqawVXo3/+P4+HanfZoA EBJsGQLl1gnXMVYh4Txhkdb9h9CCa9hxyidpmQ8+LfT19Pfu+aXVQwV/6cwkI05uq3kH UW6w== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a3si17268230vkb.85.2021.11.22.00.30.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Nov 2021 00:30:57 -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; 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" Received: from localhost ([::1]:59070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mp4j2-0002QE-Ou for patch@linaro.org; Mon, 22 Nov 2021 03:30:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mp4bp-0001bt-3b for qemu-devel@nongnu.org; Mon, 22 Nov 2021 03:23:37 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:60065) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mp4bj-000387-EN for qemu-devel@nongnu.org; Mon, 22 Nov 2021 03:23:28 -0500 Received: from quad ([82.142.2.234]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MfYgC-1m9PC50Osa-00g1kL; Mon, 22 Nov 2021 09:23:13 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 3/5] linux-user: Fix member types of target_dirent64 Date: Mon, 22 Nov 2021 09:23:08 +0100 Message-Id: <20211122082310.377809-4-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211122082310.377809-1-laurent@vivier.eu> References: <20211122082310.377809-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:V8SCLv3shdtwPoBM8doLJzITV7wB1dalB7sfrFHL9Jsu4zwveix Jp9UCYTiEpwPBuBjMq1rpzuWrwufzJ7Ly/6Bx0tL9rOuiOYu1Wr8JDasHTmoaJFiuNGeCDy xW08tV0jrWFM01UZOKYw86kthvFtZo/bR6jQdm6k3GbwCJ2nXLY2Ahv9DYSCuWyjg/zI7SL UXkXATo2Vzj/KP/v/4HeA== X-UI-Out-Filterresults: notjunk:1;V03:K0:LznGhAElsyA=:U5n/s0gz/e19U6uwyWL+pG quXHKIKe7Hj/3MjxSb5o32UNEeafUUZC896YkuGj2pQbaOAaHltM+KVTZvflQuxC1UWhNALGz gAjK8cMIUTtmBPj6sPqGyuUONwBnuewv4jzZ59DjHy8LB5Sidw03fyKyoWWANcNw+dBdCmiM8 SIHKzE3wcv6KVcwJ+dyyUU4ShltGRh8UOFiOyY8vH+lgErXHQYTQnoBeMADAbnR8r7KnNs9c/ DV1g62FRn7i8u485MEZ1K6IZSsr4INi66a+LGVaOqVfsCt2oNZJG1l3sPjNK1yezo+KMgG1HS qRXLjD6QxHONPZPbwzTDHtZb2OnuBkjcAWG7GcyKlym1UvI/wjJrUCgdLl5dYPl7Vzg7Nvg9v 3eomqd2gNuF+aB2YFjHwsXMESVkaoPaJ+scAqbm1v02ztkTdbY+4XgoHMT4jImDH8wEUeh57H diThL+Owi29NXodK0ZM63gkU5TXEO4DxygfV9MpKjIr9UkWP3ds0uXEph0AXNjrIsZfryA20U TpNY1BuwDYnCdGRqFlqyZ1ie7T/Zz7qUEe+vfaDQlbF3f+CAgoANNgmg4dlgfboCNqa/mUiOb DVIXFWroTmjUSFnQ24vUYNEVOtUy+mQwqt1WHj03VC3xzHe6N16Zzh1ilNxIWL01EvDF3m/hm qB7kCKQGyR1LLGTrq4Nia6l7Cr4TXORXdccoP0sUXKOz5z2P5ObdKooQ4lh6aeBBtZiY= Received-SPF: none client-ip=212.227.126.131; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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: , Cc: Richard Henderson , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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é Message-Id: <20211114103539.298686-4-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- 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 98b09ee6d656..41aaafbac12c 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 Mon Nov 22 08:23:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 519284 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp6623945imj; Mon, 22 Nov 2021 00:28:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrYMkCRY4AMGmi0pZkhvjNIORYo5oSbeomCe4vrwgTTCUgb2JeRb3pt+OtlYKYp5CASBjx X-Received: by 2002:a05:622a:1010:: with SMTP id d16mr28732781qte.61.1637569715558; Mon, 22 Nov 2021 00:28:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637569715; cv=none; d=google.com; s=arc-20160816; b=AFA8Kbq2yveWrpP4D5VySJka+1vfLDHcbqxCN5GhvliDX1E2xd9DAkd0gZ3mKiDcfk zqXTyNOrAQdUHmFRKx3P1DwWl2U8tXeRM51UOY1BxVPb9UwPktaup3+8SrZaHIS/ApE3 IIkH59wRBYoNEISUcTQjFMq/6YS1LlrjJG1OZgbzsld1OjWvAJNwON0UvhKJl4IiV0hC 0U3U7d0X3AdEaFFpqlTB7h0aPsJTjO9hgQ+B2t7i/a1o/SvK52s3fhSPiEPWq5Sx/oY4 x+JRZbLASWoijrZzTqRsjTNfs7z+5V3yGDJ+xh5VodC4YtxjuK21/1/BxlJeaeI5DahY naOw== 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; bh=Jd9NV8MyZ/TyjK59/lZrKYDorf0v3lCDVRceOrWmI70=; b=o2f0LtZtllGImhyKS6ugWANBMBsc6WTN7CN2e8ajY19VVfTEN+l7kWfE6wmoE51pBy B2tNzR9Qk7UuRmbvzfmb8BLbNOEVtzqUBi6z7o5lefdF1wDpGYhz4bKPH1el10q1GAUQ sr8XIWyK7oQEly6hxhukByR++BsbzgEaVnmiECb0s+GgqYpITc4bm3OvFuERrhoZBNxf 1eu06OH5MxVpLnbCRMP8nQBa3G2byt7sWitOS0wk++RnbczS4ynAQWQ6AIO8G/xEfkTS wYmLYQuDeVNw1YX1vQIrP50nadISlt2MUQEFKHiZRIff+Os/ss/OBiVn8jEFWMjdJrR8 d9YA== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a17si16343175qtx.206.2021.11.22.00.28.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Nov 2021 00:28:35 -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; 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" Received: from localhost ([::1]:52572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mp4gl-0006W7-4n for patch@linaro.org; Mon, 22 Nov 2021 03:28:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mp4br-0001bw-9l for qemu-devel@nongnu.org; Mon, 22 Nov 2021 03:23:37 -0500 Received: from mout.kundenserver.de ([212.227.126.133]:39403) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mp4bn-00038X-4Y for qemu-devel@nongnu.org; Mon, 22 Nov 2021 03:23:31 -0500 Received: from quad ([82.142.2.234]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MAOa3-1mut5e2LWd-00Bvqw; Mon, 22 Nov 2021 09:23:13 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 4/5] linux-user: Rewrite do_getdents, do_getdents64 Date: Mon, 22 Nov 2021 09:23:09 +0100 Message-Id: <20211122082310.377809-5-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211122082310.377809-1-laurent@vivier.eu> References: <20211122082310.377809-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:U3chgT1UfwZszQ+kWmHGEleRdvMdH3UgFwxO2XQyVt3l5ff5pbt 7CPGFva6H8Cd16oohgUdQ2jpRoQBzxJ4tVYNGKxLuJJr2uVPwpe+MMolRWewBETV2bVqz+T ArHd5YXqrtlN5bx2IhFZstuyzKDC6TOKQ1V9KoVcCc1+WOVPx0bYiULnG+dxmkvKrCELSNn e46YOb0L38sIkyx9cGd8Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:DBzNlpGLRxU=:Ev1wNTVoMFnk5XYhUFsnjG HdLcjqIZClJgJXcw/Fu9nVjRSC8wLlXD7axD6zkwoHxaKpsUL1Iti9FncTBe54WbbUM6WG2uY IfOyZLzD6B+rXBKrLQZFpXwBkQCdiY36oE89I2Jc1TyFHohKOfqscKu/sHBMdPth5B8TzVSA1 QOoDPBu+Yg72i8VBV7QdwmKOUwu3mije3MIWpJYlf+UjpzgXwkJGf5raGSWH5X8bNIgpt7/zW B43+0kC9iRhI/tpKuc9BfnIAx7K+ukoguF4ntjympMUB6/Sn+tVkdG4CDATaUmg8bNnwyySPu QtyyyRCGna6RNa7sSVvq/ysOTKj0Z4VBGZlGy2e0iRs/pgrEWSbKpMisoZ6FkQAPDf835ZWL8 8yYVN5kpJLUBfnSDd3cJXhlefpyUgvuCP3SeC1sJ8h1SNcP5cRNo2ghVYiAI8tNsEaB0wGMGT ff5mhnu8BE5dzoD0W/j9GtR3VnwVm1zW8n/AxaNNPVb8VWnV0TgYpGh17oIXTmyMqR1tTPeEV mu8svibYRGFyYSIQYTf3C/a00uqylhNZWimolEfzeeF9YLQ+izJuozDCwPl/UWQCoSpXhbrmR iQeZO+Hb5j2vxZehRNLeug5Isg2Sps+hx6lz7bdb1jXlV6qUy77qdlz+t8N2loF+MZRZBpuIz IPRlHYD/jGVONaQKznHo4zjozmYhWI60dCpizLp1ehan2r8DApQz7lb/XEQDOE1xpSTk= Received-SPF: none client-ip=212.227.126.133; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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: , Cc: Richard Henderson , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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é Message-Id: <20211114103539.298686-5-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 261 ++++++++++++++++++++----------------------- 1 file changed, 122 insertions(+), 139 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 499415ad81b8..f1cfcc810486 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; + + hdirp = g_try_malloc(count); + if (!hdirp) { + return -TARGET_ENOMEM; + } #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; + hlen = sys_getdents(dirfd, hdirp, count); +#else + hlen = sys_getdents64(dirfd, hdirp, count); +#endif - dirp = g_try_malloc(count); - if (!dirp) { - return -TARGET_ENOMEM; + hlen = get_errno(hlen); + if (is_error(hlen)) { + return hlen; } - 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) { + 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) { - 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 + + for (hoff = toff = 0; hoff < hlen; hoff += hreclen, toff += treclen) { +#ifdef EMULATE_GETDENTS_WITH_GETDENTS + struct linux_dirent *hde = hdirp + hoff; #else - /* Implement getdents in terms of getdents64 */ - struct linux_dirent64 *dirp; - abi_long count = arg3; + struct linux_dirent64 *hde = hdirp + hoff; +#endif + struct target_dirent *tde = tdirp + toff; + int namelen; + uint8_t type; - 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; + 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)); - 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); + if (toff + treclen > count) { /* - * The target_dirent type is in what was formerly a padding - * byte at the end of the structure: + * 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. */ - *(((char *)tde) + treclen - 1) = type; - - de = (struct linux_dirent64 *)((char *)de + reclen); - tde = (struct target_dirent *)((char *)tde + treclen); - len -= reclen; - tlen += treclen; + if (toff == 0) { + toff = -TARGET_EINVAL; /* result buffer is too small */ + break; + } + /* + * Return what we have, resetting the file pointer to the + * location of the first record not returned. + */ + 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; + + hdirp = g_try_malloc(count); + if (!hdirp) { + return -TARGET_ENOMEM; + } - dirp = lock_user(VERIFY_WRITE, arg2, count, 0); - if (!dirp) { + 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 */