1 // RUN: %clang_cl_asan %Od %s %Fe%t %MD
2 // RUN: %env_asan_opts=windows_hook_rtl_allocators=true %run %t 2>&1 | FileCheck %s
3 // UNSUPPORTED: asan-64-bits
9 extern "C" int __sanitizer_get_ownership(const volatile void *p
);
10 using AllocateFunctionPtr
= PVOID(__stdcall
*)(PVOID
, ULONG
, SIZE_T
);
11 using FreeFunctionPtr
= PVOID(__stdcall
*)(PVOID
, ULONG
, PVOID
);
14 HMODULE NtDllHandle
= GetModuleHandle("ntdll.dll");
16 puts("Couldn't load ntdll??");
20 auto RtlAllocateHeap_ptr
= (AllocateFunctionPtr
)GetProcAddress(NtDllHandle
, "RtlAllocateHeap");
21 if (RtlAllocateHeap_ptr
== 0) {
22 puts("Couldn't RtlAllocateHeap");
26 auto RtlFreeHeap_ptr
= (FreeFunctionPtr
)GetProcAddress(NtDllHandle
, "RtlFreeHeap");
27 if (RtlFreeHeap_ptr
== 0) {
28 puts("Couldn't RtlFreeHeap");
34 winbuf
= (char *)RtlAllocateHeap_ptr(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS
, 32),
35 asanbuf
= (char *)RtlAllocateHeap_ptr(GetProcessHeap(), 0, 32),
37 assert(!__sanitizer_get_ownership(winbuf
));
38 assert(__sanitizer_get_ownership(asanbuf
));
40 RtlFreeHeap_ptr(GetProcessHeap(), 0, winbuf
);
41 RtlFreeHeap_ptr(GetProcessHeap(), 0, asanbuf
);