1 // Test for __lsan_(un)register_root_region().
2 // RUN: %clangxx_lsan %s -o %t
3 // RUN: %env_lsan_opts=use_stacks=0:use_registers=0 %run %t
4 // RUN: %env_lsan_opts=use_stacks=0:use_registers=0 not %run %t foo 2>&1 | FileCheck %s
5 // RUN: %env_lsan_opts=use_stacks=0:use_registers=0:use_root_regions=0 not %run %t 2>&1 | FileCheck %s
13 #include <sanitizer/lsan_interface.h>
15 int main(int argc
, char *argv
[]) {
16 size_t size
= getpagesize() * 2;
18 mmap(0, size
, PROT_READ
| PROT_WRITE
, MAP_PRIVATE
| MAP_ANON
, -1, 0);
20 // Make half of the memory inaccessible. LSan must not crash trying to read it.
21 assert(0 == mprotect((char *)p
+ size
/ 2, size
/ 2, PROT_NONE
));
23 __lsan_register_root_region(p
, size
);
24 *((void **)p
) = malloc(1337);
25 fprintf(stderr
, "Test alloc: %p.\n", p
);
27 __lsan_unregister_root_region(p
, size
);
30 // CHECK: Test alloc: [[ADDR:.*]].
31 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)