2 * Copyright (c) 2018 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 * Interfaces to register the AppleImage4 interface with xnu-proper to avoid a
32 * build-time layering inversion.
34 #ifndef __IMG4_INTERFACE_H
35 #define __IMG4_INTERFACE_H
38 #include <sys/cdefs.h>
40 #if MACH_KERNEL_PRIVATE
41 #define _SYS_TYPES_H_ 1
42 #include <sys/kernel_types.h>
43 #include <sys/_types/_errno_t.h>
45 #include <sys/kernel_types.h>
46 #include <sys/types.h>
50 * We rely on img4.h's logic for either including sys/types.h or declaring
51 * errno_t ourselves. So when building the kernel, include img4.h from our
52 * external headers. Avoid this inclusion if we're building AppleImage4, which
53 * will have included its own internal version of the header.
55 #if MACH_KERNEL_PRIVATE || !_DARWIN_BUILDING_PROJECT_APPLEIMAGE4
56 #include <img4/img4.h>
60 * @const IMG4_INTERFACE_VERSION
61 * The version of the interface supported by the implementation. As new
62 * functions are added to the interface, this value will be incremented so that
63 * it can be tested at build-time and not require rev-locked submissions of xnu
66 #define IMG4_INTERFACE_VERSION (2u)
69 * @typedef img4_init_t
70 * A type describing a pointer to the {@link img4_init} function.
72 typedef errno_t (*const img4_init_t
)(
77 img4_destructor_t destructor
81 * @typedef img4_get_trusted_payload_t
82 * A type describing a pointer to the {@link img4_get_trusted_payload} function.
84 typedef errno_t (*const img4_get_trusted_payload_t
)(
87 const img4_environment_t
*env
,
88 const uint8_t **bytes
,
93 * @typedef img4_get_trusted_external_payload_t
94 * A type describing a pointer to the {@link img4_get_trusted_external_payload}
97 typedef errno_t (*const img4_get_trusted_external_payload_t
)(
99 img4_payload_t
*payload
,
100 const img4_environment_t
*env
,
101 const uint8_t **bytes
,
106 * @typedef img4_set_nonce_t
107 * A type describing a pointer to the {@link img4_set_nonce} function.
109 typedef void (*const img4_set_nonce_t
)(img4_t
*i4
,
115 * @typedef img4_destroy_t
116 * A type describing the {@link img4_destroy} function.
118 typedef void (*const img4_destroy_t
)(
123 * @typedef img4_payload_init_t
124 * A type describing the {@link img4_payload_init} function.
126 typedef errno_t (*const img4_payload_init_t
)(
129 img4_payload_flags_t flags
,
130 const uint8_t *bytes
,
132 img4_destructor_t destructor
136 * @typedef img4_payload_destroy_t
137 * A type describing the {@link img4_payload_destroy} function.
139 typedef void (*const img4_payload_destroy_t
)(
144 * @typedef img4_payload_destroy_t
145 * A type describing the {@link img4_set_nonce_domain} function.
147 typedef void (*const img4_set_nonce_domain_t
)(
149 const img4_nonce_domain_t
*nd
153 * @typedef img4_nonce_domain_copy_nonce_t
154 * A type describing the {@link img4_nonce_domain_copy_nonce} function.
156 typedef errno_t (*const img4_nonce_domain_copy_nonce_t
)(
157 const img4_nonce_domain_t
*nd
,
162 * @typedef img4_nonce_domain_roll_nonce_t
163 * A type describing the {@link img4_nonce_domain_roll_nonce} function.
165 typedef errno_t (*const img4_nonce_domain_roll_nonce_t
)(
166 const img4_nonce_domain_t
*nd
170 * @typedef img4_payload_init_with_vnode_4xnu_t
171 * A type describing the {@link img4_payload_init_with_vnode_4xnu} function.
173 typedef errno_t (*img4_payload_init_with_vnode_4xnu_t
)(
177 img4_payload_flags_t flags
181 * @typedef img4_interface_t
182 * A structure describing the interface to the AppleImage4 kext.
184 * @field i4if_version
185 * The version of the structure supported by the implementation.
188 * A pointer to the {@link img4_init} function.
190 * @field i4if_get_trusted_payload
191 * A pointer to the {@link img4_get_trusted_payload} function.
193 * @field i4if_get_trusted_external_payload
194 * A pointer to the {@link img4_get_trusted_external_payload} function.
196 * @field i4if_destroy
197 * A pointer to the {@link img4_destroy} function.
199 * @field i4if_payload_init
200 * A pointer to the {@link img4_payload_init} function.
202 * @field i4if_destroy
203 * A pointer to the {@link img4_payload_destroy} function.
205 * @field i4if_environment_platform
206 * The {@link IMG4_ENVIRONMENT_PLATFORM} global.
208 * @field i4if_environment_reserved
209 * Reserved for use by the implementation.
211 * @field i4if_environment_trust_cache
212 * The {@link IMG4_ENVIRONMENT_TRUST_CACHE} global.
215 * All fields added in version 1 of the structure.
217 * @field i4if_v1.set_nonce_domain
218 * A pointer to the @{link img4_set_nonce_domain} function.
220 * @field i4if_v1.nonce_domain_copy_nonce
221 * A pointer to the {@link img4_nonce_domain_copy_nonce} function.
223 * @field i4if_v1.nonce_domain_roll_nonce
224 * A pointer to the {@link img4_nonce_domain_roll_nonce} function.
226 * @field i4if_v1.nonce_domain_trust_cache
227 * The {@link IMG4_NONCE_DOMAIN_TRUST_CACHE} global.
230 * All fields added in version 2 of the structure.
232 * @field i4if_v2.payload_init_with_vnode_4xnu
233 * A pointer to the {@link img4_payload_init_with_vnode_4xnu} function.
236 * All fields added in version 3 of the structure.
238 * @field i4if_v3.nonce_domain_pdi
239 * The {@link IMG4_NONCE_DOMAIN_PDI} global.
241 * @field i4if_v3.nonce_domain_cryptex
242 * The {@link IMG4_NONCE_DOMAIN_CRYPTEX} global.
244 * @field i4if_v4.environment_init_identity
245 * A pointer to the {@link img4_environment_init_identity} function.
248 typedef struct _img4_interface
{
249 const uint32_t i4if_version
;
250 img4_init_t i4if_init
;
251 img4_set_nonce_t i4if_set_nonce
;
252 img4_get_trusted_payload_t i4if_get_trusted_payload
;
253 img4_get_trusted_external_payload_t i4if_get_trusted_external_payload
;
254 img4_destroy_t i4if_destroy
;
255 img4_payload_init_t i4if_payload_init
;
256 img4_payload_destroy_t i4if_payload_destroy
;
257 const img4_environment_t
*i4if_environment_platform
;
258 const img4_environment_t
*i4if_environment_reserved
;
259 const img4_environment_t
*i4if_environment_trust_cache
;
261 img4_set_nonce_domain_t set_nonce_domain
;
262 img4_nonce_domain_copy_nonce_t nonce_domain_copy_nonce
;
263 img4_nonce_domain_roll_nonce_t nonce_domain_roll_nonce
;
264 const img4_nonce_domain_t
*nonce_domain_trust_cache
;
267 img4_payload_init_with_vnode_4xnu_t payload_init_with_vnode_4xnu
;
269 void *__reserved
[17];
276 * The AppleImage4 interface that was registered.
278 extern const img4_interface_t
*img4if
;
281 * @function img4_interface_register
282 * Registers the AppleImage4 kext interface for use within the kernel proper.
285 * The interface to register.
288 * This routine may only be called once and must be called before late-const has
289 * been applied to kernel memory.
291 OS_EXPORT OS_NONNULL1
293 img4_interface_register(const img4_interface_t
*i4
);
297 #endif // __IMG4_INTERFACE_H