public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH V5 1/2] Initialize bnd register before performing inferior calls.
@ 2016-03-18 14:16 Walfred Tedeschi
  2016-04-26 14:08 ` Yao Qi
  0 siblings, 1 reply; 2+ messages in thread
From: Walfred Tedeschi @ 2016-03-18 14:16 UTC (permalink / raw)
  To: palves, brobecker; +Cc: gdb-patches, Walfred Tedeschi

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:

	* i387-tdep.h (i387_reset_bnd_regs): New.
	* i387-tdep.c (i387_reset_bnd_regs): New.
	* i386-tdep.c (i386_push_dummy_call): Call i387_reset_bnd_regs.
	* amd64-tdep (amd64_push_dummy_call): Call i387_reset_bnd_regs.

---
 gdb/amd64-tdep.c |  5 +++++
 gdb/i386-tdep.c  |  5 +++++
 gdb/i387-tdep.c  | 16 ++++++++++++++++
 gdb/i387-tdep.h  |  6 ++++++
 4 files changed, 32 insertions(+)

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index a62efde..c1aca26 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -997,6 +997,11 @@ amd64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   enum bfd_endian byte_order = gdbarch_byte_order (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.  */
+  i387_reset_bnd_regs (gdbarch, regcache);
+
   /* 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..e8d41a3 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2665,6 +2665,11 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   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.  */
+  i387_reset_bnd_regs (gdbarch, regcache);
+
   /* 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.  */
diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
index f7a3b55..9bb3177 100644
--- a/gdb/i387-tdep.c
+++ b/gdb/i387-tdep.c
@@ -1772,3 +1772,19 @@ i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
   regcache_raw_write_unsigned (regcache, I387_FTAG_REGNUM (tdep), 0x3fff);
 
 }
+
+void
+i387_reset_bnd_regs (struct gdbarch *gdbarch, struct regcache *regcache)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  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);
+    }
+}
diff --git a/gdb/i387-tdep.h b/gdb/i387-tdep.h
index b4dc2b7..3ac4b4d 100644
--- a/gdb/i387-tdep.h
+++ b/gdb/i387-tdep.h
@@ -156,4 +156,10 @@ extern void i387_collect_xsave (const struct regcache *regcache,
 extern void i387_return_value (struct gdbarch *gdbarch,
 			       struct regcache *regcache);
 
+/* Set all bnd registers to the INIT state. INIT state means
+   all memory range can be accessed.  */
+
+extern void i387_reset_bnd_regs (struct gdbarch *gdbarch,
+			         struct regcache *regcache);
+
 #endif /* i387-tdep.h */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH V5 1/2] Initialize bnd register before performing inferior calls.
  2016-03-18 14:16 [PATCH V5 1/2] Initialize bnd register before performing inferior calls Walfred Tedeschi
@ 2016-04-26 14:08 ` Yao Qi
  0 siblings, 0 replies; 2+ messages in thread
From: Yao Qi @ 2016-04-26 14:08 UTC (permalink / raw)
  To: Walfred Tedeschi; +Cc: palves, brobecker, gdb-patches

Walfred Tedeschi <walfred.tedeschi@intel.com> writes:

> BND registers should be initialized before performing an inferior call
> to avoid undesired bound violations.

What are the undesired bound violations?  Do have an example?

Resetting BND registers in the inferior call isn't right to me, the BND
setting isn't in effect in the inferior call.  If the function can
trigger bound violations, it is expected that it still can trigger
violations in the inferior call.

-- 
yao (齐尧)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-04-26 14:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-18 14:16 [PATCH V5 1/2] Initialize bnd register before performing inferior calls Walfred Tedeschi
2016-04-26 14:08 ` Yao Qi

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).