2 * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 #include <stdlib.h> // EXIT_SUCCESS
25 #include <mach-o/dyld.h>
26 #include <mach-o/dyld_images.h>
27 #include <mach/mach.h>
28 #include <Availability.h>
32 extern struct mach_header __dso_handle
;
35 struct dyld_all_image_infos
* getImageInfosFromKernel()
37 task_dyld_info_data_t task_dyld_info
;
38 mach_msg_type_number_t count
= TASK_DYLD_INFO_COUNT
;
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");
44 return (struct dyld_all_image_infos
*)(uintptr_t)task_dyld_info
.all_image_info_addr
;
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
);
57 if ( infos
->infoArrayCount
< 2 ) {
58 FAIL("all_image_infos: dyld_all_image_infos.infoArrayCount is < 2");
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);
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
);
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
);
82 PASS("all_image_infos");