]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/esan/TestCases/workingset-early-fault.c
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / 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
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 // Our goal is to emulate an instrumented allocator, whose calloc
12 // invoked from dlsym will trigger shadow faults, to test an
13 // early shadow fault during esan interceptor init.
14 // We do this by replacing calloc:
15 void *calloc(size_t size, size_t n) {
16 // Unfortunately we can't print anything to make the test
17 // ensure we got here b/c the sanitizer interceptors can't
18 // handle that during interceptor init.
19
20 // Ensure we trigger a shadow write fault:
21 int x[16];
22 x[0] = size;
23 // Now just emulate calloc.
24 void *res = malloc(size*n);
25 memset(res, 0, size*n);
26 return res;
27 }
28
29 int main(int argc, char **argv) {
30 printf("all done\n");
31 return 0;
32 }
33 // CHECK: all done