2 * Copyright (c) 2017 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 #ifndef __DYLD_POINTER_AUTH_H__
27 #define __DYLD_POINTER_AUTH_H__
31 #if __has_feature(ptrauth_calls)
32 #define __ptrauth_dyld_address_auth __ptrauth(ptrauth_key_process_dependent_data, 1, 0)
33 #define __ptrauth_dyld_function_ptr __ptrauth(ptrauth_key_process_dependent_code, 1, 0)
35 #define __ptrauth_dyld_address_auth
36 #define __ptrauth_dyld_function_ptr
41 // On arm64e, signs the given pointer with the address of where it is stored.
42 // Other archs just have a regular pointer
43 #pragma clang diagnostic push
44 #pragma clang diagnostic ignored "-Wptrauth-null-pointers"
46 struct AuthenticatedValue
{
47 static_assert(sizeof(T
) <= sizeof(uintptr_t));
49 AuthenticatedValue() {
50 this->value
= ptrauth_sign_unauthenticated(nullptr, ptrauth_key_process_dependent_data
, this);
52 ~AuthenticatedValue() = default;
53 AuthenticatedValue(const AuthenticatedValue
& other
) {
54 this->value
= ptrauth_auth_and_resign(other
.value
,
55 ptrauth_key_process_dependent_data
, &other
,
56 ptrauth_key_process_dependent_data
, this);
58 AuthenticatedValue(AuthenticatedValue
&& other
) {
59 this->value
= ptrauth_auth_and_resign(other
.value
,
60 ptrauth_key_process_dependent_data
, &other
,
61 ptrauth_key_process_dependent_data
, this);
62 other
.value
= ptrauth_sign_unauthenticated(nullptr, ptrauth_key_process_dependent_data
, &other
);
65 AuthenticatedValue
& operator=(const AuthenticatedValue
&) = delete;
66 AuthenticatedValue
& operator=(AuthenticatedValue
&&) = delete;
68 // Add a few convenience methods for interoperating with values of the given type
69 AuthenticatedValue
& operator=(const T
& other
) {
70 this->value
= ptrauth_sign_unauthenticated(other
, ptrauth_key_process_dependent_data
, this);
73 bool operator==(const T
& other
) const {
74 return ptrauth_auth_data(this->value
, ptrauth_key_process_dependent_data
, this) == other
;
76 bool operator!=(const T
& other
) const {
77 return ptrauth_auth_data(this->value
, ptrauth_key_process_dependent_data
, this) != other
;
85 #pragma clang diagnostic pop
89 #endif // __DYLD_POINTER_AUTH_H__