This patch unify the 39-bit and 42-bit mapping for aarch64 to use only
one instrumentation algorithm. A runtime check avoid mapping 42-bit
only segments for 39-bit kernels.
The mapping to use now is for 39 and 42-bits:
0x00000000000ULL-0x01000000000ULL MappingDesc::INVALID
0x01000000000ULL-0x02000000000ULL MappingDesc::SHADOW
0x02000000000ULL-0x03000000000ULL MappingDesc::ORIGIN
0x03000000000ULL-0x04000000000ULL MappingDesc::SHADOW
0x04000000000ULL-0x05000000000ULL MappingDesc::ORIGIN
0x05000000000ULL-0x06000000000ULL MappingDesc::APP
0x06000000000ULL-0x07000000000ULL MappingDesc::INVALID
0x07000000000ULL-0x08000000000ULL MappingDesc::APP
And only for 42-bits:
0x08000000000ULL-0x09000000000ULL MappingDesc::INVALID
0x09000000000ULL-0x0A000000000ULL MappingDesc::SHADOW
0x0A000000000ULL-0x0B000000000ULL MappingDesc::ORIGIN
0x0B000000000ULL-0x0F000000000ULL MappingDesc::INVALID
0x0F000000000ULL-0x10000000000ULL MappingDesc::APP
0x10000000000ULL-0x11000000000ULL MappingDesc::INVALID
0x11000000000ULL-0x12000000000ULL MappingDesc::APP
0x12000000000ULL-0x17000000000ULL MappingDesc::INVALID
0x17000000000ULL-0x18000000000ULL MappingDesc::SHADOW
0x18000000000ULL-0x19000000000ULL MappingDesc::ORIGIN
0x19000000000ULL-0x20000000000ULL MappingDesc::INVALID
0x20000000000ULL-0x21000000000ULL MappingDesc::APP
0x21000000000ULL-0x26000000000ULL MappingDesc::INVALID
0x26000000000ULL-0x27000000000ULL MappingDesc::SHADOW
0x27000000000ULL-0x28000000000ULL MappingDesc::ORIGIN
0x28000000000ULL-0x29000000000ULL MappingDesc::SHADOW
0x29000000000ULL-0x2A000000000ULL MappingDesc::ORIGIN
0x2A000000000ULL-0x2B000000000ULL MappingDesc::APP
0x2B000000000ULL-0x2C000000000ULL MappingDesc::INVALID
0x2C000000000ULL-0x2D000000000ULL MappingDesc::SHADOW
0x2D000000000ULL-0x2E000000000ULL MappingDesc::ORIGIN
0x2E000000000ULL-0x2F000000000ULL MappingDesc::APP
0x2F000000000ULL-0x39000000000ULL MappingDesc::INVALID
0x39000000000ULL-0x3A000000000ULL MappingDesc::SHADOW
0x3A000000000ULL-0x3B000000000ULL MappingDesc::ORIGIN
0x3B000000000ULL-0x3C000000000ULL MappingDesc::APP
0x3C000000000ULL-0x3D000000000ULL MappingDesc::INVALID
0x3D000000000ULL-0x3E000000000ULL MappingDesc::SHADOW
0x3E000000000ULL-0x3F000000000ULL MappingDesc::ORIGIN
0x3F000000000ULL-0x40000000000ULL MappingDesc::APP
And although complex it provides a better memory utilization that
previous one.
[1] http://reviews.llvm.org/D13817
llvm-svn: 251625
179 lines
6.4 KiB
C++
179 lines
6.4 KiB
C++
// This test program creates a very large number of unique histories.
|
|
|
|
// Heap origin.
|
|
// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O3 %s -o %t
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=7,origin_history_per_stack_limit=0 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
|
|
|
|
// Stack origin.
|
|
// RUN: %clangxx_msan -DSTACK -fsanitize-memory-track-origins=2 -O3 %s -o %t
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=7,origin_history_per_stack_limit=0 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
|
|
|
|
|
|
// Heap origin, with calls.
|
|
// RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -O3 %s -o %t
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=7,origin_history_per_stack_limit=0 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
|
|
|
|
|
|
// Stack origin, with calls.
|
|
// RUN: %clangxx_msan -DSTACK -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -O3 %s -o %t
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
|
|
|
|
// RUN: MSAN_OPTIONS=origin_history_size=7,origin_history_per_stack_limit=0 not %run %t >%t.out 2>&1
|
|
// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
static char *buf, *cur, *end;
|
|
void init() {
|
|
buf = new char[1000];
|
|
#ifdef STACK
|
|
char stackbuf[1000];
|
|
char *volatile p = stackbuf;
|
|
memcpy(buf, p, 1000);
|
|
#endif
|
|
cur = buf;
|
|
end = buf + 1000;
|
|
}
|
|
|
|
void line_flush() {
|
|
char *p;
|
|
for (p = cur - 1; p >= buf; --p)
|
|
if (*p == '\n')
|
|
break;
|
|
if (p >= buf) {
|
|
size_t write_sz = p - buf + 1;
|
|
// write(2, buf, write_sz);
|
|
memmove(buf, p + 1, end - p - 1);
|
|
cur -= write_sz;
|
|
}
|
|
}
|
|
|
|
void buffered_write(const char *p, size_t sz) {
|
|
while (sz > 0) {
|
|
size_t copy_sz = end - cur;
|
|
if (sz < copy_sz) copy_sz = sz;
|
|
memcpy(cur, p, copy_sz);
|
|
cur += copy_sz;
|
|
sz -= copy_sz;
|
|
line_flush();
|
|
}
|
|
}
|
|
|
|
void fn1() {
|
|
buffered_write("a\n", 2);
|
|
}
|
|
|
|
void fn2() {
|
|
buffered_write("a\n", 2);
|
|
}
|
|
|
|
void fn3() {
|
|
buffered_write("a\n", 2);
|
|
}
|
|
|
|
int main(void) {
|
|
init();
|
|
for (int i = 0; i < 2000; ++i) {
|
|
fn1();
|
|
fn2();
|
|
fn3();
|
|
}
|
|
return buf[50];
|
|
}
|
|
|
|
// CHECK7: WARNING: MemorySanitizer: use-of-uninitialized-value
|
|
// CHECK7-NOT: Uninitialized value was stored to memory at
|
|
// CHECK7: Uninitialized value was stored to memory at
|
|
// CHECK7-NOT: Uninitialized value was stored to memory at
|
|
// CHECK7: Uninitialized value was stored to memory at
|
|
// CHECK7-NOT: Uninitialized value was stored to memory at
|
|
// CHECK7: Uninitialized value was stored to memory at
|
|
// CHECK7-NOT: Uninitialized value was stored to memory at
|
|
// CHECK7: Uninitialized value was stored to memory at
|
|
// CHECK7-NOT: Uninitialized value was stored to memory at
|
|
// CHECK7: Uninitialized value was stored to memory at
|
|
// CHECK7-NOT: Uninitialized value was stored to memory at
|
|
// CHECK7: Uninitialized value was stored to memory at
|
|
// CHECK7-NOT: Uninitialized value was stored to memory at
|
|
// CHECK7: Uninitialized value was created
|
|
|
|
// CHECK2: WARNING: MemorySanitizer: use-of-uninitialized-value
|
|
// CHECK2-NOT: Uninitialized value was stored to memory at
|
|
// CHECK2: Uninitialized value was stored to memory at
|
|
// CHECK2-NOT: Uninitialized value was stored to memory at
|
|
// CHECK2: Uninitialized value was created
|
|
|
|
// CHECK-PER-STACK: WARNING: MemorySanitizer: use-of-uninitialized-value
|
|
// CHECK-PER-STACK: Uninitialized value was stored to memory at
|
|
// CHECK-PER-STACK: in fn3
|
|
// CHECK-PER-STACK: Uninitialized value was stored to memory at
|
|
// CHECK-PER-STACK: in fn2
|
|
// CHECK-PER-STACK: Uninitialized value was stored to memory at
|
|
// CHECK-PER-STACK: in fn1
|
|
// CHECK-PER-STACK: Uninitialized value was created
|
|
|
|
// CHECK-UNLIMITED: WARNING: MemorySanitizer: use-of-uninitialized-value
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was stored to memory at
|
|
// CHECK-UNLIMITED: Uninitialized value was created
|