Annotation of XNU/bsd/kern/mach_fat.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 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 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.
        !            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: /* Copyright (c) 1991 NeXT Computer, Inc.  All rights reserved.
        !            23:  *
        !            24:  *     File:   kern/mach_fat.c
        !            25:  *     Author: Peter King
        !            26:  *
        !            27:  *     Fat file support routines.
        !            28:  *
        !            29:  * HISTORY
        !            30:  * 18 May 1992 ? at NeXT
        !            31:  *     Expanded to handle little endian machines.
        !            32:  *
        !            33:  *  8-Dec-91  Peter King (king) at NeXT
        !            34:  *     Created.
        !            35:  */
        !            36: 
        !            37: #include <sys/param.h>
        !            38: #include <sys/types.h>
        !            39: #include <sys/uio.h>
        !            40: #include <sys/vnode.h>
        !            41: #include <kern/mapfs.h>
        !            42: #include <vm/vm_kern.h>
        !            43: #include <mach/kern_return.h>
        !            44: #include <mach/vm_param.h>
        !            45: #include <kern/cpu_number.h>
        !            46: #include <mach-o/fat.h>
        !            47: #include <kern/mach_loader.h>
        !            48: #include <architecture/byte_order.h>
        !            49: 
        !            50: 
        !            51: /**********************************************************************
        !            52:  * Routine:    fatfile_getarch()
        !            53:  *
        !            54:  * Function:   Locate the architecture-dependant contents of a fat
        !            55:  *             file that match this CPU.
        !            56:  *
        !            57:  * Args:       vp:             The vnode for the fat file.
        !            58:  *             header:         A pointer to the fat file header.
        !            59:  *             archret (out):  Pointer to fat_arch structure to hold
        !            60:  *                             the results.
        !            61:  *
        !            62:  * Returns:    KERN_SUCCESS:   Valid architecture found.
        !            63:  *             KERN_FAILURE:   No valid architecture found.
        !            64:  **********************************************************************/
        !            65: load_return_t fatfile_getarch(
        !            66:        struct vnode            *vp,
        !            67:        vm_offset_t     data_ptr,
        !            68:        struct fat_arch         *archret)
        !            69: {
        !            70:        /* vm_pager_t           pager; */
        !            71:        vm_offset_t             addr;
        !            72:        vm_size_t               size;
        !            73:        kern_return_t           kret;
        !            74:        load_return_t           lret;
        !            75:        struct machine_slot     *ms;
        !            76:        struct fat_arch         *arch;
        !            77:        struct fat_arch         *best_arch;
        !            78:        int                     grade;
        !            79:        int                     best_grade;
        !            80:        int                     nfat_arch;
        !            81:        int                     end_of_archs;
        !            82:        struct proc *p = current_proc();                /* XXXX */
        !            83:        struct fat_header       *header;
        !            84: 
        !            85:        /*
        !            86:         *      Get the pager for the file.
        !            87:         */
        !            88: 
        !            89:        header = (struct fat_header *)data_ptr;
        !            90: 
        !            91:        /*
        !            92:         *      Map portion that must be accessible directly into
        !            93:         *      kernel's map.
        !            94:         */
        !            95:        nfat_arch = NXSwapBigLongToHost(header->nfat_arch);
        !            96: 
        !            97:        end_of_archs = sizeof(struct fat_header)
        !            98:                + nfat_arch * sizeof(struct fat_arch);
        !            99: #if 0
        !           100:        if (vp->v_vm_info) {
        !           101:        if (end_of_archs > vp->v_vm_info->vnode_size)
        !           102:                return(LOAD_BADMACHO);
        !           103:        }
        !           104: #endif
        !           105: 
        !           106:        /* This is beacuse we are reading only 512 bytes */
        !           107: 
        !           108:        if (end_of_archs > 512)
        !           109:                return(LOAD_BADMACHO);
        !           110:        /*
        !           111:         *      Round size of fat_arch structures up to page boundry.
        !           112:         */
        !           113:        size = round_page(end_of_archs);
        !           114:        if (size <= 0)
        !           115:                return(LOAD_BADMACHO);
        !           116: 
        !           117:        /*
        !           118:         * Scan the fat_arch's looking for the best one.
        !           119:         */
        !           120:        addr = data_ptr;
        !           121:        ms = &machine_slot[cpu_number()];
        !           122:        best_arch = NULL;
        !           123:        best_grade = 0;
        !           124:        arch = (struct fat_arch *) (addr + sizeof(struct fat_header));
        !           125:        for (; nfat_arch-- > 0; arch++) {
        !           126: 
        !           127:                /*
        !           128:                 *      Check to see if right cpu type.
        !           129:                 */
        !           130:                if(NXSwapBigIntToHost(arch->cputype) != ms->cpu_type)
        !           131:                        continue;
        !           132: 
        !           133:                /*
        !           134:                 *      Get the grade of the cpu subtype.
        !           135:                 */
        !           136:                grade = grade_cpu_subtype(
        !           137:                            NXSwapBigIntToHost(arch->cpusubtype));
        !           138: 
        !           139:                /*
        !           140:                 *      Remember it if it's the best we've seen.
        !           141:                 */
        !           142:                if (grade > best_grade) {
        !           143:                        best_grade = grade;
        !           144:                        best_arch = arch;
        !           145:                }
        !           146:        }
        !           147: 
        !           148:        /*
        !           149:         *      Return our results.
        !           150:         */
        !           151:        if (best_arch == NULL) {
        !           152:                lret = LOAD_BADARCH;
        !           153:        } else {
        !           154:                archret->cputype        =
        !           155:                            NXSwapBigIntToHost(best_arch->cputype);
        !           156:                archret->cpusubtype     =
        !           157:                            NXSwapBigIntToHost(best_arch->cpusubtype);
        !           158:                archret->offset         =
        !           159:                            NXSwapBigLongToHost(best_arch->offset);
        !           160:                archret->size           =
        !           161:                            NXSwapBigLongToHost(best_arch->size);
        !           162:                archret->align          =
        !           163:                            NXSwapBigLongToHost(best_arch->align);
        !           164: 
        !           165:                lret = LOAD_SUCCESS;
        !           166:        }
        !           167: 
        !           168:        /*
        !           169:         * Free the memory we allocated and return.
        !           170:         */
        !           171:        return(lret);
        !           172: }
        !           173: 
        !           174: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.