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.hender...@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é <f4...@amsat.org>