From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 46047 invoked by alias); 16 Mar 2016 14:57:48 -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 45902 invoked by uid 89); 16 Mar 2016 14:57:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=violations X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 16 Mar 2016 14:57:37 +0000 Received: from svr-orw-fem-04.mgc.mentorg.com ([147.34.97.41]) by relay1.mentorg.com with esmtp id 1agCtC-0002uE-3l from Luis_Gustavo@mentor.com ; Wed, 16 Mar 2016 07:57:34 -0700 Received: from [172.30.3.160] (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.3.224.2; Wed, 16 Mar 2016 07:57:33 -0700 Subject: Re: [PATCH V4 1/2] Initialize bnd register before performing inferior calls. References: <1456935689-1820-1-git-send-email-walfred.tedeschi@intel.com> <1456935689-1820-2-git-send-email-walfred.tedeschi@intel.com> To: Walfred Tedeschi , , , CC: Reply-To: Luis Machado From: Luis Machado Message-ID: <56E97459.4090803@codesourcery.com> Date: Wed, 16 Mar 2016 14:57:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1456935689-1820-2-git-send-email-walfred.tedeschi@intel.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg00255.txt.bz2 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 > > 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.