diff options
author | Valentina Giusti <valentina.giusti@intel.com> | 2016-10-06 18:05:12 +0000 |
---|---|---|
committer | Valentina Giusti <valentina.giusti@intel.com> | 2016-10-06 18:05:12 +0000 |
commit | 6f8c1f8da7640438bb19a2d40b6b75742a161b9b (patch) | |
tree | ab13270b5211014569f04fb3af86c42714413074 /lldb/packages/Python | |
parent | d0a4db76324e40e38a23429c07eda76f9f26a153 (diff) | |
download | bcm5719-llvm-6f8c1f8da7640438bb19a2d40b6b75742a161b9b.tar.gz bcm5719-llvm-6f8c1f8da7640438bb19a2d40b6b75742a161b9b.zip |
Add bound violation handling for Intel(R) Memory Protection Extensions (Intel(R) MPX)
Summary:
This patch adds support for handling the SIGSEGV signal with 'si_code ==
SEGV_BNDERR', which is thrown when a bound violation is caught by the
Intel(R) MPX technology.
Differential Revision: https://reviews.llvm.org/D25329
llvm-svn: 283474
Diffstat (limited to 'lldb/packages/Python')
3 files changed, 104 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/Makefile new file mode 100644 index 00000000000..aa88c47ff3f --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../../../make + +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS += -mmpx -fcheck-pointer-bounds -fuse-ld=bfd + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py b/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py new file mode 100644 index 00000000000..45721dd260d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py @@ -0,0 +1,57 @@ +""" +Test the Intel(R) MPX bound violation signal. +""" + +from __future__ import print_function + + +import os +import sys +import 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__) + + @skipIf(compiler="clang") + @skipIf(oslist=no_match(['linux'])) + @skipIf(archs=no_match(['i386', 'x86_64'])) + @skipIf(oslist=["linux"], compiler="gcc", compiler_version=["<", "5"]) #GCC version >= 5 supports Intel(R) MPX. + def test_mpx_boundary_violation(self): + """Test Intel(R) MPX bound violation signal.""" + self.build() + self.mpx_boundary_violation() + + def mpx_boundary_violation(self): + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + self.runCmd("run", RUN_SUCCEEDED) + + target = self.dbg.GetSelectedTarget() + process = target.GetProcess() + + if (process.GetState() == lldb.eStateExited): + self.skipTest("Intel(R) MPX is not supported.") + + if (process.GetState() == lldb.eStateStopped): + self.expect("thread backtrace", STOPPED_DUE_TO_SIGNAL, + substrs = ['stop reason = signal SIGSEGV: upper bound violation', + 'fault address:', 'lower bound:', 'upper bound:']) + + self.runCmd("continue") + + if (process.GetState() == lldb.eStateStopped): + self.expect("thread backtrace", STOPPED_DUE_TO_SIGNAL, + substrs = ['stop reason = signal SIGSEGV: lower bound violation', + 'fault address:', 'lower bound:', 'upper bound:']) + + self.runCmd("continue") + self.assertTrue(process.GetState() == lldb.eStateExited, + PROCESS_EXITED) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/main.cpp new file mode 100644 index 00000000000..9c445aa8a27 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/main.cpp @@ -0,0 +1,40 @@ +//===-- 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 <cstddef> +#include <sys/prctl.h> + +static void violate_upper_bound(int *ptr, int size) +{ + int i; + i = *(ptr + size); +} + +static void violate_lower_bound (int *ptr, int size) +{ + int i; + i = *(ptr - size); +} + +int +main(int argc, char const *argv[]) +{ + unsigned int rax, rbx, rcx, rdx; + int array[5]; + + // This call returns 0 only if the CPU and the kernel support Intel(R) MPX. + if (prctl(PR_MPX_ENABLE_MANAGEMENT, 0, 0, 0, 0) != 0) + return -1; + + violate_upper_bound(array, 5); + violate_lower_bound(array, 5); + + return 0; +} |