]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/init-term-segments.dtest/main.c
dyld-733.6.tar.gz
[apple/dyld.git] / testing / test-cases / init-term-segments.dtest / main.c
1
2
3 // BUILD: $CC foo.c -dynamiclib -fno-register-global-dtors-with-atexit -Wl,-segprot,__SOMETEXT,rx,rx -Wl,-segprot,__MORETEXT,rx,rx -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib
4 // BUILD: $CC main.c -o $BUILD_DIR/init-term-segments.exe -DRUN_DIR="$RUN_DIR"
5
6 // RUN: ./init-term-segments.exe
7
8 #include <stdio.h>
9 #include <dlfcn.h>
10 #include <stdlib.h>
11
12 extern bool foo(bool* ptr);
13
14 int main()
15 {
16 printf("[BEGIN] init-term-segments\n");
17
18 void* h = dlopen(RUN_DIR "/libfoo.dylib", RTLD_NOW);
19 if (h == NULL) {
20 printf("[FAIL] init-term-segments - dlerror = %s\n", dlerror());
21 return 0;
22 }
23
24 void* fooSym = dlsym(RTLD_DEFAULT, "foo");
25 if ( fooSym == NULL ) {
26 printf("[FAIL] init-term-segments - dlsym failure\n");
27 return 0;
28 }
29
30 bool ranTerm = false;
31 bool ranInit = ((__typeof(&foo))fooSym)(&ranTerm);
32 if (!ranInit) {
33 printf("[FAIL] init-term-segments - didn't run init\n");
34 return 0;
35 }
36
37 if ( dlclose(h) != 0 ) {
38 printf("[FAIL] init-term-segments - didn't dlclose\n");
39 return 0;
40 }
41
42 if (!ranTerm) {
43 printf("[FAIL] init-term-segments - didn't run term\n");
44 return 0;
45 }
46
47 printf("[PASS] init-term-segments\n");
48 return 0;
49 }
50