]>
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 #include "test_support.h"
18 static const void *stripPointer(const void *ptr
) {
19 #if __has_feature(ptrauth_calls)
20 return __builtin_ptrauth_strip(ptr
, ptrauth_key_asia
);
27 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
28 // see if image containing malloc is in the dyld cache
30 if ( dladdr(&malloc
, &info
) == 0 ) {
31 FAIL("shared_cache_range: dladdr(&malloc, xx) fail");
33 const struct mach_header
* mh
= (struct mach_header
*)info
.dli_fbase
;
34 LOG("image with malloc=%p", mh
);
36 FAIL("shared_cache_range: dladdr(&malloc, xx) => dli_fbase==NULL");
38 bool haveSharedCache
= (mh
->flags
& 0x80000000);
39 LOG("haveSharedCache=%d", haveSharedCache
);
42 const void* cacheStart
= _dyld_get_shared_cache_range(&cacheLen
);
44 if ( haveSharedCache
) {
45 if ( cacheStart
== NULL
) {
46 FAIL("_dyld_get_shared_cache_range() returned NULL even though we have a cache");
48 LOG("shared cache start=%p, len=0x%0lX", cacheStart
, cacheLen
);
49 const void* cacheEnd
= (char*)cacheStart
+ cacheLen
;
51 // verify malloc is in shared cache
52 if ( (stripPointer((void*)&malloc
) < cacheStart
) || (stripPointer((void*)&malloc
) > cacheEnd
) ) {
53 FAIL("shared_cache_range: malloc is outside range of cache");
57 if ( cacheStart
!= NULL
) {
58 FAIL("returned non-NULL even though we don't have a cache");