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