]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/asan/TestCases/large_allocator_unpoisons_on_free.cc
Imported Upstream version 1.5.0+dfsg1
[rustc.git] / src / compiler-rt / test / asan / TestCases / large_allocator_unpoisons_on_free.cc
CommitLineData
1a4d82fc
JJ
1// Test that LargeAllocator unpoisons memory before releasing it to the OS.
2// RUN: %clangxx_asan %s -o %t
3// The memory is released only when the deallocated chunk leaves the quarantine,
4// otherwise the mmap(p, ...) call overwrites the malloc header.
5// RUN: ASAN_OPTIONS=quarantine_size=1 %run %t
6
7#include <assert.h>
8#include <string.h>
9#include <sys/mman.h>
10#include <stdlib.h>
11
12#ifdef __ANDROID__
13#include <malloc.h>
14void *my_memalign(size_t boundary, size_t size) {
15 return memalign(boundary, size);
16}
17#else
18void *my_memalign(size_t boundary, size_t size) {
19 void *p;
20 posix_memalign(&p, boundary, size);
21 return p;
22}
23#endif
24
25int main() {
26 const int kPageSize = 4096;
27 void *p = my_memalign(kPageSize, 1024 * 1024);
28 free(p);
29
30 char *q = (char *)mmap(p, kPageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, 0, 0);
31 assert(q == p);
32
33 memset(q, 42, kPageSize);
34
35 munmap(q, kPageSize);
36 return 0;
37}