]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/init-term-segments.dtest/foo.c
dyld-851.27.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 !__arm64e__
36 #if SUPPORT_CUSTOM_SEGMENTS
37 __attribute__((section(("__MORETEXT,__text"))))
38 #endif
39 __attribute__((destructor))
40 void myterm()
41 {
42 if ( gRanTerm != NULL )
43 *gRanTerm = true;
44 }
45 #endif