Files
clang-p2996/compiler-rt/test/asan/TestCases/Windows/sanitizer_purge.cpp
Matthew G McGovern 81b1d3da09 [sanitizers][Windows] Implement __sanitizer_purge_allocator for Win64
Windows' memory unmapping has to be explicit, there is no madvise.
Similarly, re-mapping memory has to be explicit as well. This patch
implements a basic method for remapping memory which was previously
returned to the OS on Windows.

Patch by Matthew G. McGovern and Jordyn Puryear
2021-02-12 09:49:04 -08:00

31 lines
637 B
C++

#include <Windows.h>
#include <stdio.h>
#include <sanitizer/allocator_interface.h>
#include <psapi.h>
// RUN: %clang_cl_asan -Od %s -Fe%t
// RUN: %t
// REQUIRES: asan-64-bits
size_t GetRSS() {
PROCESS_MEMORY_COUNTERS counters;
if (!GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters)))
return 0;
return counters.WorkingSetSize;
}
int main(){
for (int i = 0; i < 1000; i++) {
void* a = malloc(1000);
free(a);
}
size_t rss_pre = GetRSS();
__sanitizer_purge_allocator();
size_t rss_post = GetRSS();
if (rss_pre <= rss_post){
return -1;
}
return 0;
}