Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
compiler-rt/test/asan/TestCases/Windows/globalalloc_transfer.cpp
- This file was added.
#include "sanitizer\allocator_interface.h" | |||||
#include <cassert> | |||||
#include <stdio.h> | |||||
#include <windows.h> | |||||
// RUN: %clang_cl_asan %s -o%t | |||||
// RUN: %env_asan_opts=windows_hook_rtl_allocators=true %run %t 2>&1 | FileCheck %s | |||||
// UNSUPPORTED: asan-64-bits | |||||
int main() { | |||||
void *buffer, *realloc; | |||||
HGLOBAL hMem1, hMem2, hMem3; | |||||
//owned by rtl | |||||
hMem1 = GlobalAlloc(GMEM_MOVEABLE, 100); | |||||
buffer = (void *)GlobalLock(hMem1); | |||||
assert(buffer); | |||||
// still owned by rtl | |||||
hMem2 = GlobalReAlloc(buffer, 100, GMEM_MOVEABLE); | |||||
GlobalUnlock(hMem1); | |||||
buffer = (void *)GlobalLock(hMem2); | |||||
assert(buffer); | |||||
assert(!__sanitizer_get_ownership(buffer)); | |||||
assert(HeapValidate(GetProcessHeap(), 0, buffer)); | |||||
//convert to asan owned | |||||
realloc = GlobalReAlloc(buffer, 500, GMEM_FIXED); | |||||
GlobalUnlock(hMem2); | |||||
buffer = nullptr; | |||||
assert(realloc); | |||||
assert(__sanitizer_get_ownership(realloc)); | |||||
//convert back to rtl owned; | |||||
hMem3 = GlobalReAlloc(realloc, 100, GMEM_MOVEABLE); | |||||
buffer = (void *)GlobalLock(hMem3); | |||||
assert(buffer); | |||||
assert(!__sanitizer_get_ownership(buffer)); | |||||
assert(HeapValidate(GetProcessHeap(), 0, buffer)); | |||||
GlobalUnlock(hMem3); | |||||
printf("Success\n"); | |||||
} | |||||
// CHECK-NOT: assert | |||||
// CHECK-NOT: AddressSanitizer | |||||
// CHECK: Success |