1 /* 2 * Copyright (c) 2023 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 #if CONFIG_EXCLAVES 30 31 #pragma once 32 33 #include <stdint.h> 34 #include <mach/kern_return.h> 35 36 #include "kern/exclaves.tightbeam.h" 37 38 __BEGIN_DECLS 39 40 41 /*! 42 * @function exclaves_shared_memory_init 43 * 44 * @abstract 45 * Initialize a tightbeam connection to a shared memory segment. 46 * 47 * @param endpoint 48 * Endpoint ID of the shared memory 49 * 50 * @param sm_client 51 * Out paramater holding the connection. 52 * 53 * @return 54 * The KERN_SUCCESS or error code on failure. 55 */ 56 extern kern_return_t 57 exclaves_shared_memory_init(const uint64_t endpoint, 58 sharedmemorybase_segxnuaccess_s *sm_client); 59 60 /*! 61 * @function exclaves_shared_memory_setup 62 * 63 * @abstract 64 * Initialize access to the shared memory segment and setup a mapping. 65 * 66 * @param sm_client 67 * Connection to shared memory segment. 68 * 69 * @param perm 70 * Permissions associated with the access (RO, RW). 71 * 72 * @param startpage 73 * The start page of the mapping. 74 * 75 * @param endpage 76 * The end page of the mapping. 77 * 78 * @param mapping 79 * Out parameter respresenting the mapping. 80 * 81 * @return 82 * The KERN_SUCCESS or error code on failure. 83 */ 84 extern kern_return_t 85 exclaves_shared_memory_setup(const sharedmemorybase_segxnuaccess_s *sm_client, 86 const sharedmemorybase_perms_s perm, uint64_t startpage, uint64_t endpage, 87 sharedmemorybase_mapping_s *mapping); 88 89 /*! 90 * @function exclaves_shared_memory_teardown 91 * 92 * @abstract 93 * Teardown access to the shared memory segment and unmap. 94 * 95 * @param sm_client 96 * Connection to shared memory segment. 97 * 98 * @param mapping 99 * Pointer to the mapping. 100 * 101 * @return 102 * The KERN_SUCCESS or error code on failure. 103 */ 104 extern kern_return_t 105 exclaves_shared_memory_teardown(const sharedmemorybase_segxnuaccess_s *sm_client, 106 const sharedmemorybase_mapping_s *mapping); 107 108 /*! 109 * @function exclaves_shared_memory_map 110 * 111 * @abstract 112 * Map a range of memory into xnu. 113 * 114 * @param sm_client 115 * Connection to shared memory segment. 116 * 117 * @param mapping 118 * Pointer to the mapping. 119 * 120 * @param startpage 121 * The start page of the mapping. 122 * 123 * @param endpage 124 * The end page of the mapping. 125 * 126 * @return 127 * The KERN_SUCCESS or error code on failure. 128 */ 129 extern kern_return_t 130 exclaves_shared_memory_map(const sharedmemorybase_segxnuaccess_s *sm_client, 131 const sharedmemorybase_mapping_s *mapping, const uint64_t startpage, 132 const uint64_t endpage); 133 134 /*! 135 * @function exclaves_shared_memory_unmap 136 * 137 * @abstract 138 * Unmap a range of memory already mapped in xnu. 139 * 140 * @param sm_client 141 * Connection to shared memory segment. 142 * 143 * @param mapping 144 * Pointer to the mapping. 145 * 146 * @param startpage 147 * The start page of the mapping. 148 * 149 * @param endpage 150 * The end page of the mapping. 151 * 152 * @return 153 * The KERN_SUCCESS or error code on failure. 154 */ 155 extern kern_return_t 156 exclaves_shared_memory_unmap(const sharedmemorybase_segxnuaccess_s *sm_client, 157 const sharedmemorybase_mapping_s *mapping, const uint64_t startpage, 158 const uint64_t endpage); 159 160 /*! 161 * @function exclaves_shared_memory_iterate 162 * 163 * @abstract 164 * Iterate over the physical pages of a mapping 165 * 166 * @param sm_client 167 * Connection to shared memory segment. 168 * 169 * @param mapping 170 * Pointer to the mapping. 171 * 172 * @param startpage 173 * The start page of range to iterate over.. 174 * 175 * @param endpage 176 * The end page of range to iterate over. 177 * 178 * @param cb 179 * The callback to call for each physical page. 180 * 181 * @return 182 * The KERN_SUCCESS or error code on failure. 183 */ 184 /* BEGIN IGNORE CODESTYLE */ 185 extern kern_return_t 186 exclaves_shared_memory_iterate(const sharedmemorybase_segxnuaccess_s * sm_client, 187 const sharedmemorybase_mapping_s *mapping, uint64_t startpage, uint64_t endpage, 188 void (^cb)(uint64_t physical_address)); 189 /* END IGNORE CODESTYLE*/ 190 191 __END_DECLS 192 193 #endif /* CONFIG_EXCLAVES */ 194