]> git.saurik.com Git - apple/dyld.git/blob - unit-tests/test-cases/dyld_shared_cache_iterate_text/main.c
dyld-519.2.1.tar.gz
[apple/dyld.git] / unit-tests / test-cases / dyld_shared_cache_iterate_text / main.c
1 /*
2 * Copyright (c) 2015 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 #include <stdlib.h> // EXIT_SUCCESS
24 #include <stdio.h>
25 #include <mach-o/dyld.h>
26 #include <mach-o/dyld_images.h>
27 #include <mach-o/dyld_priv.h>
28 #include <mach/mach.h>
29 #include <Availability.h>
30 #include <mach/shared_region.h>
31
32 #include "test.h"
33 #include "dyld_cache_format.h"
34
35
36
37 int main()
38 {
39 uuid_t curUuid;
40 _dyld_get_shared_cache_uuid(curUuid);
41
42 int __block imageCount = 0;
43 int result = dyld_shared_cache_iterate_text(curUuid, ^(const dyld_shared_cache_dylib_text_info* info) {
44 ++imageCount;
45 //printf(" cur: 0x%09llX -> 0x%09llX off=0x%0llX %s\n", info->loadAddressUnslid, info->loadAddressUnslid + info->textSegmentSize, info->textSegmentOffset, info->path);
46 });
47 if ( result != 0 ) {
48 FAIL("dyld_shared_cache_iterate_text: dyld_shared_cache_iterate_text() failed");
49 exit(0);
50 }
51
52 if ( imageCount < 500 ) {
53 FAIL("dyld_shared_cache_iterate_text: dyld_shared_cache_iterate_text() iterated less than 500 dylibs (%d)", imageCount);
54 exit(0);
55 }
56 #if 0
57 //uuid_t fixedUUID = {0x3E, 0xDE, 0x37, 0x05, 0x81, 0x68, 0x33, 0xEF, 0xBF, 0x97, 0xC0, 0xF6, 0xD2, 0x4D, 0x93, 0xEC};
58 uuid_t fixedUUID = {0xD4, 0x3B, 0x31, 0x2B, 0xA5, 0xA7, 0x3C, 0x55, 0x90, 0xA0, 0x9A, 0x37, 0x60, 0x7D, 0x70, 0xAF};
59 result = dyld_shared_cache_iterate_text(fixedUUID, ^(const dyld_shared_cache_dylib_text_info* info) {
60 printf(" my: 0x%09llX -> 0x%09llX %s\n", info->loadAddressUnslid, info->loadAddressUnslid + info->textSegmentSize, info->path);
61 });
62 #endif
63
64 PASS("dyld_shared_cache_iterate_text");
65 return EXIT_SUCCESS;
66 }
67
68