]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/mach_fat.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
24 * File: kern/mach_fat.c
27 * Fat file support routines.
31 #include <sys/param.h>
32 #include <sys/types.h>
34 #include <sys/vnode.h>
35 #include <vm/vm_kern.h>
36 #include <mach/kern_return.h>
37 #include <mach/vm_param.h>
38 #include <kern/cpu_number.h>
39 #include <mach-o/fat.h>
40 #include <kern/mach_loader.h>
41 #include <architecture/byte_order.h>
44 /**********************************************************************
45 * Routine: fatfile_getarch()
47 * Function: Locate the architecture-dependant contents of a fat
48 * file that match this CPU.
50 * Args: vp: The vnode for the fat file.
51 * header: A pointer to the fat file header.
52 * archret (out): Pointer to fat_arch structure to hold
55 * Returns: KERN_SUCCESS: Valid architecture found.
56 * KERN_FAILURE: No valid architecture found.
57 **********************************************************************/
62 struct fat_arch
*archret
)
64 /* vm_pager_t pager; */
69 struct machine_slot
*ms
;
70 struct fat_arch
*arch
;
71 struct fat_arch
*best_arch
;
76 struct fat_header
*header
;
80 * Get the pager for the file.
83 header
= (struct fat_header
*)data_ptr
;
86 * Map portion that must be accessible directly into
89 nfat_arch
= NXSwapBigLongToHost(header
->nfat_arch
);
91 end_of_archs
= sizeof(struct fat_header
)
92 + nfat_arch
* sizeof(struct fat_arch
);
94 filesize
= ubc_getsize(vp
);
95 if (end_of_archs
> (int)filesize
) {
96 return(LOAD_BADMACHO
);
100 /* This is beacuse we are reading only 512 bytes */
102 if (end_of_archs
> 512)
103 return(LOAD_BADMACHO
);
105 * Round size of fat_arch structures up to page boundry.
107 size
= round_page(end_of_archs
);
109 return(LOAD_BADMACHO
);
112 * Scan the fat_arch's looking for the best one.
115 ms
= &machine_slot
[cpu_number()];
118 arch
= (struct fat_arch
*) (addr
+ sizeof(struct fat_header
));
119 for (; nfat_arch
-- > 0; arch
++) {
122 * Check to see if right cpu type.
124 if(NXSwapBigIntToHost(arch
->cputype
) != ms
->cpu_type
)
128 * Get the grade of the cpu subtype.
130 grade
= grade_cpu_subtype(
131 NXSwapBigIntToHost(arch
->cpusubtype
));
134 * Remember it if it's the best we've seen.
136 if (grade
> best_grade
) {
143 * Return our results.
145 if (best_arch
== NULL
) {
149 NXSwapBigIntToHost(best_arch
->cputype
);
150 archret
->cpusubtype
=
151 NXSwapBigIntToHost(best_arch
->cpusubtype
);
153 NXSwapBigLongToHost(best_arch
->offset
);
155 NXSwapBigLongToHost(best_arch
->size
);
157 NXSwapBigLongToHost(best_arch
->align
);
163 * Free the memory we allocated and return.