Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intel(R) Memory Protection Extensions (Intel(R) MPX) support.
Summary: The Intel(R) Memory Protection Extensions (Intel(R) MPX) associates pointers to bounds, against which the software can check memory references to prevent out of bound memory access. This patch allows accessing the MPX registers: * bnd0-3: 128-bit registers to hold the bound values, * bndcfgu, bndstatus: 64-bit configuration registers, This patch also adds read/write tests for the MPX registers in the register command tests and adds a new subdirectory for MPX specific tests. Signed-off-by: Valentina Giusti <valentina.giusti@intel.com> Reviewers: labath, granata.enrico, lldb-commits, clayborg Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D24187 llvm-svn: 280668
- Loading branch information
Valentina Giusti
committed
Sep 5, 2016
1 parent
9bd34f9
commit f105abb
Showing
17 changed files
with
501 additions
and
26 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.../packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
LEVEL = ../../../make | ||
|
||
CXX_SOURCES := main.cpp | ||
CXXFLAGS += -mmpx -fcheck-pointer-bounds -fuse-ld=bfd | ||
LDFLAGS += -mmpx -fcheck-pointer-bounds -fuse-ld=bfd | ||
include $(LEVEL)/Makefile.rules |
59 changes: 59 additions & 0 deletions
59
...ython/lldbsuite/test/functionalities/register/intel_xtended_registers/TestMPXRegisters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Test the MPX registers. | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
import os, sys, time | ||
import re | ||
import lldb | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
|
||
class RegisterCommandsTestCase(TestBase): | ||
|
||
mydir = TestBase.compute_mydir(__file__) | ||
|
||
def setUp(self): | ||
TestBase.setUp(self) | ||
self.has_teardown = False | ||
|
||
def tearDown(self): | ||
self.dbg.GetSelectedTarget().GetProcess().Destroy() | ||
TestBase.tearDown(self) | ||
|
||
@skipIfiOSSimulator | ||
@skipIf(compiler="clang") | ||
@expectedFailureAll(oslist=["linux"], compiler="gcc", compiler_version=["<", "5"]) | ||
@skipIf(archs=no_match(['amd64', 'i386', 'x86_64'])) | ||
def test_mpx_registers_with_example_code(self): | ||
"""Test MPX registers with example code.""" | ||
self.build() | ||
self.mpx_registers_with_example_code() | ||
|
||
def mpx_registers_with_example_code(self): | ||
"""Test MPX registers after running example code.""" | ||
self.line = line_number('main.cpp', '// Set a break point here.') | ||
|
||
exe = os.path.join(os.getcwd(), "a.out") | ||
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) | ||
|
||
self.runCmd('settings set target.inline-breakpoint-strategy always') | ||
self.addTearDownHook( | ||
lambda: self.runCmd("settings set target.inline-breakpoint-strategy always")) | ||
|
||
lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1) | ||
self.runCmd("run", RUN_SUCCEEDED) | ||
|
||
self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, | ||
substrs = ["stop reason = breakpoint 1."]) | ||
|
||
self.expect("register read -s 3", | ||
substrs = ['bnd0 = {0x0000000000000010 0xffffffffffffffe6}', | ||
'bnd1 = {0x0000000000000020 0xffffffffffffffd6}', | ||
'bnd2 = {0x0000000000000030 0xffffffffffffffc6}', | ||
'bnd3 = {0x0000000000000040 0xffffffffffffffb6}', | ||
'bndcfgu = {0x01 0x80 0xb5 0x76 0xff 0x7f 0x00 0x00}', | ||
'bndstatus = {0x02 0x80 0xb5 0x76 0xff 0x7f 0x00 0x00}']) |
69 changes: 69 additions & 0 deletions
69
.../packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//===-- main.cpp ------------------------------------------------*- C++ -*-===// | ||
//// | ||
//// The LLVM Compiler Infrastructure | ||
//// | ||
//// This file is distributed under the University of Illinois Open Source | ||
//// License. See LICENSE.TXT for details. | ||
//// | ||
////===----------------------------------------------------------------------===// | ||
// | ||
|
||
#include <cpuid.h> | ||
#include <cstddef> | ||
|
||
int | ||
main(int argc, char const *argv[]) | ||
{ | ||
unsigned int rax, rbx, rcx, rdx; | ||
|
||
// Check if XSAVE is enabled. | ||
if (!__get_cpuid(1, &rax, &rbx, &rcx, &rdx) || (rcx & bit_OSXSAVE) != bit_OSXSAVE) | ||
return -1; | ||
|
||
// Check if MPX is enabled. | ||
if (__get_cpuid_max(0, NULL) > 7) | ||
{ | ||
__cpuid_count(7, 0, rax, rbx, rcx, rdx); | ||
if ((rbx & bit_MPX) != bit_MPX) | ||
return -1; | ||
} | ||
else | ||
return -1; | ||
|
||
// Run MPX test code. | ||
#if defined(__x86_64__) | ||
asm("mov $16, %rax\n\t" | ||
"mov $9, %rdx\n\t" | ||
"bndmk (%rax,%rdx), %bnd0\n\t" | ||
"mov $32, %rax\n\t" | ||
"mov $9, %rdx\n\t" | ||
"bndmk (%rax,%rdx), %bnd1\n\t" | ||
"mov $48, %rax\n\t" | ||
"mov $9, %rdx\n\t" | ||
"bndmk (%rax,%rdx), %bnd2\n\t" | ||
"mov $64, %rax\n\t" | ||
"mov $9, %rdx\n\t" | ||
"bndmk (%rax,%rdx), %bnd3\n\t" | ||
"bndstx %bnd3, (%rax) \n\t" | ||
"nop\n\t"); | ||
#endif | ||
#if defined(__i386__) | ||
asm("mov $16, %eax\n\t" | ||
"mov $9, %edx\n\t" | ||
"bndmk (%eax,%edx), %bnd0\n\t" | ||
"mov $32, %eax\n\t" | ||
"mov $9, %edx\n\t" | ||
"bndmk (%eax,%edx), %bnd1\n\t" | ||
"mov $48, %eax\n\t" | ||
"mov $9, %edx\n\t" | ||
"bndmk (%eax,%edx), %bnd2\n\t" | ||
"mov $64, %eax\n\t" | ||
"mov $9, %edx\n\t" | ||
"bndmk (%eax,%edx), %bnd3\n\t" | ||
"bndstx %bnd3, (%eax)\n\t" | ||
"nop\n\t"); | ||
#endif | ||
asm("nop\n\t"); // Set a break point here. | ||
|
||
return 0; | ||
} |
2 changes: 1 addition & 1 deletion
2
...te/test/functionalities/register/Makefile → ...lities/register/register_command/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
LEVEL = ../../make | ||
LEVEL = ../../../make | ||
|
||
CXX_SOURCES := main.cpp a.cpp | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.