dyld-732.8.tar.gz
[apple/dyld.git] / testing / test-cases / dyld_fork-locks.dest / main.c
1
2 // BUILD: $CC main.c -o $BUILD_DIR/dyld_fork_test.exe
3
4 // RUN: ./dyld_fork_test.exe
5
6 #include <stdio.h>
7 #include <dlfcn.h>
8 #include <mach-o/dyld_priv.h>
9
10 bool isParent = true;
11
12 static void notifyBeforeFork(const struct mach_header* mh, intptr_t vmaddr_slide)
13 {
14 static bool sRanNotifier = false;
15 if (sRanNotifier)
16 return;
17 sRanNotifier = true;
18
19 // fork and exec child
20 pid_t sChildPid = fork();
21 if ( sChildPid < 0 ) {
22 printf("[FAIL] dyld_fork_test didn't fork\n");
23 return;
24 }
25 if ( sChildPid == 0 ) {
26 // child side
27 isParent = false;
28 }
29 }
30
31 int main(int argc, const char* argv[])
32 {
33 printf("[BEGIN] dyld_fork_test\n");
34
35 _dyld_register_func_for_add_image(&notifyBeforeFork);
36
37 if (isParent) {
38 printf("[PASS] dyld_fork_test\n");
39 }
40
41 return 0;
42 }