xref: /xnu-11215.61.5/libkern/libkern/image4/dlxk.h (revision 4f1223e81cd707a65cc109d0b8ad6653699da3c4)
1 /*
2  * Copyright © 2017-2024 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  * @header
30  * Kernel-private interfaces to link the upward-exported AppleImage4 API. This
31  * header serves as an umbrella header to enforce inclusion ordering among its
32  * associated headers.
33  *
34  * This file is intended for use in the xnu project.
35  */
36 #ifndef __IMAGE4_DLXK_H
37 #define __IMAGE4_DLXK_H
38 
39 #define __IMAGE4_XNU_INDIRECT 1
40 #include <image4/image4.h>
41 #include <image4/types.h>
42 #include <image4/coprocessor.h>
43 #include <image4/environment.h>
44 #include <image4/trust.h>
45 #include <image4/trust_evaluation.h>
46 #include <image4/cs/traps.h>
47 
48 #if XNU_KERNEL_PRIVATE
49 #include <libkern/image4/interface.h>
50 #include <libkern/image4/api.h>
51 #else
52 #include <image4/dlxk/interface.h>
53 #endif
54 
55 __BEGIN_DECLS
56 OS_ASSUME_NONNULL_BEGIN
57 OS_ASSUME_PTR_ABI_SINGLE_BEGIN
58 
59 #pragma mark Definitions
60 /*!
61  * @const IMAGE4_DLXK_VERSION
62  * The API version of the upward-ish-linked kernel interface structure. The
63  * kernel cannot directly call into kext exports, so the kext instead provides a
64  * structure of function pointers and registers that structure with the kernel
65  * at boot.
66  */
67 #define IMAGE4_DLXK_VERSION (2u)
68 
69 #pragma mark KPI
70 /*!
71  * @function image4_dlxk_link
72  * Links the interface exported by the AppleImage4 kext via the given structure
73  * so that the kernel-proper can use it via the trampolines provided in
74  * image4/dlxk/api.h.
75  *
76  * @param dlxk
77  * The interface to link.
78  *
79  * @discussion
80  * This routine may only be called once and must be called prior to machine
81  * lockdown.
82  */
83 OS_EXPORT OS_NONNULL1
84 void
85 image4_dlxk_link(const image4_dlxk_interface_t *dlxk);
86 
87 /*!
88  * @function image4_dlxk_get
89  * Returns the interface structure which was linked at boot.
90  *
91  * @param v
92  * The minimum required version. If the structure's version does not satisfy
93  * this constraint, NULL is returned.
94  *
95  * @result
96  * The interface structure which was linked at boot. If no structure was
97  * registered at boot, or if the registered structure's version is less than
98  * the version specified, NULL is returned.
99  */
100 OS_EXPORT OS_WARN_RESULT
101 const image4_dlxk_interface_t *_Nullable
102 image4_dlxk_get(image4_struct_version_t v);
103 
104 OS_ASSUME_PTR_ABI_SINGLE_END
105 OS_ASSUME_NONNULL_END
106 __END_DECLS
107 
108 #endif // __IMAGE4_DLXK_H
109