xref: /xnu-8019.80.24/libkern/libkern/amfi/amfi.h (revision a325d9c4a84054e40bbe985afedcb50ab80993ea)
1 /*
2  * Copyright (c) 2020 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 #ifndef __AMFI_H
30 #define __AMFI_H
31 
32 #include <os/base.h>
33 #include <sys/cdefs.h>
34 #include <sys/types.h>
35 #include <kern/cs_blobs.h>
36 
37 #define KERN_AMFI_INTERFACE_VERSION 5
38 
39 #if XNU_KERNEL_PRIVATE
40 #define CORE_ENTITLEMENTS_I_KNOW_WHAT_IM_DOING
41 #include <CoreEntitlements/CoreEntitlementsPriv.h>
42 #endif
43 
44 typedef void (*amfi_OSEntitlements_invalidate)(void* osentitlements);
45 typedef void* (*amfi_OSEntitlements_asDict)(void* osentitlements);
46 typedef CEError_t (*amfi_OSEntitlements_query)(void* osentitlements, uint8_t cdhash[CS_CDHASH_LEN], CEQuery_t query, size_t queryLength);
47 typedef bool (*amfi_OSEntitlements_get_transmuted_blob)(void* osentitlements, const CS_GenericBlob **blob);
48 typedef bool (*amfi_OSEntitlements_get_xml_blob)(void* osentitlements, CS_GenericBlob **blob);
49 typedef bool (*amfi_get_legacy_profile_exemptions)(const uint8_t **profile, size_t *profileLength);
50 typedef bool (*amfi_get_udid)(const uint8_t **udid, size_t *udidLength);
51 typedef void* (*amfi_query_context_to_object)(CEQueryContext_t ctx);
52 
53 typedef struct _amfi {
54 	amfi_OSEntitlements_invalidate OSEntitlements_invalidate;
55 	amfi_OSEntitlements_asDict OSEntitlements_asdict;
56 	amfi_OSEntitlements_query OSEntitlements_query;
57 	amfi_OSEntitlements_get_transmuted_blob OSEntitlements_get_transmuted;
58 	amfi_OSEntitlements_get_xml_blob OSEntitlements_get_xml;
59 	coreentitlements_t CoreEntitlements;
60 	amfi_get_legacy_profile_exemptions get_legacy_profile_exemptions;
61 	amfi_get_udid get_udid;
62 	amfi_query_context_to_object query_context_to_object;
63 } amfi_t;
64 
65 __BEGIN_DECLS
66 
67 /*!
68  * @const amfi
69  * The AMFI interface that was registered.
70  */
71 extern const amfi_t *amfi;
72 
73 /*!
74  * @function amfi_interface_register
75  * Registers the AMFI kext interface for use within the kernel proper.
76  *
77  * @param mfi
78  * The interface to register.
79  *
80  * @discussion
81  * This routine may only be called once and must be called before late-const has
82  * been applied to kernel memory.
83  */
84 OS_EXPORT OS_NONNULL1
85 void
86 amfi_interface_register(const amfi_t *mfi);
87 
88 __END_DECLS
89 
90 #endif // __AMFI_H
91