dyld-732.8.tar.gz
[apple/dyld.git] / testing / test-cases / _dyld_get_objc_selector-shared-cache.dtest / main.c
1
2 // BUILD: $CC main.c -o $BUILD_DIR/_dyld_get_objc_selector-shared-cache.exe
3
4 // RUN: ./_dyld_get_objc_selector-shared-cache.exe
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <dlfcn.h>
9 #include <mach-o/dyld.h>
10 #include <mach-o/dyld_priv.h>
11
12
13 int main()
14 {
15 printf("[BEGIN] _dyld_get_objc_selector-shared-cache\n");
16
17 size_t cacheLen;
18 uintptr_t cacheStart = (uintptr_t)_dyld_get_shared_cache_range(&cacheLen);
19
20 const char* selName = _dyld_get_objc_selector("retain");
21
22 if ( cacheStart != 0 ) {
23 // We have a shared cache, so the selector should be there
24 if ( selName == NULL ) {
25 printf("[FAIL] _dyld_get_objc_selector() returned null for selector in shared cache\n");
26 return 0;
27 }
28
29 if ( ((uintptr_t)selName < cacheStart) || ((uintptr_t)selName >= (cacheStart + cacheLen)) ) {
30 printf("[FAIL] _dyld_get_objc_selector() pointer outside of shared cache range\n");
31 return 0;
32 }
33 } else {
34 // No shared cache, so the selector should not be found.
35 // FIXME: This assumption may be false once the selectors are in the closure.
36 if ( selName != NULL ) {
37 printf("[FAIL] _dyld_get_objc_selector() returned non-null for selector without shared cache\n");
38 return 0;
39 }
40 }
41
42 printf("[PASS] _dyld_get_objc_selector-shared-cache\n");
43 return 0;
44 }
45