qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 4/4] linux-user: Rewrite do_getdents, do_getdents64


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v2 4/4] linux-user: Rewrite do_getdents, do_getdents64
Date: Sun, 14 Nov 2021 22:18:37 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0

On 11/14/21 11:35, Richard Henderson wrote:
> 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 <richard.henderson@linaro.org>
> ---
>  linux-user/syscall.c | 259 ++++++++++++++++++++-----------------------
>  1 file changed, 121 insertions(+), 138 deletions(-)

> +        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;
>              }
[...]
>              /*
> -             * 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.
>               */
> +            lseek64(dirfd, prev_diroff, SEEK_SET);
> +            break;
>          }

LGTM,
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]