1 | #include "sanitizer\allocator_interface.h" |
2 | #include <cassert> |
3 | #include <stdio.h> |
4 | #include <windows.h> |
5 | // RUN: %clang_cl_asan %s -o%t |
6 | // RUN: %env_asan_opts=windows_hook_rtl_allocators=true %run %t 2>&1 | FileCheck %s |
7 | // UNSUPPORTED: asan-64-bits |
8 | |
9 | int main() { |
10 | //owned by rtl |
11 | void *alloc = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, 100); |
12 | assert(alloc); |
13 | // still owned by rtl |
14 | alloc = HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, alloc, 100); |
15 | assert(alloc && !__sanitizer_get_ownership(alloc) && HeapValidate(GetProcessHeap(), 0, alloc)); |
16 | //convert to asan owned |
17 | void *realloc = HeapReAlloc(GetProcessHeap(), 0, alloc, 500); |
18 | alloc = nullptr; |
19 | assert(realloc && __sanitizer_get_ownership(realloc)); |
20 | //convert back to rtl owned; |
21 | alloc = HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, realloc, 100); |
22 | assert(alloc && !__sanitizer_get_ownership(alloc) && HeapValidate(GetProcessHeap(), 0, alloc)); |
23 | printf(format: "Success\n" ); |
24 | } |
25 | |
26 | // CHECK-NOT: assert |
27 | // CHECK-NOT: AddressSanitizer |
28 | // CHECK: Success |
29 | |