1 /* 2 * Copyright (c) 2021 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 23 #ifndef _VM_PMAP_CS_H_ 24 #define _VM_PMAP_CS_H_ 25 26 #ifdef KERNEL_PRIVATE 27 /* 28 * All of PMAP_CS definitions are private and should remain accessible only within XNU 29 * and Apple internal kernel extensions. 30 */ 31 32 #include <mach/kern_return.h> 33 #include <mach/vm_param.h> 34 #include <mach/vm_types.h> 35 #include <mach/boolean.h> 36 37 #ifdef MACH_KERNEL_PRIVATE 38 #if defined(__arm64__) 39 #include <pexpert/arm64/board_config.h> 40 #endif 41 #endif 42 43 44 /* To cover situations where we want something on RESEARCH builds as well */ 45 46 47 /* 48 * All APIs which are relevant for AppleImage4. 49 */ 50 51 #if defined(__arm__) || defined(__arm64__) 52 #define PMAP_SUPPORTS_IMAGE4_NONCE 1 53 #define PMAP_SUPPORTS_IMAGE4_OBJECT_EXECUTION 1 54 #endif 55 56 /* These are needed to complete the img4_* types */ 57 #include <img4/firmware.h> 58 #include <img4/nonce.h> 59 60 /** 61 * The PPl allocates some space for AppleImage4 to store some of its data. It needs to 62 * allocate this space since this region needs to be PPL protected, and the macro which 63 * makes a region PPL protected isn't available to kernel extensions. 64 * 65 * This function can be used to acquire the memory region which is PPL protected. 66 */ 67 extern void* pmap_image4_pmap_data( 68 size_t *allocated_size); 69 70 /** 71 * Use the AppleImage4 API to set a nonce value based on a particular nonce index. 72 * AppleImage4 ensures that a particular nonce domain value can only be set once 73 * during the boot of the system. 74 */ 75 extern void pmap_image4_set_nonce( 76 const img4_nonce_domain_index_t ndi, 77 const img4_nonce_t *nonce); 78 79 /** 80 * Use the AppleImage4 API to roll the nonce associated with a particular domain to 81 * make the nonce invalid. 82 */ 83 extern void pmap_image4_roll_nonce( 84 const img4_nonce_domain_index_t ndi); 85 86 /** 87 * Use the AppleImage4 API to copy the nonce value associated with a particular domain. 88 * 89 * The PPL will attempt to "pin" the nonce_out parameter before writing to it. 90 */ 91 extern errno_t pmap_image4_copy_nonce( 92 const img4_nonce_domain_index_t ndi, 93 img4_nonce_t *nonce_out); 94 95 /** 96 * Use the AppleImage4 API to perform object execution of a particular known object type. 97 * 98 * These are the supported object types: 99 * - IMG4_RUNTIME_OBJECT_SPEC_INDEX_SUPPLEMENTAL_ROOT 100 */ 101 extern errno_t pmap_image4_execute_object( 102 img4_runtime_object_spec_index_t obj_spec_index, 103 const img4_buff_t *payload, 104 const img4_buff_t *manifest); 105 106 /** 107 * Use the AppleImage4 API to copy an executed objects contents into provided memroy. 108 * 109 * The PPL will attempt to "pin" the object_out parameter before writing to it. 110 */ 111 extern errno_t pmap_image4_copy_object( 112 img4_runtime_object_spec_index_t obj_spec_index, 113 vm_address_t object_out, 114 size_t *object_length); 115 116 #endif /* KERNEL_PRIVATE */ 117 118 #endif /* _VM_PMAP_CS_H_ */ 119