]> git.saurik.com Git - apple/dyld.git/blob - unit-tests/test-cases/all_image_infos/main.c
dyld-655.1.1.tar.gz
[apple/dyld.git] / unit-tests / test-cases / all_image_infos / main.c
1 /*
2 * Copyright (c) 2008-2009 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/mach.h>
28 #include <Availability.h>
29
30 #include "test.h"
31
32 extern struct mach_header __dso_handle;
33
34
35 struct dyld_all_image_infos* getImageInfosFromKernel()
36 {
37 task_dyld_info_data_t task_dyld_info;
38 mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
39
40 if ( task_info(mach_task_self(), TASK_DYLD_INFO, (task_info_t)&task_dyld_info, &count) ) {
41 FAIL("all_image_infos: task_info() failed");
42 exit(0);
43 }
44 return (struct dyld_all_image_infos*)(uintptr_t)task_dyld_info.all_image_info_addr;
45 }
46
47
48 int
49 main()
50 {
51 struct dyld_all_image_infos* infos = getImageInfosFromKernel();
52 if ( infos->version < 9 ) {
53 FAIL("all_image_infos: dyld_all_image_infos is not version >= 9, is %d", infos->version);
54 exit(0);
55 }
56
57 if ( infos->infoArrayCount < 2 ) {
58 FAIL("all_image_infos: dyld_all_image_infos.infoArrayCount is < 2");
59 exit(0);
60 }
61
62 //for( int i=0; i < infos->infoArrayCount; ++i) {
63 // fprintf(stderr, "infos->infoArray[%d].imageLoadAddress=%p %s\n", i, infos->infoArray[i].imageLoadAddress, infos->infoArray[i].imageFilePath);
64 //}
65
66 if ( infos->infoArray[0].imageLoadAddress != &__dso_handle ) {
67 FAIL("all_image_infos: dyld_all_image_infos.infoArray for main executable is wrong, infos->infoArray[0].imageLoadAddress=0x%08lX vs 0x%08X",
68 infos->infoArray[0].imageLoadAddress, &__dso_handle);
69 exit(0);
70 }
71
72 #if __IPHONE_OS_VERSION_MIN_REQUIRED
73 for (const struct dyld_image_info* p = infos->infoArray; p < &infos->infoArray[infos->infoArrayCount]; ++p) {
74 //fprintf(stderr, "addr=0x%p, mTime=0x%lX, path=%s\n", p->imageLoadAddress, p->imageFileModDate, p->imageFilePath);
75 if ( (strncmp(p->imageFilePath, "/usr/lib", 8) == 0) && (p->imageFileModDate != 0) ) {
76 FAIL("all_image_infos, mTime not zero for cache image %s", p->imageFilePath);
77 exit(0);
78 }
79 }
80 #endif
81
82 PASS("all_image_infos");
83 return EXIT_SUCCESS;
84 }
85
86