From: "Dmitry V. Levin" <ldv@altlinux.org>
To: elfutils-devel@sourceware.org
Subject: Re: [PATCH] libdwfl: Use process_vm_readv when available.
Date: Tue, 20 Mar 2018 23:28:00 -0000 [thread overview]
Message-ID: <20180320232848.GB12453@altlinux.org> (raw)
In-Reply-To: <20180318004323.21340-1-mark@klomp.org>
[-- Attachment #1: Type: text/plain, Size: 1575 bytes --]
On Sun, Mar 18, 2018 at 01:43:23AM +0100, Mark Wielaard wrote:
[...]
> @@ -115,12 +116,80 @@ __libdwfl_ptrace_attach (pid_t tid, bool *tid_was_stoppedp)
> return true;
> }
>
> +#ifdef HAVE_PROCESS_VM_READV
> +static bool
> +read_cached_memory (struct __libdwfl_pid_arg *pid_arg,
> + Dwarf_Addr addr, Dwarf_Word *result)
> +{
> + /* 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?
> + return false;
> +
> + struct __libdwfl_remote_mem_cache *mem_cache = pid_arg->mem_cache;
> + if (mem_cache == NULL)
> + {
> + size_t mem_cache_size = sizeof (struct __libdwfl_remote_mem_cache);
> + mem_cache = (struct __libdwfl_remote_mem_cache *) malloc (mem_cache_size);
> + if (mem_cache == NULL)
> + return false;
> +
> + mem_cache->addr = 0;
> + mem_cache->len = 0;
> + pid_arg->mem_cache = mem_cache;
> + }
> +
> + unsigned char *d;
> + if (addr >= mem_cache->addr && addr - mem_cache->addr < mem_cache->len)
> + {
> + d = &mem_cache->buf[addr - mem_cache->addr];
> + *result = *(unsigned long *) d;
Likewise, shouldn't it be memcpy(result, d, sizeof(*result)) instead?
--
ldv
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
next prev parent reply other threads:[~2018-03-20 23:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-18 0:43 Mark Wielaard
2018-03-20 22:32 ` Mark Wielaard
2018-03-28 14:33 ` Mark Wielaard
2018-03-28 21:42 ` Dmitry V. Levin
2018-03-20 23:28 ` Dmitry V. Levin [this message]
2018-03-21 0:47 ` Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180320232848.GB12453@altlinux.org \
--to=ldv@altlinux.org \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).