From: Luis Machado <lgustavo@codesourcery.com>
To: Walfred Tedeschi <walfred.tedeschi@intel.com>,
<palves@redhat.com>, <eliz@gnu.org>, <brobecker@adacore.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH V4 1/2] Initialize bnd register before performing inferior calls.
Date: Wed, 16 Mar 2016 14:57:00 -0000 [thread overview]
Message-ID: <56E97459.4090803@codesourcery.com> (raw)
In-Reply-To: <1456935689-1820-2-git-send-email-walfred.tedeschi@intel.com>
On 03/02/2016 01:21 PM, Walfred Tedeschi wrote:
> BND registers should be initialized before performing an inferior call
> to avoid undesired bound violations.
>
> 2016-02-03 Walfred Tedeschi <walfred.tedeschi@intel.com>
>
> gdb/ChangeLog:
>
> * i386-tdep.c (i386_push_dummy_call): Initialize bnd registers.
> * amd64-tdep (amd64_push_dummy_call): Initialize bnd registers.
>
> ---
> gdb/amd64-tdep.c | 15 +++++++++++++++
> gdb/i386-tdep.c | 15 +++++++++++++++
> 2 files changed, 30 insertions(+)
>
> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
> index a62efde..0e4e89b 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -995,8 +995,23 @@ amd64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
> int struct_return, CORE_ADDR struct_addr)
> {
> enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
> gdb_byte buf[8];
>
> + /* When MPX is enabled, all bnd registers have to be initialized
> + before the call. This avoids an undesired bound violation
> + during the function's execution. */
> +
> + if (I387_BND0R_REGNUM (tdep) > 0)
> + {
> + gdb_byte bnd_buf[16];
> + int i;
> +
> + memset (bnd_buf, 0, 16);
> + for (i = 0; i < I387_BND0R_REGNUM (tdep); i++)
> + regcache_raw_write (regcache, I387_BND0R_REGNUM (tdep) + i, bnd_buf);
> + }
> +
> /* Pass arguments. */
> sp = amd64_push_arguments (regcache, nargs, args, sp, struct_return);
>
> diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
> index 4c66edf..8c3576c 100644
> --- a/gdb/i386-tdep.c
> +++ b/gdb/i386-tdep.c
> @@ -2660,11 +2660,26 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
> CORE_ADDR struct_addr)
> {
> enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
> gdb_byte buf[4];
> int i;
> int write_pass;
> int args_space = 0;
>
> + /* When MPX is enabled, all bnd registers have to be initialized
> + before the call. This avoids an undesired bound violation
> + during the function's execution. */
> +
> + if (I387_BND0R_REGNUM (tdep) > 0)
> + {
> + gdb_byte bnd_buf[16];
> + int i;
> +
> + memset (bnd_buf, 0, 16);
> + for (i = 0; i < I387_BND0R_REGNUM (tdep); i++)
> + regcache_raw_write (regcache, I387_BND0R_REGNUM (tdep) + i, bnd_buf);
> + }
> +
> /* Determine the total space required for arguments and struct
> return address in a first pass (allowing for 16-byte-aligned
> arguments), then push arguments in a second pass. */
>
Not sure if it was suggested previously in earlier versions of this
series (i could not find it), but wouldn't it make sense to have that
code moved to a new function in, say, i387-tdep.c? Then we wouldn't need
to duplicate the code as above.
next prev parent reply other threads:[~2016-03-16 14:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-02 16:21 [PATCH V4 0/2] BND register initialization Walfred Tedeschi
2016-03-02 16:21 ` [PATCH V4 1/2] Initialize bnd register before performing inferior calls Walfred Tedeschi
2016-03-16 14:57 ` Luis Machado [this message]
2016-03-02 16:21 ` [PATCH V4 2/2] Add mpx-bnd-init-on-return set/show command for " Walfred Tedeschi
2016-03-02 16:35 ` Eli Zaretskii
2016-03-03 11:04 ` Walfred Tedeschi
2016-03-03 20:34 ` Eli Zaretskii
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=56E97459.4090803@codesourcery.com \
--to=lgustavo@codesourcery.com \
--cc=brobecker@adacore.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=walfred.tedeschi@intel.com \
/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