]>
git.saurik.com Git - apple/system_cmds.git/blob - gcore.tproj/dyld_shared_cache.c
2 * Copyright (c) 2016 Apple Inc. All rights reserved.
6 #include "dyld_shared_cache.h"
22 static const size_t dyld_cache_header_size
= sizeof (struct copied_dyld_cache_header
);
25 * The shared cache must both contain the magic ID and
26 * match the uuid we discovered via dyld's information.
27 * Assumes that the dyld_cache_header grows in a binary compatible fashion.
30 get_uuid_from_shared_cache_mapping(const void *addr
, size_t size
, uuid_t out
)
32 const struct copied_dyld_cache_header
*ch
= addr
;
33 if (size
< sizeof (*ch
))
35 static const char prefix
[] = "dyld_v";
36 if (strncmp(ch
->magic
, prefix
, strlen(prefix
)) != 0)
38 uuid_copy(out
, ch
->uuid
);
43 * Look in the known places to see if we can find this one ..
46 shared_cache_filename(const uuid_t uu
)
48 assert(!uuid_is_null(uu
));
49 static char *sc_argv
[] = {
50 #if defined(__i386__) || defined(__x86_64__)
52 #elif defined(__arm__) || defined(__arm64__)
53 "/System/Library/Caches/com.apple.dyld",
60 FTS
*fts
= fts_open(sc_argv
, FTS_NOCHDIR
| FTS_LOGICAL
| FTS_XDEV
, NULL
);
63 while (NULL
!= (fe
= fts_read(fts
))) {
64 if ((fe
->fts_info
& FTS_F
) == 0 ||
65 (fe
->fts_info
& FTS_ERR
) != 0)
68 static const char prefix
[] = "dyld_shared_cache_";
69 if (strncmp(fe
->fts_name
, prefix
, strlen(prefix
)) != 0)
72 if (fe
->fts_statp
->st_size
< (off_t
)dyld_cache_header_size
)
75 int d
= open(fe
->fts_accpath
, O_RDONLY
);
77 if (OPTIONS_DEBUG(opt
, 1))
78 printf("%s: cannot open - %s\n", fe
->fts_accpath
, strerror(errno
));
81 void *addr
= mmap(NULL
, dyld_cache_header_size
, PROT_READ
, MAP_PRIVATE
, d
, 0);
83 if ((void *)-1 == addr
) {
84 if (OPTIONS_DEBUG(opt
, 1))
85 printf("%s: cannot mmap - %s\n", fe
->fts_accpath
, strerror(errno
));
90 if (get_uuid_from_shared_cache_mapping(addr
, dyld_cache_header_size
, scuuid
)) {
91 if (uuid_compare(uu
, scuuid
) == 0)
92 nm
= strdup(fe
->fts_accpath
);
93 else if (OPTIONS_DEBUG(opt
, 3)) {
95 uuid_unparse_lower(scuuid
, scstr
);
96 printf("%s: shared cache mismatch (%s)\n", fe
->fts_accpath
, scstr
);
99 munmap(addr
, dyld_cache_header_size
);