1 /* 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 /* 29 * Copyright (C) 1992, NeXT, Inc. 30 * 31 * File: kern/mach_loader.h 32 * 33 * Mach object file loader API. 34 * 35 * HISTORY 36 * 24-Aug-92 Doug Mitchell at NeXT 37 * Created. 38 */ 39 40 #ifndef _BSD_KERN_MACH_LOADER_H_ 41 #define _BSD_KERN_MACH_LOADER_H_ 42 43 #include <mach/mach_types.h> 44 #include <mach-o/loader.h> 45 46 typedef int load_return_t; 47 48 /* libmalloc relies on these values not changing. If they change, 49 * you need to update the values in that project as well */ 50 __options_decl(HR_flags_t, uint32_t, { 51 BrowserHostEntitlementMask = 0x01, 52 BrowserGPUEntitlementMask = 0x02, 53 BrowserNetworkEntitlementMask = 0x04, 54 BrowserWebContentEntitlementMask = 0x08, 55 }); 56 #define HR_FLAGS_NUM_NIBBLES (sizeof(HR_flags_t) / 2) 57 58 /* 59 * Structure describing the result from calling load_machfile(), if that 60 * function returns LOAD_SUCCESS. 61 */ 62 typedef struct _load_result { 63 user_addr_t mach_header; 64 user_addr_t entry_point; 65 66 // The user stack pointer and addressable user stack size. 67 user_addr_t user_stack; 68 mach_vm_size_t user_stack_size; 69 70 // The allocation containing the stack and guard area. 71 user_addr_t user_stack_alloc; 72 mach_vm_size_t user_stack_alloc_size; 73 74 mach_vm_address_t all_image_info_addr; 75 mach_vm_size_t all_image_info_size; 76 77 int thread_count; 78 unsigned int 79 unixproc : 1, 80 needs_dynlinker : 1, 81 dynlinker : 1, 82 validentry : 1, 83 has_pagezero : 1, 84 using_lcmain : 1, 85 #if __arm64__ 86 legacy_footprint : 1, 87 #endif /* __arm64__ */ 88 is_64bit_addr : 1, 89 is_64bit_data : 1, 90 custom_stack : 1, 91 is_rosetta : 1; 92 unsigned int csflags; 93 unsigned char uuid[16]; 94 mach_vm_address_t min_vm_addr; 95 mach_vm_address_t max_vm_addr; 96 mach_vm_address_t ro_vm_start; 97 mach_vm_address_t ro_vm_end; 98 unsigned int platform_binary; 99 100 /* Flags denoting which type of hardened runtime binary this is*/ 101 HR_flags_t hardened_runtime_binary; 102 off_t cs_end_offset; 103 void *threadstate; 104 size_t threadstate_sz; 105 uint32_t ip_platform; 106 uint32_t lr_min_sdk; 107 uint32_t lr_sdk; 108 user_addr_t dynlinker_mach_header; 109 user_addr_t dynlinker_max_vm_addr; 110 mach_vm_address_t dynlinker_ro_vm_start; 111 mach_vm_address_t dynlinker_ro_vm_end; 112 int dynlinker_fd; 113 struct fileproc* dynlinker_fp; 114 } load_result_t; 115 116 struct image_params; 117 load_return_t load_machfile( 118 struct image_params *imgp, 119 struct mach_header *header, 120 thread_t thread, 121 vm_map_t *mapp, 122 load_result_t *result); 123 124 load_return_t 125 validate_potential_simulator_binary( 126 cpu_type_t exectype, 127 struct image_params *imgp, 128 off_t file_offset, 129 off_t macho_size); 130 131 #define LOAD_SUCCESS 0 132 #define LOAD_BADARCH 1 /* CPU type/subtype not found */ 133 #define LOAD_BADMACHO 2 /* malformed mach-o file */ 134 #define LOAD_SHLIB 3 /* shlib version mismatch */ 135 #define LOAD_FAILURE 4 /* Miscellaneous error */ 136 #define LOAD_NOSPACE 5 /* No VM available */ 137 #define LOAD_PROTECT 6 /* protection violation */ 138 #define LOAD_RESOURCE 7 /* resource allocation failure */ 139 #define LOAD_ENOENT 8 /* resource not found */ 140 #define LOAD_IOERROR 9 /* IO error */ 141 #define LOAD_DECRYPTFAIL 10 /* FP decrypt failure */ 142 #define LOAD_BADMACHO_UPX 11 /* malformed mach-o file */ 143 #define LOAD_BADARCH_X86 12 /* -no32exec boot-arg + attempted load of 32bit x86 binary */ 144 145 #endif /* _BSD_KERN_MACH_LOADER_H_ */ 146