Chameleon

Chameleon Svn Source Tree

Root/branches/xZen/src/arch/i386/libsaio/load.c

Source at commit 1267 created 12 years 8 months ago.
By meklort, Strip out code. Update Makefiles
1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 2.0 (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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * load.c - Functions for decoding a Mach-o Kernel.
24 *
25 * Copyright (c) 1998-2003 Apple Computer, Inc.
26 *
27 */
28
29#include <mach-o/fat.h>
30#include <mach-o/loader.h>
31#include <mach/machine/thread_status.h>
32
33#include <sl.h>
34
35bool gHaveKernelCache;/* XXX aserebln: uninitialized? and only set to true, never to false */
36cpu_type_t archCpuType=CPU_TYPE_I386;
37
38// Public Functions
39
40long ThinFatFile(void **binary, unsigned long *length)
41{
42 unsigned long nfat, swapped, size = 0;
43 struct fat_header *fhp = (struct fat_header *)*binary;
44 struct fat_arch *fap =
45 (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header));
46 cpu_type_t fapcputype;
47 uint32_t fapoffset;
48 uint32_t fapsize;
49
50 if (fhp->magic == FAT_MAGIC) {
51 nfat = fhp->nfat_arch;
52 swapped = 0;
53 } else if (fhp->magic == FAT_CIGAM) {
54 nfat = OSSwapInt32(fhp->nfat_arch);
55 swapped = 1;
56 } else {
57 return -1;
58 }
59
60 for (; nfat > 0; nfat--, fap++) {
61 if (swapped) {
62 fapcputype = OSSwapInt32(fap->cputype);
63 fapoffset = OSSwapInt32(fap->offset);
64 fapsize = OSSwapInt32(fap->size);
65 }
66else
67{
68fapcputype = fap->cputype;
69fapoffset = fap->offset;
70fapsize = fap->size;
71}
72
73 if (fapcputype == archCpuType) {
74 *binary = (void *) ((unsigned long)*binary + fapoffset);
75 size = fapsize;
76 break;
77 }
78 }
79
80 if (length != 0) *length = size;
81
82 return 0;
83}

Archive Download this file

Revision: 1267