1// RUN: %clang_dfsan -fno-sanitize=dataflow -DCALLOC -c %s -o %t-calloc.o
2// RUN: %clang_dfsan %s %t-calloc.o -o %t
3// RUN: %run %t
4//
5// REQUIRES: x86_64-target-arch
6//
7// Tests that calling mmap() during during dfsan initialization works.
8
9#include <assert.h>
10#include <sanitizer/dfsan_interface.h>
11#include <string.h>
12#include <sys/mman.h>
13#include <unistd.h>
14
15#ifdef CALLOC
16
17// dfsan_init() installs interceptors via dlysm(), which calls calloc().
18// Calling mmap() from here should work even if interceptors haven't been fully
19// set up yet.
20void *calloc(size_t Num, size_t Size) {
21 size_t PageSize = getpagesize();
22 Size = Size * Num;
23 Size = (Size + PageSize - 1) & ~(PageSize - 1); // Round up to PageSize.
24 void *Ret = mmap(NULL, Size, PROT_READ | PROT_WRITE,
25 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
26 assert(Ret != MAP_FAILED);
27 return Ret;
28}
29
30#else
31
32int main() { return 0; }
33
34#endif // CALLOC
35