clang 24.0.0git
PointerAuthOptions.h
Go to the documentation of this file.
1//===--- PointerAuthOptions.h -----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines options for configuring pointer-auth technologies
10// like ARMv8.3.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
15#define LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
16
17#include "clang/Basic/LLVM.h"
19#include "llvm/ADT/STLForwardCompat.h"
20#include "llvm/Support/ErrorHandling.h"
21#include "llvm/Target/TargetOptions.h"
22#include <optional>
23
24namespace clang {
25
26/// Constant discriminator to be used with block descriptor pointers. The value
27/// is ptrauth_string_discriminator("block_descriptor")
29
30/// Constant discriminator to be used with method list pointers. The value is
31/// ptrauth_string_discriminator("method_list_t")
33
34/// Constant discriminator to be used with objective-c isa pointers. The value
35/// is ptrauth_string_discriminator("isa")
37
38/// Constant discriminator to be used with objective-c superclass pointers.
39/// The value is ptrauth_string_discriminator("objc_class:superclass")
41
42/// Constant discriminator to be used with objective-c sel pointers. The value
43/// is ptrauth_string_discriminator("sel")
45
46/// Constant discriminator to be used with objective-c class_ro_t pointers.
47/// The value is ptrauth_string_discriminator("class_data_bits")
49
50constexpr unsigned PointerAuthKeyNone = -1;
51
52/// Constant discriminator for std::type_info vtable pointers: 0xB1EA/45546
53/// The value is ptrauth_string_discriminator("_ZTVSt9type_info"), i.e.,
54/// the vtable type discriminator for classes derived from std::type_info.
56
58public:
59 enum class Kind : unsigned {
62 };
63
64 /// Hardware pointer-signing keys in ARM8.3.
65 ///
66 /// These values are the same used in ptrauth.h.
67 enum class ARM8_3Key : unsigned {
68 ASIA = 0,
69 ASIB = 1,
70 ASDA = 2,
71 ASDB = 3
72 };
73
74 /// Forms of extra discrimination.
75 enum class Discrimination : unsigned {
76 /// No additional discrimination.
78
79 /// Include a hash of the entity's type.
81
82 /// Include a hash of the entity's identity.
84
85 /// Discriminate using a constant value.
87 };
88
89private:
90 Kind TheKind : 2;
91 unsigned IsAddressDiscriminated : 1;
92 unsigned IsIsaPointer : 1;
93 unsigned AuthenticatesNullValues : 1;
94 PointerAuthenticationMode SelectedAuthenticationMode : 2;
95 Discrimination DiscriminationKind : 2;
96 unsigned Key : 2;
97 unsigned ConstantDiscriminator : 16;
98
99public:
100 PointerAuthSchema() : TheKind(Kind::None) {}
101
103 ARM8_3Key Key, bool IsAddressDiscriminated,
104 PointerAuthenticationMode AuthenticationMode,
105 Discrimination OtherDiscrimination,
106 std::optional<uint16_t> ConstantDiscriminatorOrNone = std::nullopt,
107 bool IsIsaPointer = false, bool AuthenticatesNullValues = false)
108 : TheKind(Kind::ARM8_3), IsAddressDiscriminated(IsAddressDiscriminated),
109 IsIsaPointer(IsIsaPointer),
110 AuthenticatesNullValues(AuthenticatesNullValues),
111 SelectedAuthenticationMode(AuthenticationMode),
112 DiscriminationKind(OtherDiscrimination), Key(llvm::to_underlying(Key)) {
114 ConstantDiscriminatorOrNone) &&
115 "constant discrimination requires a constant!");
116 if (ConstantDiscriminatorOrNone)
117 ConstantDiscriminator = *ConstantDiscriminatorOrNone;
118 }
119
121 ARM8_3Key Key, bool IsAddressDiscriminated,
122 Discrimination OtherDiscrimination,
123 std::optional<uint16_t> ConstantDiscriminatorOrNone = std::nullopt,
124 bool IsIsaPointer = false, bool AuthenticatesNullValues = false)
125 : PointerAuthSchema(Key, IsAddressDiscriminated,
127 OtherDiscrimination, ConstantDiscriminatorOrNone,
128 IsIsaPointer, AuthenticatesNullValues) {}
129
130 Kind getKind() const { return TheKind; }
131
132 explicit operator bool() const { return isEnabled(); }
133
134 bool isEnabled() const { return getKind() != Kind::None; }
135
137 assert(getKind() != Kind::None);
138 return IsAddressDiscriminated;
139 }
140
141 bool isIsaPointer() const {
142 assert(getKind() != Kind::None);
143 return IsIsaPointer;
144 }
145
147 assert(getKind() != Kind::None);
148 return AuthenticatesNullValues;
149 }
150
154
156 assert(getKind() != Kind::None);
157 return DiscriminationKind;
158 }
159
162 return ConstantDiscriminator;
163 }
164
165 unsigned getKey() const {
166 switch (getKind()) {
167 case Kind::None:
168 llvm_unreachable("calling getKey() on disabled schema");
169 case Kind::ARM8_3:
170 return llvm::to_underlying(getARM8_3Key());
171 }
172 llvm_unreachable("bad key kind");
173 }
174
176 return SelectedAuthenticationMode;
177 }
178
180 assert(getKind() == Kind::ARM8_3);
181 return ARM8_3Key(Key);
182 }
183};
184
186 /// Should return addresses be authenticated?
187 bool ReturnAddresses = false;
188
189 /// Do authentication failures cause a trap?
190 bool AuthTraps = false;
191
192 /// Do indirect goto label addresses need to be authenticated?
193 bool IndirectGotos = false;
194
195 /// Use hardened lowering for jump-table dispatch?
197
198 /// The ABI for C function pointers.
200
201 /// The ABI for C++ virtual table pointers (the pointer to the table
202 /// itself) as installed in an actual class instance.
204
205 /// TypeInfo has external ABI requirements and is emitted without
206 /// actually having parsed the libcxx definition, so we can't simply
207 /// perform a look up. The settings for this should match the exact
208 /// specification in type_info.h
210
211 /// The ABI for C++ virtual table pointers as installed in a VTT.
213
214 /// The ABI for most C++ virtual function pointers, i.e. v-table entries.
216
217 /// The ABI for variadic C++ virtual function pointers.
219
220 /// The ABI for C++ member function pointers.
222
223 /// The ABI for block invocation function pointers.
225
226 /// The ABI for block object copy/destroy function pointers.
228
229 /// The ABI for __block variable copy/destroy function pointers.
231
232 /// The ABI for pointers to block descriptors.
234
235 /// The ABI for Objective-C method lists.
237
238 /// The ABI for a reference to an Objective-C method list in _class_ro_t.
240
241 /// The ABI for Objective-C isa pointers.
243
244 /// The ABI for Objective-C superclass pointers.
246
247 /// The ABI for Objective-C class_ro_t pointers.
249};
250
251} // end namespace clang
252
253#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
Discrimination getOtherDiscrimination() const
PointerAuthSchema(ARM8_3Key Key, bool IsAddressDiscriminated, Discrimination OtherDiscrimination, std::optional< uint16_t > ConstantDiscriminatorOrNone=std::nullopt, bool IsIsaPointer=false, bool AuthenticatesNullValues=false)
Discrimination
Forms of extra discrimination.
@ None
No additional discrimination.
@ Type
Include a hash of the entity's type.
@ Decl
Include a hash of the entity's identity.
@ Constant
Discriminate using a constant value.
ARM8_3Key
Hardware pointer-signing keys in ARM8.3.
PointerAuthSchema(ARM8_3Key Key, bool IsAddressDiscriminated, PointerAuthenticationMode AuthenticationMode, Discrimination OtherDiscrimination, std::optional< uint16_t > ConstantDiscriminatorOrNone=std::nullopt, bool IsIsaPointer=false, bool AuthenticatesNullValues=false)
PointerAuthenticationMode getAuthenticationMode() const
uint16_t getConstantDiscrimination() const
The JSON file list parser is used to communicate input to InstallAPI.
constexpr uint16_t BlockDescriptorConstantDiscriminator
Constant discriminator to be used with block descriptor pointers.
constexpr uint16_t IsaPointerConstantDiscriminator
Constant discriminator to be used with objective-c isa pointers.
constexpr uint16_t SuperPointerConstantDiscriminator
Constant discriminator to be used with objective-c superclass pointers.
constexpr uint16_t MethodListPointerConstantDiscriminator
Constant discriminator to be used with method list pointers.
constexpr uint16_t ClassROConstantDiscriminator
Constant discriminator to be used with objective-c class_ro_t pointers.
constexpr uint16_t SelPointerConstantDiscriminator
Constant discriminator to be used with objective-c sel pointers.
constexpr unsigned PointerAuthKeyNone
constexpr uint16_t StdTypeInfoVTablePointerConstantDiscrimination
Constant discriminator for std::type_info vtable pointers: 0xB1EA/45546 The value is ptrauth_string_d...
PointerAuthenticationMode
Definition LangOptions.h:63
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 uint16_t
PointerAuthSchema BlockDescriptorPointers
The ABI for pointers to block descriptors.
PointerAuthSchema BlockHelperFunctionPointers
The ABI for block object copy/destroy function pointers.
PointerAuthSchema CXXVTablePointers
The ABI for C++ virtual table pointers (the pointer to the table itself) as installed in an actual cl...
PointerAuthSchema BlockInvocationFunctionPointers
The ABI for block invocation function pointers.
PointerAuthSchema BlockByrefHelperFunctionPointers
The ABI for __block variable copy/destroy function pointers.
PointerAuthSchema CXXVTTVTablePointers
The ABI for C++ virtual table pointers as installed in a VTT.
bool ReturnAddresses
Should return addresses be authenticated?
PointerAuthSchema CXXTypeInfoVTablePointer
TypeInfo has external ABI requirements and is emitted without actually having parsed the libcxx defin...
bool AArch64JumpTableHardening
Use hardened lowering for jump-table dispatch?
PointerAuthSchema ObjCMethodListPointer
The ABI for a reference to an Objective-C method list in _class_ro_t.
PointerAuthSchema FunctionPointers
The ABI for C function pointers.
PointerAuthSchema ObjCSuperPointers
The ABI for Objective-C superclass pointers.
bool AuthTraps
Do authentication failures cause a trap?
PointerAuthSchema CXXMemberFunctionPointers
The ABI for C++ member function pointers.
PointerAuthSchema CXXVirtualVariadicFunctionPointers
The ABI for variadic C++ virtual function pointers.
PointerAuthSchema ObjCMethodListFunctionPointers
The ABI for Objective-C method lists.
PointerAuthSchema ObjCClassROPointers
The ABI for Objective-C class_ro_t pointers.
PointerAuthSchema CXXVirtualFunctionPointers
The ABI for most C++ virtual function pointers, i.e. v-table entries.
PointerAuthSchema ObjCIsaPointers
The ABI for Objective-C isa pointers.
bool IndirectGotos
Do indirect goto label addresses need to be authenticated?