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