clang 22.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")
28constexpr uint16_t BlockDescriptorConstantDiscriminator = 0xC0BB;
29
30/// Constant discriminator to be used with function pointers in .init_array and
31/// .fini_array. The value is ptrauth_string_discriminator("init_fini")
32constexpr uint16_t InitFiniPointerConstantDiscriminator = 0xD9D4;
33
34/// Constant discriminator to be used with method list pointers. The value is
35/// ptrauth_string_discriminator("method_list_t")
36constexpr uint16_t MethodListPointerConstantDiscriminator = 0xC310;
37
38/// Constant discriminator to be used with objective-c isa pointers. The value
39/// is ptrauth_string_discriminator("isa")
40constexpr uint16_t IsaPointerConstantDiscriminator = 0x6AE1;
41
42/// Constant discriminator to be used with objective-c superclass pointers.
43/// The value is ptrauth_string_discriminator("objc_class:superclass")
44constexpr uint16_t SuperPointerConstantDiscriminator = 0xB5AB;
45
46/// Constant discriminator to be used with objective-c sel pointers. The value
47/// is ptrauth_string_discriminator("sel")
48constexpr uint16_t SelPointerConstantDiscriminator = 0x57c2;
49
50/// Constant discriminator to be used with objective-c class_ro_t pointers.
51/// The value is ptrauth_string_discriminator("class_data_bits")
52constexpr uint16_t ClassROConstantDiscriminator = 0x61F8;
53
54constexpr unsigned PointerAuthKeyNone = -1;
55
56/// Constant discriminator for std::type_info vtable pointers: 0xB1EA/45546
57/// The value is ptrauth_string_discriminator("_ZTVSt9type_info"), i.e.,
58/// the vtable type discriminator for classes derived from std::type_info.
60
62public:
63 enum class Kind : unsigned {
64 None,
65 ARM8_3,
66 };
67
68 /// Hardware pointer-signing keys in ARM8.3.
69 ///
70 /// These values are the same used in ptrauth.h.
71 enum class ARM8_3Key : unsigned {
72 ASIA = 0,
73 ASIB = 1,
74 ASDA = 2,
75 ASDB = 3
76 };
77
78 /// Forms of extra discrimination.
79 enum class Discrimination : unsigned {
80 /// No additional discrimination.
81 None,
82
83 /// Include a hash of the entity's type.
84 Type,
85
86 /// Include a hash of the entity's identity.
87 Decl,
88
89 /// Discriminate using a constant value.
91 };
92
93private:
94 Kind TheKind : 2;
95 unsigned IsAddressDiscriminated : 1;
96 unsigned IsIsaPointer : 1;
97 unsigned AuthenticatesNullValues : 1;
98 PointerAuthenticationMode SelectedAuthenticationMode : 2;
99 Discrimination DiscriminationKind : 2;
100 unsigned Key : 2;
101 unsigned ConstantDiscriminator : 16;
102
103public:
104 PointerAuthSchema() : TheKind(Kind::None) {}
105
107 ARM8_3Key Key, bool IsAddressDiscriminated,
108 PointerAuthenticationMode AuthenticationMode,
109 Discrimination OtherDiscrimination,
110 std::optional<uint16_t> ConstantDiscriminatorOrNone = std::nullopt,
111 bool IsIsaPointer = false, bool AuthenticatesNullValues = false)
112 : TheKind(Kind::ARM8_3), IsAddressDiscriminated(IsAddressDiscriminated),
113 IsIsaPointer(IsIsaPointer),
114 AuthenticatesNullValues(AuthenticatesNullValues),
115 SelectedAuthenticationMode(AuthenticationMode),
116 DiscriminationKind(OtherDiscrimination), Key(llvm::to_underlying(Key)) {
118 ConstantDiscriminatorOrNone) &&
119 "constant discrimination requires a constant!");
120 if (ConstantDiscriminatorOrNone)
121 ConstantDiscriminator = *ConstantDiscriminatorOrNone;
122 }
123
125 ARM8_3Key Key, bool IsAddressDiscriminated,
126 Discrimination OtherDiscrimination,
127 std::optional<uint16_t> ConstantDiscriminatorOrNone = std::nullopt,
128 bool IsIsaPointer = false, bool AuthenticatesNullValues = false)
129 : PointerAuthSchema(Key, IsAddressDiscriminated,
131 OtherDiscrimination, ConstantDiscriminatorOrNone,
132 IsIsaPointer, AuthenticatesNullValues) {}
133
134 Kind getKind() const { return TheKind; }
135
136 explicit operator bool() const { return isEnabled(); }
137
138 bool isEnabled() const { return getKind() != Kind::None; }
139
141 assert(getKind() != Kind::None);
142 return IsAddressDiscriminated;
143 }
144
145 bool isIsaPointer() const {
146 assert(getKind() != Kind::None);
147 return IsIsaPointer;
148 }
149
151 assert(getKind() != Kind::None);
152 return AuthenticatesNullValues;
153 }
154
157 }
158
160 assert(getKind() != Kind::None);
161 return DiscriminationKind;
162 }
163
164 uint16_t getConstantDiscrimination() const {
166 return ConstantDiscriminator;
167 }
168
169 unsigned getKey() const {
170 switch (getKind()) {
171 case Kind::None:
172 llvm_unreachable("calling getKey() on disabled schema");
173 case Kind::ARM8_3:
174 return llvm::to_underlying(getARM8_3Key());
175 }
176 llvm_unreachable("bad key kind");
177 }
178
180 return SelectedAuthenticationMode;
181 }
182
184 assert(getKind() == Kind::ARM8_3);
185 return ARM8_3Key(Key);
186 }
187};
188
190 /// Should return addresses be authenticated?
191 bool ReturnAddresses = false;
192
193 /// Do authentication failures cause a trap?
194 bool AuthTraps = false;
195
196 /// Do indirect goto label addresses need to be authenticated?
197 bool IndirectGotos = false;
198
199 /// Use hardened lowering for jump-table dispatch?
201
202 /// The ABI for C function pointers.
204
205 /// The ABI for C++ virtual table pointers (the pointer to the table
206 /// itself) as installed in an actual class instance.
208
209 /// TypeInfo has external ABI requirements and is emitted without
210 /// actually having parsed the libcxx definition, so we can't simply
211 /// perform a look up. The settings for this should match the exact
212 /// specification in type_info.h
214
215 /// The ABI for C++ virtual table pointers as installed in a VTT.
217
218 /// The ABI for most C++ virtual function pointers, i.e. v-table entries.
220
221 /// The ABI for variadic C++ virtual function pointers.
223
224 /// The ABI for C++ member function pointers.
226
227 /// The ABI for function addresses in .init_array and .fini_array
229
230 /// The ABI for block invocation function pointers.
232
233 /// The ABI for block object copy/destroy function pointers.
235
236 /// The ABI for __block variable copy/destroy function pointers.
238
239 /// The ABI for pointers to block descriptors.
241
242 /// The ABI for Objective-C method lists.
244
245 /// The ABI for a reference to an Objective-C method list in _class_ro_t.
247
248 /// The ABI for Objective-C isa pointers.
250
251 /// The ABI for Objective-C superclass pointers.
253
254 /// The ABI for Objective-C class_ro_t pointers.
256};
257
258} // end namespace clang
259
260#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
Discrimination getOtherDiscrimination() const
ARM8_3Key getARM8_3Key() 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
#define bool
Definition: gpuintrin.h:32
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 InitFiniPointerConstantDiscriminator
Constant discriminator to be used with function pointers in .init_array and .fini_array.
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:62
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
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 InitFiniPointers
The ABI for function addresses in .init_array and .fini_array.
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?