]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/init-term-segments.dtest/foo.c
dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / init-term-segments.dtest / foo.c
1
2
3 #include <stdio.h>
4 #include <dlfcn.h>
5 #include <stdlib.h>
6 #include <dispatch/dispatch.h>
7 #include <stdbool.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <pthread.h>
11 #include <assert.h>
12 #include <unistd.h>
13
14 bool ranInit = false;
15 bool* gRanTerm = NULL;
16
17 #define SUPPORT_CUSTOM_SEGMENTS !(__arm64e__ || (__arm64__ && __ARM64_ARCH_8_32__))
18
19 #if SUPPORT_CUSTOM_SEGMENTS
20 __attribute__((section(("__SOMETEXT,__text"))))
21 #endif
22 __attribute__((constructor))
23 void myinit()
24 {
25 ranInit = true;
26 }
27
28 bool foo(bool* ptr) {
29 if (!ranInit)
30 return false;
31 gRanTerm = ptr;
32 return true;
33 }
34
35 #if SUPPORT_CUSTOM_SEGMENTS
36 __attribute__((section(("__MORETEXT,__text"))))
37 #endif
38 __attribute__((destructor))
39 void myterm()
40 {
41 if ( gRanTerm != NULL )
42 *gRanTerm = true;
43 }