]>
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 proc
*p
= current_proc(); /* XXXX */
77 struct fat_header
*header
;
81 * Get the pager for the file.
84 header
= (struct fat_header
*)data_ptr
;
87 * Map portion that must be accessible directly into
90 nfat_arch
= NXSwapBigLongToHost(header
->nfat_arch
);
92 end_of_archs
= sizeof(struct fat_header
)
93 + nfat_arch
* sizeof(struct fat_arch
);
95 filesize
= ubc_getsize(vp
);
96 if (end_of_archs
> (int)filesize
)
97 return(LOAD_BADMACHO
);
101 /* This is beacuse we are reading only 512 bytes */
103 if (end_of_archs
> 512)
104 return(LOAD_BADMACHO
);
106 * Round size of fat_arch structures up to page boundry.
108 size
= round_page(end_of_archs
);
110 return(LOAD_BADMACHO
);
113 * Scan the fat_arch's looking for the best one.
116 ms
= &machine_slot
[cpu_number()];
119 arch
= (struct fat_arch
*) (addr
+ sizeof(struct fat_header
));
120 for (; nfat_arch
-- > 0; arch
++) {
123 * Check to see if right cpu type.
125 if(NXSwapBigIntToHost(arch
->cputype
) != ms
->cpu_type
)
129 * Get the grade of the cpu subtype.
131 grade
= grade_cpu_subtype(
132 NXSwapBigIntToHost(arch
->cpusubtype
));
135 * Remember it if it's the best we've seen.
137 if (grade
> best_grade
) {
144 * Return our results.
146 if (best_arch
== NULL
) {
150 NXSwapBigIntToHost(best_arch
->cputype
);
151 archret
->cpusubtype
=
152 NXSwapBigIntToHost(best_arch
->cpusubtype
);
154 NXSwapBigLongToHost(best_arch
->offset
);
156 NXSwapBigLongToHost(best_arch
->size
);
158 NXSwapBigLongToHost(best_arch
->align
);
164 * Free the memory we allocated and return.