aboutsummaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/functionalities/register/intel_xtended_registers/mpx_bound_violation/main.cpp
blob: b78eb9e5a2a2a56c1a810d4be46a873235cf19b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//===-- 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];

// PR_MPX_ENABLE_MANAGEMENT won't be defined on linux kernel versions below 3.19
#ifndef PR_MPX_ENABLE_MANAGEMENT
    return -1;
#endif

  // 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;
}