This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: [PATCH] libdwfl: Use process_vm_readv when available.
On Wed, Mar 21, 2018 at 02:28:48AM +0300, Dmitry V. Levin wrote:
> On Sun, Mar 18, 2018 at 01:43:23AM +0100, Mark Wielaard wrote:
> > + /* Let the ptrace fallback deal with the corner case of the address
> > + possibly crossing a page boundery. */
> > + if ((addr & ((Dwarf_Addr)__LIBDWFL_REMOTE_MEM_CACHE_SIZE - 1))
> > + > (Dwarf_Addr)__LIBDWFL_REMOTE_MEM_CACHE_SIZE - sizeof (unsigned long))
>
> It looks odd that the variable that is going to be assigned has type
> Dwarf_Word, while the size being checked has type unsigned long.
> Shouldn't it be sizeof(*result) instead?
>
> > + d = &mem_cache->buf[addr - mem_cache->addr];
> > + *result = *(unsigned long *) d;
>
> Likewise, shouldn't it be memcpy(result, d, sizeof(*result)) instead?
That is indeed not immediately clear. I'll add some documentation.
Although the functions do use Dwarf_Word (which is always 64bits)
they actually return the result of an unsigned long/address. This
is true for both the pid based and core based memory read functions.
I am not completely sure if this was originally deliberate, or if
this was the accidental result of the ptrace interface returning a
long (target word) for PTRACE_PEEKDATA.
Thanks for reviewing.
Cheers,
Mark