Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions clang/docs/PointerAuthentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,36 @@ The result value is never zero and always within range for both the

This can be used in constant expressions.

``ptrauth_type_discriminator``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: c

ptrauth_type_discriminator(type)

Compute the constant discriminator derived from the given type, as is computed
for automatically type diversified schemas.

``type`` must be a type. The result has the type ``ptrauth_extra_data_t``.

This can be used in constant expressions.

``ptrauth_function_pointer_type_discriminator``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe ptrauth_function_pointer_discriminator (w/o type) would suite better here? We either have a type-based discriminator if the feature is requested or just have zero, so it might be better to call the macro just ptrauth_function_pointer_discriminator w/o making the user think that it's a type discriminator.

Totally optional and feel free to ignore.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: c

ptrauth_function_pointer_type_discriminator(function_type)

Compute the constant discriminator derived from the provided function type, for
use in contexts where the default function authentication schema. If function
pointer type diversity is enabled, this is equivalent to
`ptrauth_type_discriminator(function_type)`, if it is not enabled this is `0`.

``function_type`` must be a function type. The result has the type ``ptrauth_extra_data_t``.

This can be used in constant expressions.

``ptrauth_strip``
^^^^^^^^^^^^^^^^^

Expand Down
14 changes: 14 additions & 0 deletions clang/lib/Headers/ptrauth.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
#define ptrauth_type_discriminator(__type) \
__builtin_ptrauth_type_discriminator(__type)

/* Compute the constant discriminator used by Clang to sign pointers with the
given C function pointer type.

A call to this function is an integer constant expression. */
#if __has_feature(ptrauth_function_pointer_type_discrimination)
#define ptrauth_function_pointer_type_discriminator(__type) \
__builtin_ptrauth_type_discriminator(__type)
#else
#define ptrauth_function_pointer_type_discriminator(__type) \
((ptrauth_extra_data_t)0)
#endif

/* Compute a signature for the given pair of pointer-sized values.
The order of the arguments is significant.

Expand Down Expand Up @@ -372,6 +384,8 @@ typedef __UINTPTR_TYPE__ ptrauth_generic_signature_t;
})

#define ptrauth_type_discriminator(__type) ((ptrauth_extra_data_t)0)
#define ptrauth_function_pointer_type_discriminator(__type) \
((ptrauth_extra_data_t)0)

#define ptrauth_sign_generic_data(__value, __data) \
({ \
Expand Down
Loading