@@ -199,6 +199,25 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
199199 ptrauth_auth_and_resign(__value, __old_key, __old_data, \
200200 ptrauth_key_function_pointer, 0)
201201
202+ /* Cast a value to the given type without changing any signature.
203+
204+ The type must be a pointer sized type compatible with the __ptrauth
205+ qualifier.
206+ The value must be an expression with a non-address diversified pointer
207+ authentication schema, and will be converted to an rvalue prior to the cast.
208+ The result has type given by the first argument.
209+
210+ The result has an identical bit-pattern to the input pointer. */
211+ #define ptrauth_nop_cast (__type , __value ) \
212+ ({ \
213+ union { \
214+ typeof(*(__value)) *__fptr; \
215+ typeof(__type) __opaque; \
216+ } __storage; \
217+ __storage.__fptr = (__value); \
218+ __storage.__opaque; \
219+ })
220+
202221/* Authenticate a data pointer.
203222
204223 The value must be an expression of non-function pointer type.
@@ -241,6 +260,18 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
241260#define ptrauth_type_discriminator (__type ) \
242261 __builtin_ptrauth_type_discriminator(__type)
243262
263+ /* Compute the constant discriminator used by Clang to sign pointers with the
264+ given C function pointer type.
265+
266+ A call to this function is an integer constant expression. */
267+ #if __has_feature (ptrauth_function_pointer_type_discrimination )
268+ #define ptrauth_function_pointer_type_discriminator (__type ) \
269+ __builtin_ptrauth_type_discriminator(__type)
270+ #else
271+ #define ptrauth_function_pointer_type_discriminator (__type ) \
272+ ((ptrauth_extra_data_t)0)
273+ #endif
274+
244275/* Compute a signature for the given pair of pointer-sized values.
245276 The order of the arguments is significant.
246277
@@ -263,6 +294,32 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
263294#define ptrauth_sign_generic_data (__value , __data ) \
264295 __builtin_ptrauth_sign_generic_data(__value, __data)
265296
297+ /* Define some standard __ptrauth qualifiers used in the ABI. */
298+ #define __ptrauth_function_pointer (__typekey ) \
299+ __ptrauth(ptrauth_key_function_pointer, 0, __typekey)
300+ #define __ptrauth_return_address __ptrauth(ptrauth_key_return_address, 1, 0)
301+ #define __ptrauth_block_invocation_pointer \
302+ __ptrauth(ptrauth_key_function_pointer, 1, 0)
303+ #define __ptrauth_block_copy_helper \
304+ __ptrauth(ptrauth_key_function_pointer, 1, 0)
305+ #define __ptrauth_block_destroy_helper \
306+ __ptrauth(ptrauth_key_function_pointer, 1, 0)
307+ #define __ptrauth_block_byref_copy_helper \
308+ __ptrauth(ptrauth_key_function_pointer, 1, 0)
309+ #define __ptrauth_block_byref_destroy_helper \
310+ __ptrauth(ptrauth_key_function_pointer, 1, 0)
311+ #if __has_feature (ptrauth_signed_block_descriptors )
312+ #define __ptrauth_block_descriptor_pointer \
313+ __ptrauth(ptrauth_key_block_descriptor_pointer, 1, 0xC0BB)
314+ #else
315+ #define __ptrauth_block_descriptor_pointer
316+ #endif
317+
318+ #define __ptrauth_cxx_vtable_pointer \
319+ __ptrauth(ptrauth_key_cxx_vtable_pointer, 0, 0)
320+ #define __ptrauth_cxx_vtt_vtable_pointer \
321+ __ptrauth(ptrauth_key_cxx_vtable_pointer, 0, 0)
322+
266323/* C++ vtable pointer signing class attribute */
267324#define ptrauth_cxx_vtable_pointer (key , address_discrimination , \
268325 extra_discrimination ...) \
@@ -371,7 +428,10 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
371428 ((ptrauth_extra_data_t)0); \
372429 })
373430
431+ #define ptrauth_nop_cast (__type , __value ) (__type)(__value)
374432#define ptrauth_type_discriminator (__type ) ((ptrauth_extra_data_t)0)
433+ #define ptrauth_function_pointer_type_discriminator (__type ) \
434+ ((ptrauth_extra_data_t)0)
375435
376436#define ptrauth_sign_generic_data (__value , __data ) \
377437 ({ \
@@ -384,9 +444,23 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
384444#define ptrauth_cxx_vtable_pointer (key , address_discrimination , \
385445 extra_discrimination ...)
386446
447+ #define __ptrauth_function_pointer (__typekey )
448+ #define __ptrauth_return_address
449+ #define __ptrauth_block_invocation_pointer
450+ #define __ptrauth_block_copy_helper
451+ #define __ptrauth_block_destroy_helper
452+ #define __ptrauth_block_byref_copy_helper
453+ #define __ptrauth_block_byref_destroy_helper
454+ #define __ptrauth_block_descriptor_pointer
455+ #define __ptrauth_objc_method_list_imp
456+ #define __ptrauth_objc_method_list_pointer
387457#define __ptrauth_objc_isa_pointer
388458#define __ptrauth_objc_isa_uintptr
389459#define __ptrauth_objc_super_pointer
460+ #define __ptrauth_cxx_vtable_pointer
461+ #define __ptrauth_cxx_vtt_vtable_pointer
462+ #define __ptrauth_objc_sel
463+ #define __ptrauth_objc_class_ro
390464
391465#endif /* __has_feature(ptrauth_intrinsics) || defined(__PTRAUTH__) */
392466
0 commit comments