From patchwork Sun Jun 10 03:01:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138149 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2602866lji; Sat, 9 Jun 2018 20:56:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKISCBcjLlC56sOWZ4ClLfH/RR2g1iotPdl5rQ0lBJMtIIA9hqWyJC6+iCKBmeAW2DruzegI X-Received: by 2002:a0c:9588:: with SMTP id s8-v6mr11091166qvs.23.1528602968319; Sat, 09 Jun 2018 20:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528602968; cv=none; d=google.com; s=arc-20160816; b=dIj7cJTrQfNmeFqRwMwoqBxo44HuoqQm8OWfahi5jR+szs0yBZm3cSzcbvF4TfgjHl sz50lniCxL7sBFs82FyrNeo+hashy2wjPOqcXG7cja+8477zu3AHg0RHBxXQTEoeojfZ qyj/a0A0/+9Ye1knG5FJD1n4HtctQ1e2Cn7IEl32T/Prhy2xaRAFOuq/NLEsOMNAagiN Pj/m3Ehh6Mt3zAbtCaAi9Dq0R6YVc5KM/lOlqJttYniBwGMaRqj8D7xH6AiGcKTp77Qi CExRVsfIDEAeVGAZQngP6eg8vktaKmObQmEuySogoWhqn5/nCJmLAp/fsWqYXoRZQd9R ZiIw== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Lzw/JRx37tqXQbLnj4evXXdQpDvmQGzkx2xaVa/H3NM=; b=0z/gPSqIs2BxkVjfLeaSEg8hZZg+MJrWmx0oD1CutsNh4g3ZowhOI7P+0iJsk0RNwC bhqJmsBQT7Hino0prpFtfq6fDNCRDnzXR7rN+y/CBQeoTjs11emOaDeOcOmDe/z/5f9Z 3ErRqqw9XjutDvl+YC2mYmLubh8oxkQ7bAsL85WsysQm5LEPTthpZSjY9c5J4/pFei9M 6H/QWa1CEQlprlQnLOCM8bFlLj+ydSvLXrQUoOTj5Ti5zDrl09QOodo9QDsUkNpfON8V fzrdEB9tm6w+8nFEWHs0Hua/NYAEbJ2pJ+Jq38ATJOjzB45LLqjOe5cp/Dax+v/2KpaR PiVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Vyea4o1y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u6-v6si892278qkc.122.2018.06.09.20.56.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:56:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Vyea4o1y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRrSZ-0001Cx-Nq for patch@linaro.org; Sat, 09 Jun 2018 23:56:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqel-0003QH-LY for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqej-0003rY-Sm for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:39 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:37249) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqej-0003rN-KT for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:04:37 -0400 Received: by mail-pf0-x244.google.com with SMTP id y5-v6so7584032pfn.4 for ; Sat, 09 Jun 2018 20:04:37 -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; bh=Lzw/JRx37tqXQbLnj4evXXdQpDvmQGzkx2xaVa/H3NM=; b=Vyea4o1yPOqwOjzogeA4vwjTkdwUeA9q/zTrjyGjTMqdKnmUR9khyZtLOVNuNf/8wV 69CCdXehnnYj5saXsUQhCjREEvWFVpmfLp0NhpQzcFWrk94KOCeqNdMShXfce7a3xLAs 1Z332eXb8aFe/L6krtZ8F3Qxis3OvO6PoKXhA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Lzw/JRx37tqXQbLnj4evXXdQpDvmQGzkx2xaVa/H3NM=; b=shvQW+sT6YMvCcJbgu0F0uAP1U2jeni1qyTOd/fneVov8nXXWdFQWVGU6w2IdfEby8 +/zcBl0yiBy04ANpJprtXwW0vzLsXKBmaFEy31+eiQTSZI82IUATsBaW6CUZc//QEkg7 0fgQh46xn/zcgARfU1gTZIsCDudIu+C9rVChN+idRxkParupmBCH6IaGgULbpXjn6jNy AqWpe1yB7uS31wI+hHMQIwewAyT8tHjUIZczxmmoZjtMczutsayjN+row8UTfTTgeDU6 fF2l0U33lJ8UPe6AiuyoB663wtO3MiJXn8ReuI73muOEzE0/DLoO6Xts3CVDquIZTmpc zwcw== X-Gm-Message-State: APt69E01L2JgZjuQSeWTDcQQaDw5IOLmqDrCgLcY5GUkXdh5/67KGJeG tLvY2Y3OeqBfVcIdLBxgBbkmhM7Su1w= X-Received: by 2002:a62:67c5:: with SMTP id t66-v6mr12287467pfj.20.1528599876453; Sat, 09 Jun 2018 20:04:36 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id y17-v6sm31712718pfe.33.2018.06.09.20.04.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:04:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:32 -1000 Message-Id: <20180610030220.3777-61-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v2 060/108] linux-user: Split out getdents, getdents64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" Signed-off-by: Richard Henderson --- linux-user/syscall.c | 329 ++++++++++++++++++++++--------------------- 1 file changed, 170 insertions(+), 159 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f5f21658a8..600702ea3e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8121,6 +8121,170 @@ IMPL(futimesat) } #endif +#ifdef TARGET_NR_getdents +IMPL(getdents) +{ + abi_long 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 = dirp; + int len = ret; + int reclen; + + 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 = dirp; + struct target_dirent *tde = (struct target_dirent *)dirp; + int len = ret; + int tlen = 0; + + 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 + +#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) +IMPL(getdents64) +{ + struct linux_dirent64 *dirp; + abi_long count = arg3; + abi_long 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 = dirp; + int len = ret; + + while (len > 0) { + int 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 */ + IMPL(getitimer) { struct itimerval value; @@ -10485,165 +10649,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { -#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; -#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; -#endif /* TARGET_NR_getdents64 */ #if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll) # ifdef TARGET_NR_poll case TARGET_NR_poll: @@ -12939,6 +12944,12 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(ftruncate); #ifdef TARGET_NR_futimesat SYSCALL(futimesat); +#endif +#ifdef TARGET_NR_getdents + SYSCALL(getdents); +#endif +#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) + SYSCALL(getdents64); #endif SYSCALL(getitimer); #ifdef TARGET_NR_getpeername