brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 9129dc7 Raw
38 lines · c
1// RUN: %clang_dfsan -fno-sanitize=dataflow -DCALLOC -c %s -o %t-calloc.o2// RUN: %clang_dfsan %s %t-calloc.o -o %t3// RUN: %run %t4//5// Tests that calling mmap() during during dfsan initialization works.6 7// `internal_symbolizer` can not use `realloc` on memory from the test `calloc`.8// UNSUPPORTED: internal_symbolizer9 10#include <sanitizer/dfsan_interface.h>11#include <sys/mman.h>12#include <unistd.h>13 14#ifdef CALLOC15 16extern void exit(int) __attribute__((noreturn));17 18// dfsan_init() installs interceptors via dlysm(), which calls calloc().19// Calling mmap() from here should work even if interceptors haven't been fully20// set up yet.21void *calloc(size_t Num, size_t Size) {22  size_t PageSize = getpagesize();23  Size = Size * Num;24  Size = (Size + PageSize - 1) & ~(PageSize - 1); // Round up to PageSize.25  void *Ret = mmap(NULL, Size, PROT_READ | PROT_WRITE,26                   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);27  // Use assert may cause link errors that require -Wl,-z,notext.28  // Do not know the root cause yet.29  if (Ret == MAP_FAILED) exit(-1);30  return Ret;31}32 33#else34 35int main() { return 0; }36 37#endif // CALLOC38