]>
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"
21 #include <TargetConditionals.h>
23 static const size_t dyld_cache_header_size
= sizeof (struct copied_dyld_cache_header
);
26 * The shared cache must both contain the magic ID and
27 * match the uuid we discovered via dyld's information.
28 * Assumes that the dyld_cache_header grows in a binary compatible fashion.
31 get_uuid_from_shared_cache_mapping(const void *addr
, size_t size
, uuid_t out
)
33 const struct copied_dyld_cache_header
*ch
= addr
;
34 if (size
< sizeof (*ch
))
36 static const char prefix
[] = "dyld_v";
37 if (strncmp(ch
->magic
, prefix
, strlen(prefix
)) != 0)
39 uuid_copy(out
, ch
->uuid
);
44 * Look in the known places to see if we can find this one ..
47 shared_cache_filename(const uuid_t uu
)
49 assert(!uuid_is_null(uu
));
50 static char *sc_argv
[] = {
52 "/System/Library/dyld",
53 #elif TARGET_OS_IPHONE
54 "/System/Library/Caches/com.apple.dyld",
61 FTS
*fts
= fts_open(sc_argv
, FTS_NOCHDIR
| FTS_LOGICAL
| FTS_XDEV
, NULL
);
64 while (NULL
!= (fe
= fts_read(fts
))) {
65 if ((fe
->fts_info
& FTS_F
) == 0 ||
66 (fe
->fts_info
& FTS_ERR
) != 0)
69 static const char prefix
[] = "dyld_shared_cache_";
70 if (strncmp(fe
->fts_name
, prefix
, strlen(prefix
)) != 0)
73 if (fe
->fts_statp
->st_size
< (off_t
)dyld_cache_header_size
)
76 int d
= open(fe
->fts_accpath
, O_RDONLY
);
78 if (OPTIONS_DEBUG(opt
, 1))
79 printf("%s: cannot open - %s\n", fe
->fts_accpath
, strerror(errno
));
82 void *addr
= mmap(NULL
, dyld_cache_header_size
, PROT_READ
, MAP_PRIVATE
, d
, 0);
84 if ((void *)-1 == addr
) {
85 if (OPTIONS_DEBUG(opt
, 1))
86 printf("%s: cannot mmap - %s\n", fe
->fts_accpath
, strerror(errno
));
91 if (get_uuid_from_shared_cache_mapping(addr
, dyld_cache_header_size
, scuuid
)) {
92 if (uuid_compare(uu
, scuuid
) == 0)
93 nm
= strdup(fe
->fts_accpath
);
94 else if (OPTIONS_DEBUG(opt
, 3)) {
96 uuid_unparse_lower(scuuid
, scstr
);
97 printf("%s: shared cache mismatch (%s)\n", fe
->fts_accpath
, scstr
);
100 munmap(addr
, dyld_cache_header_size
);