xref: /xnu-10002.1.13/EXTERNAL_HEADERS/CoreEntitlements/Runtime.h (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a)
1*1031c584SApple OSS Distributions //
2*1031c584SApple OSS Distributions //  Runtime.h
3*1031c584SApple OSS Distributions //  CoreEntitlements
4*1031c584SApple OSS Distributions //
5*1031c584SApple OSS Distributions //
6*1031c584SApple OSS Distributions 
7*1031c584SApple OSS Distributions #ifndef CORE_ENTITLEMENTS_RUNTIME_H
8*1031c584SApple OSS Distributions #define CORE_ENTITLEMENTS_RUNTIME_H
9*1031c584SApple OSS Distributions 
10*1031c584SApple OSS Distributions #ifndef _CE_INDIRECT
11*1031c584SApple OSS Distributions #error "Please include <CoreEntitlements/CoreEntitlements.h> instead of this file"
12*1031c584SApple OSS Distributions #endif
13*1031c584SApple OSS Distributions 
14*1031c584SApple OSS Distributions #include <stdint.h>
15*1031c584SApple OSS Distributions #include <stddef.h>
16*1031c584SApple OSS Distributions #include <stdbool.h>
17*1031c584SApple OSS Distributions 
18*1031c584SApple OSS Distributions __ptrcheck_abi_assume_single();
19*1031c584SApple OSS Distributions 
20*1031c584SApple OSS Distributions #define CE_MAX_KEY_SIZE 240
21*1031c584SApple OSS Distributions 
22*1031c584SApple OSS Distributions #ifndef __result_use_check
23*1031c584SApple OSS Distributions #define __result_use_check
24*1031c584SApple OSS Distributions #endif
25*1031c584SApple OSS Distributions 
26*1031c584SApple OSS Distributions #define CE_RUNTIME_VERSION 1
27*1031c584SApple OSS Distributions #define CE_RUNTIME_WITH_INDEX_VERSION 2
28*1031c584SApple OSS Distributions 
29*1031c584SApple OSS Distributions /*!
30*1031c584SApple OSS Distributions  * @struct CEBuffer
31*1031c584SApple OSS Distributions  * Represents a sized chunk of DER data
32*1031c584SApple OSS Distributions  * Strings and blobs used and returned by CoreEntitlements always use CEBuffer
33*1031c584SApple OSS Distributions  *
34*1031c584SApple OSS Distributions  * @note
35*1031c584SApple OSS Distributions  * If a DER string is returned to you via a CEBuffer, you cannot assume it is null-terminated.
36*1031c584SApple OSS Distributions  */
37*1031c584SApple OSS Distributions typedef struct {
38*1031c584SApple OSS Distributions     const uint8_t *__counted_by(length) data;
39*1031c584SApple OSS Distributions     size_t length;
40*1031c584SApple OSS Distributions } CEBuffer;
41*1031c584SApple OSS Distributions 
42*1031c584SApple OSS Distributions /*!
43*1031c584SApple OSS Distributions  * @struct CEStaticBuffer
44*1031c584SApple OSS Distributions  * Represents a sized chunk of data that is stored inline
45*1031c584SApple OSS Distributions  */
46*1031c584SApple OSS Distributions typedef struct {
47*1031c584SApple OSS Distributions     uint8_t data[CE_MAX_KEY_SIZE];
48*1031c584SApple OSS Distributions     size_t length;
49*1031c584SApple OSS Distributions } CEStaticBuffer;
50*1031c584SApple OSS Distributions 
51*1031c584SApple OSS Distributions #define CEBuffStr(str) (CEBuffer){.data = (const uint8_t*)str, .length = sizeof(str) - 1}
52*1031c584SApple OSS Distributions 
53*1031c584SApple OSS Distributions /*!
54*1031c584SApple OSS Distributions  * @typedef CERuntimeMalloc
55*1031c584SApple OSS Distributions  * Function prototype that the CERuntime may ues to allocate data (e.g.. malloc)
56*1031c584SApple OSS Distributions  */
57*1031c584SApple OSS Distributions typedef void* __unsafe_indexable (*CERuntimeMalloc)(const CERuntime_t rt, size_t size) __result_use_check;
58*1031c584SApple OSS Distributions /*!
59*1031c584SApple OSS Distributions  * @typedef CERuntimeFree
60*1031c584SApple OSS Distributions  * Function prototype that the CERuntime may ues to free allocated data (e.g. free)
61*1031c584SApple OSS Distributions  */
62*1031c584SApple OSS Distributions typedef void (*CERuntimeFree)(const CERuntime_t rt, void* address);
63*1031c584SApple OSS Distributions /*!
64*1031c584SApple OSS Distributions  * @typedef CERuntimeLog
65*1031c584SApple OSS Distributions  * Function prototype that the CERuntime may use to log helpful information (e.g. printf)
66*1031c584SApple OSS Distributions  */
67*1031c584SApple OSS Distributions typedef void (*CERuntimeLog)(const CERuntime_t rt, const char* __unsafe_indexable fmt, ...) __printflike(2, 3);
68*1031c584SApple OSS Distributions /*!
69*1031c584SApple OSS Distributions  * @typedef CERuntimeAbort
70*1031c584SApple OSS Distributions  * Function prototype that the CERuntime will use if it encounters a condition which may compromise the integrity of the system (e.g. abort, panic)
71*1031c584SApple OSS Distributions  */
72*1031c584SApple OSS Distributions typedef void (*CERuntimeAbort)(const CERuntime_t rt, const char* __unsafe_indexable fmt, ...) __printflike(2, 3) __attribute__((noreturn));
73*1031c584SApple OSS Distributions /*!
74*1031c584SApple OSS Distributions  * @typedef CERuntimeInternalStatus
75*1031c584SApple OSS Distributions  * Function prototype that the CERuntime may use to query AppleInternal status
76*1031c584SApple OSS Distributions  */
77*1031c584SApple OSS Distributions typedef bool (*CERuntimeInternalStatus)(const CERuntime_t rt);
78*1031c584SApple OSS Distributions 
79*1031c584SApple OSS Distributions /*!
80*1031c584SApple OSS Distributions  * @typedef CERuntimeAllocIndex
81*1031c584SApple OSS Distributions  * Function prototype that the CERuntime may ues to allocate an index of the specified size
82*1031c584SApple OSS Distributions  */
83*1031c584SApple OSS Distributions typedef void* __unsafe_indexable (*CERuntimeAllocIndex)(const CERuntime_t rt, size_t size) __result_use_check;
84*1031c584SApple OSS Distributions 
85*1031c584SApple OSS Distributions /*!
86*1031c584SApple OSS Distributions  * @typedef CERuntimeFreeIndex
87*1031c584SApple OSS Distributions  * Function prototype that the CERuntime may ues to free an index of the specified size
88*1031c584SApple OSS Distributions  */
89*1031c584SApple OSS Distributions typedef void (*CERuntimeFreeIndex)(const CERuntime_t rt, void* index, size_t size);
90*1031c584SApple OSS Distributions 
91*1031c584SApple OSS Distributions /*!
92*1031c584SApple OSS Distributions  * @struct CERuntime
93*1031c584SApple OSS Distributions  * This structure represents the interface that CoreEntitlements uses to communicate with the outside world.
94*1031c584SApple OSS Distributions  * The presense or absence of function pointers in this structure may degrade certain functionality.
95*1031c584SApple OSS Distributions  *
96*1031c584SApple OSS Distributions  * @note
97*1031c584SApple OSS Distributions  * The only prototype that MUST be implemented is CERuntimeAbort abort.
98*1031c584SApple OSS Distributions  */
99*1031c584SApple OSS Distributions struct CERuntime {
100*1031c584SApple OSS Distributions     const uint64_t                  version;
101*1031c584SApple OSS Distributions     const CERuntimeMalloc           alloc;
102*1031c584SApple OSS Distributions     const CERuntimeFree             free;
103*1031c584SApple OSS Distributions     const CERuntimeLog              log;
104*1031c584SApple OSS Distributions     const CERuntimeAbort            abort;
105*1031c584SApple OSS Distributions     const CERuntimeInternalStatus   internalStatus;
106*1031c584SApple OSS Distributions     const CERuntimeAllocIndex       allocIndex;
107*1031c584SApple OSS Distributions     const CERuntimeFreeIndex        freeIndex;
108*1031c584SApple OSS Distributions } ;
109*1031c584SApple OSS Distributions 
110*1031c584SApple OSS Distributions #endif
111