This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2 1/5] mips: Do not malloc on getdents64 fallback
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 8 Oct 2019 16:52:36 -0300
- Subject: Re: [PATCH v2 1/5] mips: Do not malloc on getdents64 fallback
- References: <20190731183136.21545-1-adhemerval.zanella@linaro.org> <87k1av6kuh.fsf@oldenburg2.str.redhat.com> <49dc9440-d9a5-112f-9ec6-b62f4c0bcdf2@linaro.org> <87zhjmvoow.fsf@oldenburg2.str.redhat.com> <30395e41-d6c9-4fce-ca7a-933d55900fc7@linaro.org> <87imp0flym.fsf@oldenburg2.str.redhat.com> <703d65b6-82bd-f557-7257-0fdd9cedb2f4@linaro.org> <874l0j9iit.fsf@oldenburg2.str.redhat.com>
On 08/10/2019 15:52, Florian Weimer wrote:
> * Adhemerval Zanella:
>
>> +#define DP_MEMBER(src, type, member) \
>> + (__typeof__((type){0}.member) *) \
>> + memcpy (&((__typeof__((type){0}.member)){0}), \
>> + ((char *)(src) + offsetof (type, member)), \
>> + sizeof ((type){0}.member))
>
> Please add a comment that this is used to avoid an aliasing violation.
Ack.
>
>> + memcpy (((char *)(dp) + offsetof (struct dirent64, d_ino)),
>> + DP_MEMBER (kdp, struct kernel_dirent, d_ino),
>> + sizeof ((struct dirent64){0}.d_ino));
>> + memcpy (((char *)(dp) + offsetof (struct dirent64, d_off)),
>> + DP_MEMBER (kdp, struct kernel_dirent, d_ino),
>> + sizeof ((struct dirent64){0}.d_ino));
>> + memcpy (&last_offset,
>> + DP_MEMBER (kdp, struct kernel_dirent, d_off),
>> + sizeof (last_offset));
>
> I think you should be able to use:
>
> last_offset = *DP_MEMBER (kdp, struct kernel_dirent, d_off);
>
> last_offset has the correct type.
Ack.
>
>> + memcpy (DP_MEMBER (dp, struct dirent64, d_reclen), &new_reclen,
>> + sizeof ((struct dirent64){0}.d_reclen));
>
> That looks wrong. DP_MEMBER (dp, struct dirent64, d_reclen) is a
> temporary object, so the outer memcpy is dead.
Sigh, indeed. I changed to:
memcpy (((char *)(dp) + offsetof (struct dirent64, d_reclen)),
&new_reclen, sizeof ((struct dirent64){0}.d_reclen));
>
> Thanks,
> Florian
>
I hope I got this right this time...