File: stack-history-length.c

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (42 lines) | stat: -rw-r--r-- 1,228 bytes parent folder | download | duplicates (5)
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
// RUN: %clang_hwasan -O1 %s -o %t
// RUN: %env_hwasan_opts=stack_history_size=2048 not %run %t 2045 2>&1 | FileCheck %s --check-prefix=YES
// RUN: %env_hwasan_opts=stack_history_size=2048 not %run %t 2047 2>&1 | FileCheck %s --check-prefix=NO

// REQUIRES: stable-runtime

// Stack histories are currently not recorded on x86.
// XFAIL: x86_64

#include <stdlib.h>

void USE(void *x) { // pretend_to_do_something(void *x)
  __asm__ __volatile__("" : : "r" (x) : "memory");
}

volatile int four = 4;
__attribute__((noinline)) void FUNC0() { int x[4]; USE(&x[0]); }
__attribute__((noinline)) void FUNC() { int x[4]; USE(&x[0]); }
__attribute__((noinline)) void OOB() { int x[4]; x[four] = 0; USE(&x[0]); }

int main(int argc, char **argv) {
  int X = argc == 2 ? atoi(argv[1]) : 10;
  // FUNC0 is X+2's element of the ring buffer.
  // If runtime buffer size is less than it, FUNC0 record will be lost.
  FUNC0();
  for (int i = 0; i < X; ++i)
    FUNC();
  // Make at least one call to OOB where base tag != 0 so that the bug is caught
  // at least once.
  OOB();
  OOB();
}

// YES: Previously allocated frames
// YES: OOB
// YES: FUNC
// YES: FUNC0

// NO: Previously allocated frames
// NO: OOB
// NO: FUNC
// NO-NOT: FUNC0