xref: /xnu-8796.121.2/EXTERNAL_HEADERS/TrustCache/Return.h (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1 #ifndef libTrustCache_Return_h
2 #define libTrustCache_Return_h
3 
4 #include <sys/cdefs.h>
5 __BEGIN_DECLS
6 
7 #include <stdint.h>
8 
9 /* Components which can return information from the library */
10 enum {
11     kTCComponentLoadModule = 0x00,
12     kTCComponentLoad = 0x01,
13     kTCComponentImage4Validate = 0x02,
14     kTCComponentImage4Callback = 0x03,
15     kTCComponentConstructInvalid = 0x04,
16     kTCComponentCheckRuntimeForUUID = 0x05,
17     kTCComponentExtractModule = 0x06,
18     kTCComponentGetUUID = 0x07,
19     kTCComponentGetModule = 0x08,
20 
21     /* Query Functions */
22     kTCComponentQuery = 0x10,
23     kTCComponentQueryChain = 0x11,
24     kTCComponentQueryRuntime = 0x12,
25     kTCComponentQueryTCType = 0x13,
26     kTCComponentQueryHashType = 0x14,
27     kTCComponentQueryFlags = 0x15,
28     kTCComponentQueryConstraintCategory = 0x16,
29 
30     /* Module based */
31     kTCComponentQueryModule = 0x40,
32     kTCComponentValidateModule = 0x41,
33     kTCComponentQueryModule0 = 0x42,
34     kTCComponentValidateModule0 = 0x43,
35     kTCComponentQueryModule1 = 0x44,
36     kTCComponentValidateModule1 = 0x45,
37     kTCComponentQueryModule2 = 0x46,
38     kTCComponentValidateModule2 = 0x47,
39     kTCComponentModuleCapabilities = 0x48,
40 
41     /* Other functions which can return a value */
42     kTCComponentLinkedListAddHead = 0x80,
43     kTCComponentLinkedListRemove = 0x81,
44     kTCComponentExtractImage4Payload = 0x82,
45 
46     /* Cannot exceed this value */
47     kTCComponentTotal = 0xFF,
48 };
49 
50 /* Error types which can be returned from the library */
51 enum {
52     kTCReturnSuccess = 0x00,
53 
54     /* Generic error condition - avoid using this */
55     kTCReturnError = 0x01,
56 
57     /* Specific error conditions */
58     kTCReturnOverflow = 0x20,
59     kTCReturnUnsupported = 0x21,
60     kTCReturnInvalidModule = 0x22,
61     kTCReturnDuplicate = 0x23,
62     kTCReturnNotFound = 0x24,
63     kTCReturnInvalidArguments = 0x25,
64     kTCReturnInsufficientLength = 0x26,
65     kTCReturnNotPermitted = 0x27,
66     kTCReturnLinkedListCorrupted = 0x28,
67 
68     /* Image 4 return errors */
69     kTCReturnImage4Expired = 0xA0,
70     kTCReturnImage4UnknownFormat = 0xA1,
71     kTCReturnImage4WrongObject = 0xA2,
72     kTCReturnImage4WrongCrypto = 0xA3,
73     kTCReturnImage4ManifestViolation = 0xA4,
74     kTCReturnImage4PayloadViolation = 0xA5,
75     kTCReturnImage4PermissionDenied = 0xA6,
76     kTCReturnImage4NoChipAvailable = 0xA7,
77     kTCReturnImage4NoNonceAvailable = 0xA8,
78     kTCReturnImage4NoDeviceAvailable = 0xA9,
79     kTCReturnImage4DecodeError = 0xAA,
80     kTCReturnImage4UnknownError = 0xAF,
81 
82     /* Cannot exceed this value */
83     kTCReturnTotal = 0xFF
84 };
85 
86 typedef struct _TCReturn {
87     union {
88         /* Raw 32 bit representation of the return code */
89         uint32_t rawValue;
90 
91         /* Formatted representation of the return code */
92         struct {
93             /* Component of the library which is returning the code */
94             uint8_t component;
95 
96             /* Error code which is being returned */
97             uint8_t error;
98 
99             /* Unique error path within the component */
100             uint16_t uniqueError;
101         } __attribute__((packed));
102     } __attribute__((packed));
103 } __attribute__((packed)) TCReturn_t;
104 
105 /* Ensure the size of the structure remains as expected */
106 _Static_assert(sizeof(TCReturn_t) == sizeof(uint32_t), "TCReturn_t is not 32 bits large");
107 
108 static inline TCReturn_t
buildTCRet(uint8_t component,uint8_t error,uint16_t uniqueError)109 buildTCRet(uint8_t component,
110            uint8_t error,
111            uint16_t uniqueError)
112 {
113     TCReturn_t ret = {
114         .component = component,
115         .error = error,
116         .uniqueError = uniqueError
117     };
118 
119     return ret;
120 }
121 
122 __END_DECLS
123 #endif /* libTrustCache_Return_h */
124