]>
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.
29 get_uuid_from_shared_cache_mapping(const void *addr
, size_t size
, uuid_t out
)
31 const struct copied_dyld_cache_header
*ch
= addr
;
32 if (size
< sizeof (*ch
))
34 static const char prefix
[] = "dyld_v1 ";
35 if (strncmp(ch
->magic
, prefix
, strlen(prefix
)) != 0)
37 uuid_copy(out
, ch
->uuid
);
42 * Look in the known places to see if we can find this one ..
45 shared_cache_filename(const uuid_t uu
)
47 assert(!uuid_is_null(uu
));
48 static char *sc_argv
[] = {
49 #if defined(__i386__) || defined(__x86_64__)
51 #elif defined(__arm__) || defined(__arm64__)
52 "/System/Library/Caches/com.apple.dyld",
59 FTS
*fts
= fts_open(sc_argv
, FTS_NOCHDIR
| FTS_LOGICAL
| FTS_XDEV
, NULL
);
62 while (NULL
!= (fe
= fts_read(fts
))) {
63 if ((fe
->fts_info
& FTS_F
) == 0 ||
64 (fe
->fts_info
& FTS_ERR
) != 0)
67 static const char prefix
[] = "dyld_shared_cache_";
68 if (strncmp(fe
->fts_name
, prefix
, strlen(prefix
)) != 0)
71 if (fe
->fts_statp
->st_size
< (off_t
)dyld_cache_header_size
)
74 int d
= open(fe
->fts_accpath
, O_RDONLY
);
76 if (OPTIONS_DEBUG(opt
, 1))
77 printf("%s: cannot open - %s\n", fe
->fts_accpath
, strerror(errno
));
80 void *addr
= mmap(NULL
, dyld_cache_header_size
, PROT_READ
, MAP_PRIVATE
, d
, 0);
82 if ((void *)-1 == addr
) {
83 if (OPTIONS_DEBUG(opt
, 1))
84 printf("%s: cannot mmap - %s\n", fe
->fts_accpath
, strerror(errno
));
89 if (get_uuid_from_shared_cache_mapping(addr
, dyld_cache_header_size
, scuuid
)) {
90 if (uuid_compare(uu
, scuuid
) == 0)
91 nm
= strdup(fe
->fts_accpath
);
92 else if (OPTIONS_DEBUG(opt
, 3)) {
94 uuid_unparse_lower(scuuid
, scstr
);
95 printf("%s: shared cache mismatch (%s)\n", fe
->fts_accpath
, scstr
);
98 munmap(addr
, dyld_cache_header_size
);