]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/shared_cache_range.dtest/main.c
2 // BUILD: $CC main.c -o $BUILD_DIR/shared_cache_range.exe
4 // RUN: ./shared_cache_range.exe
9 #include <mach-o/dyld_priv.h>
12 #if __has_feature(ptrauth_calls)
16 static const void *stripPointer(const void *ptr
) {
17 #if __has_feature(ptrauth_calls)
18 return __builtin_ptrauth_strip(ptr
, ptrauth_key_asia
);
27 printf("[BEGIN] shared_cache_range\n");
29 // see if image containing malloc is in the dyld cache
31 if ( dladdr(&malloc
, &info
) == 0 ) {
32 printf("[FAIL] shared_cache_range: dladdr(&malloc, xx) failed");
35 const struct mach_header
* mh
= (struct mach_header
*)info
.dli_fbase
;
36 printf("image with malloc=%p\n", mh
);
38 printf("[FAIL] shared_cache_range: dladdr(&malloc, xx) => dli_fbase==NULL");
41 bool haveSharedCache
= (mh
->flags
& 0x80000000);
42 printf("haveSharedCache=%d\n", haveSharedCache
);
45 const void* cacheStart
= _dyld_get_shared_cache_range(&cacheLen
);
47 if ( haveSharedCache
) {
48 if ( cacheStart
== NULL
) {
49 printf("[FAIL] _dyld_get_shared_cache_range() returned NULL even though we have a cache\n");
52 printf("shared cache start=%p, len=0x%0lX\n", cacheStart
, cacheLen
);
53 const void* cacheEnd
= (char*)cacheStart
+ cacheLen
;
55 // verify malloc is in shared cache
56 if ( (stripPointer((void*)&malloc
) < cacheStart
) || (stripPointer((void*)&malloc
) > cacheEnd
) ) {
57 printf("[FAIL] shared_cache_range: malloc is outside range of cache\n");
62 if ( cacheStart
!= NULL
) {
63 printf("[FAIL] _dyld_get_shared_cache_range() returned non-NULL even though we don't have a cache\n");
68 printf("[PASS] shared_cache_range\n");