blob: ff184430a044865343c9723368cfbe0c339be3de (
plain)
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
|
// Test for __lsan_(un)register_root_region().
// RUN: LSAN_BASE="use_stacks=0:use_registers=0"
// RUN: %clangxx_lsan %s -o %t
// RUN: LSAN_OPTIONS=$LSAN_BASE %run %t
// RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t foo 2>&1 | FileCheck %s
// RUN: LSAN_OPTIONS=$LSAN_BASE:use_root_regions=0 not %run %t 2>&1 | FileCheck %s
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sanitizer/lsan_interface.h>
// OSX doesn't have MAP_ANONYMOUS.
#ifndef MAP_ANONYMOUS
# define MAP_ANONYMOUS MAP_ANON
#endif
int main(int argc, char *argv[]) {
size_t size = getpagesize() * 2;
void *p =
mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
assert(p);
// Make half of the memory inaccessible. LSan must not crash trying to read it.
assert(0 == mprotect((char *)p + size / 2, size / 2, PROT_NONE));
__lsan_register_root_region(p, size);
*((void **)p) = malloc(1337);
fprintf(stderr, "Test alloc: %p.\n", p);
if (argc > 1)
__lsan_unregister_root_region(p, size);
return 0;
}
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)
|