xref: /xnu-11215.61.5/EXTERNAL_HEADERS/ptrauth.h (revision 4f1223e81cd707a65cc109d0b8ad6653699da3c4)
1*4f1223e8SApple OSS Distributions /*===---- ptrauth.h - Pointer authentication -------------------------------===
2*4f1223e8SApple OSS Distributions  *
3*4f1223e8SApple OSS Distributions  * Permission is hereby granted, free of charge, to any person obtaining a copy
4*4f1223e8SApple OSS Distributions  * of this software and associated documentation files (the "Software"), to deal
5*4f1223e8SApple OSS Distributions  * in the Software without restriction, including without limitation the rights
6*4f1223e8SApple OSS Distributions  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*4f1223e8SApple OSS Distributions  * copies of the Software, and to permit persons to whom the Software is
8*4f1223e8SApple OSS Distributions  * furnished to do so, subject to the following conditions:
9*4f1223e8SApple OSS Distributions  *
10*4f1223e8SApple OSS Distributions  * The above copyright notice and this permission notice shall be included in
11*4f1223e8SApple OSS Distributions  * all copies or substantial portions of the Software.
12*4f1223e8SApple OSS Distributions  *
13*4f1223e8SApple OSS Distributions  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*4f1223e8SApple OSS Distributions  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*4f1223e8SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16*4f1223e8SApple OSS Distributions  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17*4f1223e8SApple OSS Distributions  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18*4f1223e8SApple OSS Distributions  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19*4f1223e8SApple OSS Distributions  * THE SOFTWARE.
20*4f1223e8SApple OSS Distributions  *
21*4f1223e8SApple OSS Distributions  *===-----------------------------------------------------------------------===
22*4f1223e8SApple OSS Distributions  */
23*4f1223e8SApple OSS Distributions 
24*4f1223e8SApple OSS Distributions #ifndef __PTRAUTH_H
25*4f1223e8SApple OSS Distributions #define __PTRAUTH_H
26*4f1223e8SApple OSS Distributions 
27*4f1223e8SApple OSS Distributions #include <stdint.h>
28*4f1223e8SApple OSS Distributions 
29*4f1223e8SApple OSS Distributions typedef enum {
30*4f1223e8SApple OSS Distributions   ptrauth_key_asia = 0,
31*4f1223e8SApple OSS Distributions   ptrauth_key_asib = 1,
32*4f1223e8SApple OSS Distributions   ptrauth_key_asda = 2,
33*4f1223e8SApple OSS Distributions   ptrauth_key_asdb = 3,
34*4f1223e8SApple OSS Distributions 
35*4f1223e8SApple OSS Distributions   /* A process-independent key which can be used to sign code pointers.
36*4f1223e8SApple OSS Distributions      Signing and authenticating with this key is a no-op in processes
37*4f1223e8SApple OSS Distributions      which disable ABI pointer authentication. */
38*4f1223e8SApple OSS Distributions   ptrauth_key_process_independent_code = ptrauth_key_asia,
39*4f1223e8SApple OSS Distributions 
40*4f1223e8SApple OSS Distributions   /* A process-specific key which can be used to sign code pointers.
41*4f1223e8SApple OSS Distributions      Signing and authenticating with this key is enforced even in processes
42*4f1223e8SApple OSS Distributions      which disable ABI pointer authentication. */
43*4f1223e8SApple OSS Distributions   ptrauth_key_process_dependent_code = ptrauth_key_asib,
44*4f1223e8SApple OSS Distributions 
45*4f1223e8SApple OSS Distributions   /* A process-independent key which can be used to sign data pointers.
46*4f1223e8SApple OSS Distributions      Signing and authenticating with this key is a no-op in processes
47*4f1223e8SApple OSS Distributions      which disable ABI pointer authentication. */
48*4f1223e8SApple OSS Distributions   ptrauth_key_process_independent_data = ptrauth_key_asda,
49*4f1223e8SApple OSS Distributions 
50*4f1223e8SApple OSS Distributions   /* A process-specific key which can be used to sign data pointers.
51*4f1223e8SApple OSS Distributions      Signing and authenticating with this key is a no-op in processes
52*4f1223e8SApple OSS Distributions      which disable ABI pointer authentication. */
53*4f1223e8SApple OSS Distributions   ptrauth_key_process_dependent_data = ptrauth_key_asdb,
54*4f1223e8SApple OSS Distributions 
55*4f1223e8SApple OSS Distributions   /* The key used to sign C function pointers.
56*4f1223e8SApple OSS Distributions      The extra data is always 0. */
57*4f1223e8SApple OSS Distributions   ptrauth_key_function_pointer = ptrauth_key_process_independent_code,
58*4f1223e8SApple OSS Distributions 
59*4f1223e8SApple OSS Distributions   /* The key used to sign return addresses on the stack.
60*4f1223e8SApple OSS Distributions      The extra data is based on the storage address of the return address.
61*4f1223e8SApple OSS Distributions      On ARM64, that is always the storage address of the return address plus 8
62*4f1223e8SApple OSS Distributions      (or, in other words, the value of the stack pointer on function entry) */
63*4f1223e8SApple OSS Distributions   ptrauth_key_return_address = ptrauth_key_process_dependent_code,
64*4f1223e8SApple OSS Distributions 
65*4f1223e8SApple OSS Distributions   /* The key used to sign frame pointers on the stack.
66*4f1223e8SApple OSS Distributions      The extra data is based on the storage address of the frame pointer.
67*4f1223e8SApple OSS Distributions      On ARM64, that is always the storage address of the frame pointer plus 16
68*4f1223e8SApple OSS Distributions      (or, in other words, the value of the stack pointer on function entry) */
69*4f1223e8SApple OSS Distributions   ptrauth_key_frame_pointer = ptrauth_key_process_dependent_data,
70*4f1223e8SApple OSS Distributions 
71*4f1223e8SApple OSS Distributions   /* The key used to sign block function pointers, including:
72*4f1223e8SApple OSS Distributions        invocation functions,
73*4f1223e8SApple OSS Distributions        block object copy functions,
74*4f1223e8SApple OSS Distributions        block object destroy functions,
75*4f1223e8SApple OSS Distributions        __block variable copy functions, and
76*4f1223e8SApple OSS Distributions        __block variable destroy functions.
77*4f1223e8SApple OSS Distributions      The extra data is always the address at which the function pointer
78*4f1223e8SApple OSS Distributions      is stored.
79*4f1223e8SApple OSS Distributions 
80*4f1223e8SApple OSS Distributions      Note that block object pointers themselves (i.e. the direct
81*4f1223e8SApple OSS Distributions      representations of values of block-pointer type) are not signed. */
82*4f1223e8SApple OSS Distributions   ptrauth_key_block_function = ptrauth_key_asia,
83*4f1223e8SApple OSS Distributions 
84*4f1223e8SApple OSS Distributions   /* The key used to sign C++ v-table pointers.
85*4f1223e8SApple OSS Distributions      The extra data is always 0. */
86*4f1223e8SApple OSS Distributions   ptrauth_key_cxx_vtable_pointer = ptrauth_key_asda,
87*4f1223e8SApple OSS Distributions 
88*4f1223e8SApple OSS Distributions   /* Other pointers signed under the ABI use private ABI rules. */
89*4f1223e8SApple OSS Distributions 
90*4f1223e8SApple OSS Distributions } ptrauth_key;
91*4f1223e8SApple OSS Distributions 
92*4f1223e8SApple OSS Distributions /* An integer type of the appropriate size for an extra-data argument. */
93*4f1223e8SApple OSS Distributions typedef uintptr_t ptrauth_extra_data_t;
94*4f1223e8SApple OSS Distributions 
95*4f1223e8SApple OSS Distributions /* An integer type of the appropriate size for a generic signature. */
96*4f1223e8SApple OSS Distributions typedef uintptr_t ptrauth_generic_signature_t;
97*4f1223e8SApple OSS Distributions 
98*4f1223e8SApple OSS Distributions /* A signed pointer value embeds the original pointer together with
99*4f1223e8SApple OSS Distributions    a signature that attests to the validity of that pointer.  Because
100*4f1223e8SApple OSS Distributions    this signature must use only "spare" bits of the pointer, a
101*4f1223e8SApple OSS Distributions    signature's validity is probabilistic in practice: it is unlikely
102*4f1223e8SApple OSS Distributions    but still plausible that an invalidly-derived signature will
103*4f1223e8SApple OSS Distributions    somehow equal the correct signature and therefore successfully
104*4f1223e8SApple OSS Distributions    authenticate.  Nonetheless, this scheme provides a strong degree
105*4f1223e8SApple OSS Distributions    of protection against certain kinds of attacks. */
106*4f1223e8SApple OSS Distributions 
107*4f1223e8SApple OSS Distributions /* Authenticating a pointer that was not signed with the given key
108*4f1223e8SApple OSS Distributions    and extra-data value will (likely) fail.  However, an
109*4f1223e8SApple OSS Distributions    authentication failure will not lead immediately to a trap.
110*4f1223e8SApple OSS Distributions    Instead, it will yield a value which is guaranteed to trap
111*4f1223e8SApple OSS Distributions    if actually dereferenced. */
112*4f1223e8SApple OSS Distributions 
113*4f1223e8SApple OSS Distributions /* The null function pointer is always the all-zero bit pattern.
114*4f1223e8SApple OSS Distributions    Signing an all-zero bit pattern will embed a (likely) non-zero
115*4f1223e8SApple OSS Distributions    signature in the result, and so the result will not seem to be
116*4f1223e8SApple OSS Distributions    a null function pointer.  Authenticating this value will yield
117*4f1223e8SApple OSS Distributions    a null function pointer back.  However, authenticating an
118*4f1223e8SApple OSS Distributions    all-zero bit pattern will probably fail, because the
119*4f1223e8SApple OSS Distributions    authentication will expect a (likely) non-zero signature to
120*4f1223e8SApple OSS Distributions    embedded in the value.
121*4f1223e8SApple OSS Distributions 
122*4f1223e8SApple OSS Distributions    Because of this, if a pointer may validly be null, you should
123*4f1223e8SApple OSS Distributions    check for null before attempting to authenticate it. */
124*4f1223e8SApple OSS Distributions 
125*4f1223e8SApple OSS Distributions #ifdef __PTRAUTH_INTRINSICS__
126*4f1223e8SApple OSS Distributions 
127*4f1223e8SApple OSS Distributions /* Strip the signature from a value without authenticating it.
128*4f1223e8SApple OSS Distributions 
129*4f1223e8SApple OSS Distributions    If the value is a function pointer, the result will not be a
130*4f1223e8SApple OSS Distributions    legal function pointer because of the missing signature, and
131*4f1223e8SApple OSS Distributions    attempting to call it will result in an authentication failure.
132*4f1223e8SApple OSS Distributions 
133*4f1223e8SApple OSS Distributions    The value must be an expression of pointer type.
134*4f1223e8SApple OSS Distributions    The key must be a constant expression of type ptrauth_key.
135*4f1223e8SApple OSS Distributions    The result will have the same type as the original value. */
136*4f1223e8SApple OSS Distributions #define ptrauth_strip(__value, __key) \
137*4f1223e8SApple OSS Distributions   __builtin_ptrauth_strip(__value, __key)
138*4f1223e8SApple OSS Distributions 
139*4f1223e8SApple OSS Distributions /* Blend a pointer and a small integer to form a new extra-data
140*4f1223e8SApple OSS Distributions    discriminator.  Not all bits of the inputs are guaranteed to
141*4f1223e8SApple OSS Distributions    contribute to the result.
142*4f1223e8SApple OSS Distributions 
143*4f1223e8SApple OSS Distributions    On ARM64, only the low 16 bits of the integer will be considered.
144*4f1223e8SApple OSS Distributions 
145*4f1223e8SApple OSS Distributions    For the purposes of ptrauth_sign_constant, the result of calling
146*4f1223e8SApple OSS Distributions    this function is considered a constant expression if the arguments
147*4f1223e8SApple OSS Distributions    are constant.  Some restrictions may be imposed on the pointer.
148*4f1223e8SApple OSS Distributions 
149*4f1223e8SApple OSS Distributions    The first argument must be an expression of pointer type.
150*4f1223e8SApple OSS Distributions    The second argument must be an expression of integer type.
151*4f1223e8SApple OSS Distributions    The result will have type uintptr_t. */
152*4f1223e8SApple OSS Distributions #define ptrauth_blend_discriminator(__pointer, __integer) \
153*4f1223e8SApple OSS Distributions   __builtin_ptrauth_blend_discriminator(__pointer, __integer)
154*4f1223e8SApple OSS Distributions 
155*4f1223e8SApple OSS Distributions /* Compute the 16-bit integer discriminator of the given type.
156*4f1223e8SApple OSS Distributions 
157*4f1223e8SApple OSS Distributions    The argument must be a type.
158*4f1223e8SApple OSS Distributions */
159*4f1223e8SApple OSS Distributions #if __has_builtin(__builtin_ptrauth_type_discriminator)
160*4f1223e8SApple OSS Distributions #define ptrauth_type_discriminator(__type) \
161*4f1223e8SApple OSS Distributions   __builtin_ptrauth_type_discriminator(__type)
162*4f1223e8SApple OSS Distributions #else
163*4f1223e8SApple OSS Distributions #define ptrauth_type_discriminator(__type) ((uintptr_t)0)
164*4f1223e8SApple OSS Distributions #endif
165*4f1223e8SApple OSS Distributions 
166*4f1223e8SApple OSS Distributions /* Compute the constant discriminator used by Clang to sign pointers with the
167*4f1223e8SApple OSS Distributions    given C function pointer type.
168*4f1223e8SApple OSS Distributions 
169*4f1223e8SApple OSS Distributions    A call to this function is an integer constant expression*/
170*4f1223e8SApple OSS Distributions #if __has_feature(ptrauth_function_pointer_type_discrimination)
171*4f1223e8SApple OSS Distributions #define ptrauth_function_pointer_type_discriminator(__type) \
172*4f1223e8SApple OSS Distributions   __builtin_ptrauth_type_discriminator(__type)
173*4f1223e8SApple OSS Distributions #else
174*4f1223e8SApple OSS Distributions #define ptrauth_function_pointer_type_discriminator(__type) ((uintptr_t)0)
175*4f1223e8SApple OSS Distributions #endif
176*4f1223e8SApple OSS Distributions 
177*4f1223e8SApple OSS Distributions /* Add a signature to the given pointer value using a specific key,
178*4f1223e8SApple OSS Distributions    using the given extra data as a salt to the signing process.
179*4f1223e8SApple OSS Distributions 
180*4f1223e8SApple OSS Distributions    The value must be a constant expression of pointer type.
181*4f1223e8SApple OSS Distributions    The key must be a constant expression of type ptrauth_key.
182*4f1223e8SApple OSS Distributions    The extra data must be a constant expression of pointer or integer type;
183*4f1223e8SApple OSS Distributions    if an integer, it will be coerced to ptrauth_extra_data_t.
184*4f1223e8SApple OSS Distributions    The result will have the same type as the original value.
185*4f1223e8SApple OSS Distributions 
186*4f1223e8SApple OSS Distributions    This is a constant expression if the extra data is an integer or
187*4f1223e8SApple OSS Distributions    null pointer constant. */
188*4f1223e8SApple OSS Distributions #define ptrauth_sign_constant(__value, __key, __data) \
189*4f1223e8SApple OSS Distributions   __builtin_ptrauth_sign_constant(__value, __key, __data)
190*4f1223e8SApple OSS Distributions 
191*4f1223e8SApple OSS Distributions /* Add a signature to the given pointer value using a specific key,
192*4f1223e8SApple OSS Distributions    using the given extra data as a salt to the signing process.
193*4f1223e8SApple OSS Distributions 
194*4f1223e8SApple OSS Distributions    This operation does not authenticate the original value and is
195*4f1223e8SApple OSS Distributions    therefore potentially insecure if an attacker could possibly
196*4f1223e8SApple OSS Distributions    control that value.
197*4f1223e8SApple OSS Distributions 
198*4f1223e8SApple OSS Distributions    The value must be an expression of pointer type.
199*4f1223e8SApple OSS Distributions    The key must be a constant expression of type ptrauth_key.
200*4f1223e8SApple OSS Distributions    The extra data must be an expression of pointer or integer type;
201*4f1223e8SApple OSS Distributions    if an integer, it will be coerced to ptrauth_extra_data_t.
202*4f1223e8SApple OSS Distributions    The result will have the same type as the original value. */
203*4f1223e8SApple OSS Distributions #define ptrauth_sign_unauthenticated(__value, __key, __data) \
204*4f1223e8SApple OSS Distributions   __builtin_ptrauth_sign_unauthenticated(__value, __key, __data)
205*4f1223e8SApple OSS Distributions 
206*4f1223e8SApple OSS Distributions /* Authenticate a pointer using one scheme and resign it using another.
207*4f1223e8SApple OSS Distributions 
208*4f1223e8SApple OSS Distributions    If the result is subsequently authenticated using the new scheme, that
209*4f1223e8SApple OSS Distributions    authentication is guaranteed to fail if and only if the initial
210*4f1223e8SApple OSS Distributions    authentication failed.
211*4f1223e8SApple OSS Distributions 
212*4f1223e8SApple OSS Distributions    The value must be an expression of pointer type.
213*4f1223e8SApple OSS Distributions    The key must be a constant expression of type ptrauth_key.
214*4f1223e8SApple OSS Distributions    The extra data must be an expression of pointer or integer type;
215*4f1223e8SApple OSS Distributions    if an integer, it will be coerced to ptrauth_extra_data_t.
216*4f1223e8SApple OSS Distributions    The result will have the same type as the original value.
217*4f1223e8SApple OSS Distributions 
218*4f1223e8SApple OSS Distributions    This operation is guaranteed to not leave the intermediate value
219*4f1223e8SApple OSS Distributions    available for attack before it is re-signed.
220*4f1223e8SApple OSS Distributions 
221*4f1223e8SApple OSS Distributions    Do not pass a null pointer to this function. A null pointer
222*4f1223e8SApple OSS Distributions    will not successfully authenticate. */
223*4f1223e8SApple OSS Distributions #define ptrauth_auth_and_resign(__value, __old_key, __old_data, __new_key, __new_data) \
224*4f1223e8SApple OSS Distributions   __builtin_ptrauth_auth_and_resign(__value, __old_key, __old_data, __new_key, __new_data)
225*4f1223e8SApple OSS Distributions 
226*4f1223e8SApple OSS Distributions /* Authenticate a pointer using one scheme and resign it as a C
227*4f1223e8SApple OSS Distributions    function pointer.
228*4f1223e8SApple OSS Distributions 
229*4f1223e8SApple OSS Distributions    If the result is subsequently authenticated using the new scheme, that
230*4f1223e8SApple OSS Distributions    authentication is guaranteed to fail if and only if the initial
231*4f1223e8SApple OSS Distributions    authentication failed.
232*4f1223e8SApple OSS Distributions 
233*4f1223e8SApple OSS Distributions    The value must be an expression of function pointer type.
234*4f1223e8SApple OSS Distributions    The key must be a constant expression of type ptrauth_key.
235*4f1223e8SApple OSS Distributions    The extra data must be an expression of pointer or integer type;
236*4f1223e8SApple OSS Distributions    if an integer, it will be coerced to ptrauth_extra_data_t.
237*4f1223e8SApple OSS Distributions    The result will have the same type as the original value.
238*4f1223e8SApple OSS Distributions 
239*4f1223e8SApple OSS Distributions    This operation is guaranteed to not leave the intermediate value
240*4f1223e8SApple OSS Distributions    available for attack before it is re-signed. Additionally, if this
241*4f1223e8SApple OSS Distributions    expression is used syntactically as the function expression in a
242*4f1223e8SApple OSS Distributions    call, only a single authentication will be performed. */
243*4f1223e8SApple OSS Distributions #define ptrauth_auth_function(__value, __old_key, __old_data) \
244*4f1223e8SApple OSS Distributions   ptrauth_auth_and_resign(__value, __old_key, __old_data, ptrauth_key_function_pointer, 0)
245*4f1223e8SApple OSS Distributions 
246*4f1223e8SApple OSS Distributions /* Cast a pointer to the given type without changing any signature.
247*4f1223e8SApple OSS Distributions 
248*4f1223e8SApple OSS Distributions    The type must have the same size as a pointer type.
249*4f1223e8SApple OSS Distributions    The type of value must have the same size as a pointer type, and will be
250*4f1223e8SApple OSS Distributions    converted to an rvalue prior to the cast.
251*4f1223e8SApple OSS Distributions    The result has type given by the first argument.
252*4f1223e8SApple OSS Distributions 
253*4f1223e8SApple OSS Distributions    The result has an identical bit-pattern to the input pointer. */
254*4f1223e8SApple OSS Distributions #define ptrauth_nop_cast(__type, __value)        \
255*4f1223e8SApple OSS Distributions   ({ union {                                     \
256*4f1223e8SApple OSS Distributions       typeof(__value) __fptr;                    \
257*4f1223e8SApple OSS Distributions       typeof(__type) __opaque;                   \
258*4f1223e8SApple OSS Distributions   } __storage;                                   \
259*4f1223e8SApple OSS Distributions   __storage.__fptr = (__value);                  \
260*4f1223e8SApple OSS Distributions   __storage.__opaque; })
261*4f1223e8SApple OSS Distributions 
262*4f1223e8SApple OSS Distributions /* Authenticate a data pointer.
263*4f1223e8SApple OSS Distributions 
264*4f1223e8SApple OSS Distributions    The value must be an expression of non-function pointer type.
265*4f1223e8SApple OSS Distributions    The key must be a constant expression of type ptrauth_key.
266*4f1223e8SApple OSS Distributions    The extra data must be an expression of pointer or integer type;
267*4f1223e8SApple OSS Distributions    if an integer, it will be coerced to ptrauth_extra_data_t.
268*4f1223e8SApple OSS Distributions    The result will have the same type as the original value.
269*4f1223e8SApple OSS Distributions 
270*4f1223e8SApple OSS Distributions    If the authentication fails, dereferencing the resulting pointer
271*4f1223e8SApple OSS Distributions    will fail. */
272*4f1223e8SApple OSS Distributions #define ptrauth_auth_data(__value, __old_key, __old_data) \
273*4f1223e8SApple OSS Distributions   __builtin_ptrauth_auth(__value, __old_key, __old_data)
274*4f1223e8SApple OSS Distributions 
275*4f1223e8SApple OSS Distributions /* Return an extra-discriminator value which can validly be used
276*4f1223e8SApple OSS Distributions    as the second argument to ptrauth_blend_discriminator or the
277*4f1223e8SApple OSS Distributions    third argument to the __ptrauth qualifier.
278*4f1223e8SApple OSS Distributions 
279*4f1223e8SApple OSS Distributions    The argument must be a string literal.
280*4f1223e8SApple OSS Distributions    A call to this function is an integer constant expression. */
281*4f1223e8SApple OSS Distributions #define ptrauth_string_discriminator(__string) \
282*4f1223e8SApple OSS Distributions   __builtin_ptrauth_string_discriminator(__string)
283*4f1223e8SApple OSS Distributions 
284*4f1223e8SApple OSS Distributions /* Compute a full pointer-width generic signature for the given
285*4f1223e8SApple OSS Distributions    value, using the given data as a salt.
286*4f1223e8SApple OSS Distributions 
287*4f1223e8SApple OSS Distributions    This generic signature is process-independent, but may not be
288*4f1223e8SApple OSS Distributions    consistent across reboots.
289*4f1223e8SApple OSS Distributions 
290*4f1223e8SApple OSS Distributions    This can be used to validate the integrity of arbitrary data
291*4f1223e8SApple OSS Distributions    by storing a signature for that data together with it.  Because
292*4f1223e8SApple OSS Distributions    the signature is pointer-sized, if the stored signature matches
293*4f1223e8SApple OSS Distributions    the result of re-signing the current data, a match provides very
294*4f1223e8SApple OSS Distributions    strong evidence that the data has not been corrupted.
295*4f1223e8SApple OSS Distributions 
296*4f1223e8SApple OSS Distributions    The value must be an expression of pointer or integer type; if
297*4f1223e8SApple OSS Distributions    an integer, it will be coerced to uintptr_t.
298*4f1223e8SApple OSS Distributions    The extra data must be an expression of pointer or integer type;
299*4f1223e8SApple OSS Distributions    if an integer, it will be coerced to ptrauth_extra_data_t.
300*4f1223e8SApple OSS Distributions    The result will have type ptrauth_generic_signature_t.
301*4f1223e8SApple OSS Distributions 
302*4f1223e8SApple OSS Distributions    This operation will compute a meaningful signature even in processes
303*4f1223e8SApple OSS Distributions    which disable ABI pointer authentication. */
304*4f1223e8SApple OSS Distributions #define ptrauth_sign_generic_data(__value, __data) \
305*4f1223e8SApple OSS Distributions   __builtin_ptrauth_sign_generic_data(__value, __data)
306*4f1223e8SApple OSS Distributions 
307*4f1223e8SApple OSS Distributions 
308*4f1223e8SApple OSS Distributions /* Define some standard __ptrauth qualifiers used in the ABI. */
309*4f1223e8SApple OSS Distributions #define __ptrauth_function_pointer            \
310*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,0,0)
311*4f1223e8SApple OSS Distributions #define __ptrauth_return_address              \
312*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_return_address,1,0)
313*4f1223e8SApple OSS Distributions #define __ptrauth_block_invocation_pointer    \
314*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,0)
315*4f1223e8SApple OSS Distributions #define __ptrauth_block_copy_helper           \
316*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,0)
317*4f1223e8SApple OSS Distributions #define __ptrauth_block_destroy_helper        \
318*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,0)
319*4f1223e8SApple OSS Distributions #define __ptrauth_block_byref_copy_helper     \
320*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,0)
321*4f1223e8SApple OSS Distributions #define __ptrauth_block_byref_destroy_helper  \
322*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,0)
323*4f1223e8SApple OSS Distributions #define __ptrauth_objc_method_list_imp        \
324*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,0)
325*4f1223e8SApple OSS Distributions #define __ptrauth_cxx_vtable_pointer          \
326*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_cxx_vtable_pointer,0,0)
327*4f1223e8SApple OSS Distributions #define __ptrauth_cxx_vtt_vtable_pointer      \
328*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_cxx_vtable_pointer,0,0)
329*4f1223e8SApple OSS Distributions #define __ptrauth_swift_heap_object_destructor \
330*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,0xbbbf)
331*4f1223e8SApple OSS Distributions 
332*4f1223e8SApple OSS Distributions /* Some situations in the C++ and Swift ABIs use declaration-specific
333*4f1223e8SApple OSS Distributions    or type-specific extra discriminators. */
334*4f1223e8SApple OSS Distributions #define __ptrauth_cxx_virtual_function_pointer(__declkey) \
335*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,__declkey)
336*4f1223e8SApple OSS Distributions #define __ptrauth_swift_function_pointer(__typekey) \
337*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,0,__typekey)
338*4f1223e8SApple OSS Distributions #define __ptrauth_swift_class_method_pointer(__declkey) \
339*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,__declkey)
340*4f1223e8SApple OSS Distributions #define __ptrauth_swift_protocol_witness_function_pointer(__declkey) \
341*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,__declkey)
342*4f1223e8SApple OSS Distributions #define __ptrauth_swift_value_witness_function_pointer(__key) \
343*4f1223e8SApple OSS Distributions   __ptrauth(ptrauth_key_function_pointer,1,__key)
344*4f1223e8SApple OSS Distributions 
345*4f1223e8SApple OSS Distributions #else
346*4f1223e8SApple OSS Distributions 
347*4f1223e8SApple OSS Distributions #define ptrauth_strip(__value, __key) ({ (void)__key; __value; })
348*4f1223e8SApple OSS Distributions #define ptrauth_blend_discriminator(__pointer, __integer) ({ (void)__pointer; (void)__integer; (uintptr_t)0; })
349*4f1223e8SApple OSS Distributions #define ptrauth_type_discriminator(__type) ((uintptr_t)0)
350*4f1223e8SApple OSS Distributions #define ptrauth_function_pointer_type_discriminator(__type) ((uintptr_t)0)
351*4f1223e8SApple OSS Distributions #define ptrauth_sign_constant(__value, __key, __data) ({ (void)__key; (void)__data; __value; })
352*4f1223e8SApple OSS Distributions #define ptrauth_sign_unauthenticated(__value, __key, __data) ({ (void)__key; (void)__data; __value; })
353*4f1223e8SApple OSS Distributions #define ptrauth_auth_and_resign(__value, __old_key, __old_data, __new_key, __new_data) ({ \
354*4f1223e8SApple OSS Distributions       (void)__old_key; \
355*4f1223e8SApple OSS Distributions       (void)__old_data; \
356*4f1223e8SApple OSS Distributions       (void)__new_key; \
357*4f1223e8SApple OSS Distributions       (void)__new_data; \
358*4f1223e8SApple OSS Distributions       __value; })
359*4f1223e8SApple OSS Distributions #define ptrauth_auth_function(__value, __old_key, __old_data) ({ (void)__old_key; (void)__old_data; __value; })
360*4f1223e8SApple OSS Distributions #define ptrauth_nop_cast(__type, __value) ((__type)__value)
361*4f1223e8SApple OSS Distributions #define ptrauth_auth_data(__value, __old_key, __old_data) ({ (void)__old_key; (void)__old_data; __value; })
362*4f1223e8SApple OSS Distributions #define ptrauth_string_discriminator(__string) ({ (void)__string; (int)0; })
363*4f1223e8SApple OSS Distributions #define ptrauth_sign_generic_data(__value, __data) ({ (void)__value; (void)__data; (ptrauth_generic_signature_t)0; })
364*4f1223e8SApple OSS Distributions 
365*4f1223e8SApple OSS Distributions #define __ptrauth_function_pointer
366*4f1223e8SApple OSS Distributions #define __ptrauth_return_address
367*4f1223e8SApple OSS Distributions #define __ptrauth_block_invocation_pointer
368*4f1223e8SApple OSS Distributions #define __ptrauth_block_copy_helper
369*4f1223e8SApple OSS Distributions #define __ptrauth_block_destroy_helper
370*4f1223e8SApple OSS Distributions #define __ptrauth_block_byref_copy_helper
371*4f1223e8SApple OSS Distributions #define __ptrauth_block_byref_destroy_helper
372*4f1223e8SApple OSS Distributions #define __ptrauth_objc_method_list_imp
373*4f1223e8SApple OSS Distributions #define __ptrauth_cxx_vtable_pointer
374*4f1223e8SApple OSS Distributions #define __ptrauth_cxx_vtt_vtable_pointer
375*4f1223e8SApple OSS Distributions #define __ptrauth_swift_heap_object_destructor
376*4f1223e8SApple OSS Distributions #define __ptrauth_cxx_virtual_function_pointer(__declkey)
377*4f1223e8SApple OSS Distributions #define __ptrauth_swift_function_pointer(__typekey)
378*4f1223e8SApple OSS Distributions #define __ptrauth_swift_class_method_pointer(__declkey)
379*4f1223e8SApple OSS Distributions #define __ptrauth_swift_protocol_witness_function_pointer(__declkey)
380*4f1223e8SApple OSS Distributions #define __ptrauth_swift_value_witness_function_pointer(__key)
381*4f1223e8SApple OSS Distributions 
382*4f1223e8SApple OSS Distributions #endif /* __PTRAUTH_INTRINSICS__ */
383*4f1223e8SApple OSS Distributions 
384*4f1223e8SApple OSS Distributions #endif /* __PTRAUTH_H */
385