From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4817 invoked by alias); 2 Mar 2016 16:21:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 4707 invoked by uid 89); 2 Mar 2016 16:21:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=walfred.tedeschi@intel.com, bnd, walfredtedeschiintelcom, U*walfred.tedeschi X-HELO: mga11.intel.com Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Mar 2016 16:21:41 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 02 Mar 2016 08:21:40 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 02 Mar 2016 08:21:39 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u22GLc0h024362; Wed, 2 Mar 2016 16:21:38 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id u22GLbj8001867; Wed, 2 Mar 2016 17:21:37 +0100 Received: (from wtedesch@localhost) by ulvlx001.iul.intel.com with œ id u22GLbp2001863; Wed, 2 Mar 2016 17:21:37 +0100 From: Walfred Tedeschi To: palves@redhat.com, eliz@gnu.org, brobecker@adacore.com Cc: gdb-patches@sourceware.org, Walfred Tedeschi Subject: [PATCH V4 1/2] Initialize bnd register before performing inferior calls. Date: Wed, 02 Mar 2016 16:21:00 -0000 Message-Id: <1456935689-1820-2-git-send-email-walfred.tedeschi@intel.com> In-Reply-To: <1456935689-1820-1-git-send-email-walfred.tedeschi@intel.com> References: <1456935689-1820-1-git-send-email-walfred.tedeschi@intel.com> X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg00036.txt.bz2 BND registers should be initialized before performing an inferior call to avoid undesired bound violations. 2016-02-03 Walfred Tedeschi 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. */ -- 2.1.4