]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/esan/TestCases/workingset-early-fault.c
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / esan / TestCases / workingset-early-fault.c
1 // Test shadow faults during esan initialization as well as
2 // faults during dlsym's calloc during interceptor init.
3 //
4 // RUN: %clang_esan_wset %s -o %t
5 // RUN: %run %t 2>&1 | FileCheck %s
6 // Stucks at init and no clone feature equivalent.
7 // UNSUPPORTED: freebsd
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 // Our goal is to emulate an instrumented allocator, whose calloc
14 // invoked from dlsym will trigger shadow faults, to test an
15 // early shadow fault during esan interceptor init.
16 // We do this by replacing calloc:
17 void *calloc(size_t size, size_t n) {
18   // Unfortunately we can't print anything to make the test
19   // ensure we got here b/c the sanitizer interceptors can't
20   // handle that during interceptor init.
21
22   // Ensure we trigger a shadow write fault:
23   int x[16];
24   x[0] = size;
25   // Now just emulate calloc.
26   void *res = malloc(size*n);
27   memset(res, 0, size*n);
28   return res;
29 }
30
31 int main(int argc, char **argv) {
32   printf("all done\n");
33   return 0;
34 }
35 // CHECK: all done