]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/shared_cache_range.dtest/main.c
693de548b8b85acb089e6c71f17d38f4a932838e
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>
15 printf("[BEGIN] shared_cache_range\n");
17 // see if image containing malloc is in the dyld cache
19 if ( dladdr(&malloc
, &info
) == 0 ) {
20 printf("[FAIL] shared_cache_range: dladdr(&malloc, xx) failed");
23 const struct mach_header
* mh
= (struct mach_header
*)info
.dli_fbase
;
24 printf("image with malloc=%p\n", mh
);
26 printf("[FAIL] shared_cache_range: dladdr(&malloc, xx) => dli_fbase==NULL");
29 bool haveSharedCache
= (mh
->flags
& 0x80000000);
30 printf("haveSharedCache=%d\n", haveSharedCache
);
33 const void* cacheStart
= _dyld_get_shared_cache_range(&cacheLen
);
35 if ( haveSharedCache
) {
36 if ( cacheStart
== NULL
) {
37 printf("[FAIL] _dyld_get_shared_cache_range() returned NULL even though we have a cache\n");
40 printf("shared cache start=%p, len=0x%0lX\n", cacheStart
, cacheLen
);
41 const void* cacheEnd
= (char*)cacheStart
+ cacheLen
;
43 // verify malloc is in shared cache
44 if ( ((void*)&malloc
< cacheStart
) || ((void*)&malloc
> cacheEnd
) ) {
45 printf("[FAIL] shared_cache_range: malloc is outside range of cache\n");
50 if ( cacheStart
!= NULL
) {
51 printf("[FAIL] _dyld_get_shared_cache_range() returned non-NULL even though we don't have a cache\n");
56 printf("[PASS] shared_cache_range\n");