|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved. ! 26: * ! 27: * File: kern/mach_fat.c ! 28: * Author: Peter King ! 29: * ! 30: * Fat file support routines. ! 31: * ! 32: * HISTORY ! 33: * 18 May 1992 ? at NeXT ! 34: * Expanded to handle little endian machines. ! 35: * ! 36: * 8-Dec-91 Peter King (king) at NeXT ! 37: * Created. ! 38: */ ! 39: ! 40: #import <sys/param.h> ! 41: #import <sys/types.h> ! 42: #import <sys/uio.h> ! 43: #import <sys/vnode.h> ! 44: ! 45: #import <kern/mapfs.h> ! 46: #import <vm/vm_kern.h> ! 47: ! 48: #import <mach/kern_return.h> ! 49: #import <mach/vm_param.h> ! 50: ! 51: #import <machine/cpu.h> ! 52: ! 53: #import <mach-o/fat.h> ! 54: ! 55: #import <kern/mach_loader.h> ! 56: ! 57: #import <architecture/byte_order.h> ! 58: ! 59: ! 60: /********************************************************************** ! 61: * Routine: fatfile_getarch() ! 62: * ! 63: * Function: Locate the architecture-dependant contents of a fat ! 64: * file that match this CPU. ! 65: * ! 66: * Args: vp: The vnode for the fat file. ! 67: * header: A pointer to the fat file header. ! 68: * archret (out): Pointer to fat_arch structure to hold ! 69: * the results. ! 70: * ! 71: * Returns: KERN_SUCCESS: Valid architecture found. ! 72: * KERN_FAILURE: No valid architecture found. ! 73: **********************************************************************/ ! 74: load_return_t fatfile_getarch( ! 75: struct vnode *vp, ! 76: vm_offset_t data_ptr, ! 77: struct fat_arch *archret) ! 78: { ! 79: vm_pager_t pager; ! 80: vm_offset_t addr; ! 81: vm_size_t size; ! 82: kern_return_t kret; ! 83: load_return_t lret; ! 84: struct machine_slot *ms; ! 85: struct fat_arch *arch; ! 86: struct fat_arch *best_arch; ! 87: int grade; ! 88: int best_grade; ! 89: int nfat_arch; ! 90: int end_of_archs; ! 91: struct proc *p = current_proc(); /* XXXX */ ! 92: struct fat_header *header; ! 93: ! 94: /* ! 95: * Get the pager for the file. ! 96: */ ! 97: ! 98: header = (struct fat_header *)data_ptr; ! 99: ! 100: /* ! 101: * Map portion that must be accessible directly into ! 102: * kernel's map. ! 103: */ ! 104: nfat_arch = NXSwapBigLongToHost(header->nfat_arch); ! 105: ! 106: end_of_archs = sizeof(struct fat_header) ! 107: + nfat_arch * sizeof(struct fat_arch); ! 108: ! 109: #if 0 ! 110: /* ! 111: * It is incorrect to assume that vp->v_vm_info->vnode_size ! 112: * would be initialized at this point. ! 113: */ ! 114: if (vp->v_vm_info) { ! 115: if (end_of_archs > vp->v_vm_info->vnode_size) ! 116: return(LOAD_BADMACHO); ! 117: } ! 118: #endif ! 119: ! 120: /* This is beacuse we are reading only 512 bytes */ ! 121: ! 122: if (end_of_archs > 512) ! 123: return(LOAD_BADMACHO); ! 124: /* ! 125: * Round size of fat_arch structures up to page boundry. ! 126: */ ! 127: size = round_page(end_of_archs); ! 128: if (size <= 0) ! 129: return(LOAD_BADMACHO); ! 130: ! 131: /* ! 132: * Scan the fat_arch's looking for the best one. ! 133: */ ! 134: addr = data_ptr; ! 135: ms = &machine_slot[cpu_number()]; ! 136: best_arch = NULL; ! 137: best_grade = 0; ! 138: arch = (struct fat_arch *) (addr + sizeof(struct fat_header)); ! 139: for (; nfat_arch-- > 0; arch++) { ! 140: ! 141: /* ! 142: * Check to see if right cpu type. ! 143: */ ! 144: if(NXSwapBigIntToHost(arch->cputype) != ms->cpu_type) ! 145: continue; ! 146: ! 147: /* ! 148: * Get the grade of the cpu subtype. ! 149: */ ! 150: grade = grade_cpu_subtype( ! 151: NXSwapBigIntToHost(arch->cpusubtype)); ! 152: ! 153: /* ! 154: * Remember it if it's the best we've seen. ! 155: */ ! 156: if (grade > best_grade) { ! 157: best_grade = grade; ! 158: best_arch = arch; ! 159: } ! 160: } ! 161: ! 162: /* ! 163: * Return our results. ! 164: */ ! 165: if (best_arch == NULL) { ! 166: lret = LOAD_BADARCH; ! 167: } else { ! 168: archret->cputype = ! 169: NXSwapBigIntToHost(best_arch->cputype); ! 170: archret->cpusubtype = ! 171: NXSwapBigIntToHost(best_arch->cpusubtype); ! 172: archret->offset = ! 173: NXSwapBigLongToHost(best_arch->offset); ! 174: archret->size = ! 175: NXSwapBigLongToHost(best_arch->size); ! 176: archret->align = ! 177: NXSwapBigLongToHost(best_arch->align); ! 178: ! 179: lret = LOAD_SUCCESS; ! 180: } ! 181: ! 182: /* ! 183: * Free the memory we allocated and return. ! 184: */ ! 185: return(lret); ! 186: } ! 187: ! 188:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.