]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dyld_fork-locks.dest/main.c
dyld-851.27.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 #include "test_support.h"
11
12 bool isParent = true;
13
14 static void notifyBeforeFork(const struct mach_header* mh, intptr_t vmaddr_slide)
15 {
16 static bool sRanNotifier = false;
17 if (sRanNotifier)
18 return;
19 sRanNotifier = true;
20
21 // fork and exec child
22 pid_t sChildPid = fork();
23 if ( sChildPid < 0 ) {
24 FAIL("Didn't fork");
25 }
26 if ( sChildPid == 0 ) {
27 // child side
28 isParent = false;
29 }
30 }
31
32 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
33 _dyld_register_func_for_add_image(&notifyBeforeFork);
34
35 if (isParent) {
36 PASS("Success");
37 }
38
39 return 0;
40 }