@@ -53,6 +53,10 @@ struct RuntimeTarget;
53
53
template <>
54
54
struct RuntimeTarget <4 > {
55
55
using StoredPointer = uint32_t ;
56
+ // To avoid implicit conversions from StoredSignedPointer to StoredPointer.
57
+ using StoredSignedPointer = struct {
58
+ uint32_t SignedValue;
59
+ };
56
60
using StoredSize = uint32_t ;
57
61
using StoredPointerDifference = int32_t ;
58
62
static constexpr size_t PointerSize = 4 ;
@@ -61,6 +65,10 @@ struct RuntimeTarget<4> {
61
65
template <>
62
66
struct RuntimeTarget <8 > {
63
67
using StoredPointer = uint64_t ;
68
+ // To avoid implicit conversions from StoredSignedPointer to StoredPointer.
69
+ using StoredSignedPointer = struct {
70
+ uint64_t SignedValue;
71
+ };
64
72
using StoredSize = uint64_t ;
65
73
using StoredPointerDifference = int64_t ;
66
74
static constexpr size_t PointerSize = 8 ;
@@ -77,6 +85,7 @@ namespace reflection {
77
85
struct InProcess {
78
86
static constexpr size_t PointerSize = sizeof (uintptr_t );
79
87
using StoredPointer = uintptr_t ;
88
+ using StoredSignedPointer = uintptr_t ;
80
89
using StoredSize = size_t ;
81
90
using StoredPointerDifference = ptrdiff_t ;
82
91
@@ -85,6 +94,9 @@ struct InProcess {
85
94
86
95
template <typename T>
87
96
using Pointer = T*;
97
+
98
+ template <typename T>
99
+ using SignedPointer = T;
88
100
89
101
template <typename T, bool Nullable = false >
90
102
using FarRelativeDirectPointer = FarRelativeDirectPointer<T, Nullable>;
@@ -111,13 +123,17 @@ struct ExternalPointer {
111
123
template <typename Runtime>
112
124
struct External {
113
125
using StoredPointer = typename Runtime::StoredPointer;
126
+ using StoredSignedPointer = typename Runtime::StoredSignedPointer;
114
127
using StoredSize = typename Runtime::StoredSize;
115
128
using StoredPointerDifference = typename Runtime::StoredPointerDifference;
116
129
static constexpr size_t PointerSize = Runtime::PointerSize;
117
130
const StoredPointer PointerValue;
118
131
119
132
template <typename T>
120
133
using Pointer = StoredPointer;
134
+
135
+ template <typename T>
136
+ using SignedPointer = StoredSignedPointer;
121
137
122
138
template <typename T, bool Nullable = false >
123
139
using FarRelativeDirectPointer = StoredPointer;
@@ -141,9 +157,13 @@ using ConstTargetMetadataPointer
141
157
template <typename Runtime, typename T>
142
158
using TargetPointer = typename Runtime::template Pointer<T>;
143
159
160
+ template <typename Runtime, typename T>
161
+ using TargetSignedPointer = typename Runtime::template SignedPointer<T>;
162
+
144
163
template <typename Runtime, typename T>
145
164
using ConstTargetPointer = typename Runtime::template Pointer<const T>;
146
165
166
+
147
167
template <typename Runtime, template <typename > class Pointee ,
148
168
bool Nullable = true >
149
169
using ConstTargetFarRelativeDirectPointer
@@ -281,7 +301,10 @@ class TargetValueWitnessTypes {
281
301
#define WANT_ALL_VALUE_WITNESSES
282
302
#define DATA_VALUE_WITNESS (lowerId, upperId, type )
283
303
#define FUNCTION_VALUE_WITNESS (lowerId, upperId, returnType, paramTypes ) \
284
- typedef TargetPointer<Runtime, returnType paramTypes> lowerId;
304
+ typedef returnType (*lowerId ## Unsigned) paramTypes; \
305
+ typedef TargetSignedPointer<Runtime, lowerId ## Unsigned \
306
+ __ptrauth_swift_value_witness_function_pointer ( \
307
+ SpecialPointerAuthDiscriminators::upperId)> lowerId;
285
308
#define MUTABLE_VALUE_TYPE TargetPointer<Runtime, OpaqueValue>
286
309
#define IMMUTABLE_VALUE_TYPE ConstTargetPointer<Runtime, OpaqueValue>
287
310
#define MUTABLE_BUFFER_TYPE TargetPointer<Runtime, ValueBuffer>
@@ -314,6 +337,9 @@ template <typename Runtime> struct TargetValueWitnessTable {
314
337
#define WANT_ONLY_REQUIRED_VALUE_WITNESSES
315
338
#define VALUE_WITNESS (LOWER_ID, UPPER_ID ) \
316
339
typename TargetValueWitnessTypes<Runtime>::LOWER_ID LOWER_ID;
340
+ #define FUNCTION_VALUE_WITNESS (LOWER_ID, UPPER_ID, RET, PARAMS ) \
341
+ typename TargetValueWitnessTypes<Runtime>::LOWER_ID LOWER_ID;
342
+
317
343
#include " swift/ABI/ValueWitness.def"
318
344
319
345
using StoredSize = typename Runtime::StoredSize;
@@ -595,7 +621,7 @@ struct TargetMetadata {
595
621
#define WANT_ONLY_REQUIRED_VALUE_WITNESSES
596
622
#define FUNCTION_VALUE_WITNESS (WITNESS, UPPER, RET_TYPE, PARAM_TYPES ) \
597
623
template <typename ...A> \
598
- _ResultOf<ValueWitnessTypes::WITNESS>::type \
624
+ _ResultOf<ValueWitnessTypes::WITNESS ## Unsigned >::type \
599
625
vw_##WITNESS(A &&...args) const { \
600
626
return getValueWitnesses ()->WITNESS (std::forward<A>(args)..., this ); \
601
627
}
@@ -744,7 +770,7 @@ template <typename Runtime>
744
770
struct TargetHeapMetadataHeaderPrefix {
745
771
// / Destroy the object, returning the allocated size of the object
746
772
// / or 0 if the object shouldn't be deallocated.
747
- TargetPointer <Runtime, HeapObjectDestroyer> destroy;
773
+ TargetSignedPointer <Runtime, HeapObjectDestroyer *__ptrauth_swift_heap_object_destructor > destroy;
748
774
};
749
775
using HeapMetadataHeaderPrefix =
750
776
TargetHeapMetadataHeaderPrefix<InProcess>;
@@ -838,18 +864,26 @@ struct TargetVTableDescriptorHeader {
838
864
839
865
template <typename Runtime> struct TargetContextDescriptor ;
840
866
841
- template <typename Runtime>
867
+ template <typename Runtime,
868
+ template <typename _Runtime> class Context = TargetContextDescriptor>
869
+ using TargetSignedContextPointer = TargetSignedPointer<Runtime,
870
+ Context<Runtime> * __ptrauth_swift_type_descriptor>;
871
+
872
+ template <typename Runtime,
873
+ template <typename _Runtime> class Context = TargetContextDescriptor>
842
874
using TargetRelativeContextPointer =
843
- RelativeIndirectablePointer<const TargetContextDescriptor<Runtime>,
844
- /* nullable*/ true >;
875
+ RelativeIndirectablePointer<const Context<Runtime>,
876
+ /* nullable*/ true , int32_t ,
877
+ TargetSignedContextPointer<Runtime, Context>>;
845
878
846
879
using RelativeContextPointer = TargetRelativeContextPointer<InProcess>;
847
880
848
881
template <typename Runtime, typename IntTy,
849
882
template <typename _Runtime> class Context = TargetContextDescriptor>
850
883
using RelativeContextPointerIntPair =
851
884
RelativeIndirectablePointerIntPair<const Context<Runtime>, IntTy,
852
- /* nullable*/ true , int32_t >;
885
+ /* nullable*/ true , int32_t ,
886
+ TargetSignedContextPointer<Runtime, Context>>;
853
887
854
888
template <typename Runtime> struct TargetMethodDescriptor ;
855
889
@@ -1085,13 +1119,13 @@ struct TargetClassMetadata : public TargetAnyClassMetadata<Runtime> {
1085
1119
// / if this is an artificial subclass. We currently provide no
1086
1120
// / supported mechanism for making a non-artificial subclass
1087
1121
// / dynamically.
1088
- ConstTargetMetadataPointer <Runtime, TargetClassDescriptor> Description;
1122
+ TargetSignedPointer <Runtime, const TargetClassDescriptor<Runtime> * __ptrauth_swift_type_descriptor > Description;
1089
1123
1090
1124
public:
1091
1125
// / A function for destroying instance variables, used to clean up after an
1092
1126
// / early return from a constructor. If null, no clean up will be performed
1093
1127
// / and all ivars must be trivial.
1094
- TargetPointer <Runtime, ClassIVarDestroyer> IVarDestroyer;
1128
+ TargetSignedPointer <Runtime, ClassIVarDestroyer * __ptrauth_swift_heap_object_destructor > IVarDestroyer;
1095
1129
1096
1130
// After this come the class members, laid out as follows:
1097
1131
// - class members for the superclass (recursively)
@@ -1108,6 +1142,12 @@ struct TargetClassMetadata : public TargetAnyClassMetadata<Runtime> {
1108
1142
return Description;
1109
1143
}
1110
1144
1145
+ typename Runtime::StoredSignedPointer
1146
+ getDescriptionAsSignedPointer () const {
1147
+ assert (isTypeMetadata ());
1148
+ return Description;
1149
+ }
1150
+
1111
1151
void setDescription (const TargetClassDescriptor<Runtime> *description) {
1112
1152
Description = description;
1113
1153
}
@@ -1314,7 +1354,7 @@ struct TargetForeignClassMetadata : public TargetForeignTypeMetadata<Runtime> {
1314
1354
using StoredPointer = typename Runtime::StoredPointer;
1315
1355
1316
1356
// / An out-of-line description of the type.
1317
- ConstTargetMetadataPointer <Runtime, TargetClassDescriptor> Description;
1357
+ TargetSignedPointer <Runtime, const TargetClassDescriptor<Runtime> * __ptrauth_swift_type_descriptor > Description;
1318
1358
1319
1359
// / The superclass of the foreign class, if any.
1320
1360
ConstTargetMetadataPointer<Runtime, swift::TargetForeignClassMetadata>
@@ -1330,6 +1370,11 @@ struct TargetForeignClassMetadata : public TargetForeignTypeMetadata<Runtime> {
1330
1370
return Description;
1331
1371
}
1332
1372
1373
+ typename Runtime::StoredSignedPointer
1374
+ getDescriptionAsSignedPointer () const {
1375
+ return Description;
1376
+ }
1377
+
1333
1378
static bool classof (const TargetMetadata<Runtime> *metadata) {
1334
1379
return metadata->getKind () == MetadataKind::ForeignClass;
1335
1380
}
@@ -1345,8 +1390,7 @@ struct TargetValueMetadata : public TargetMetadata<Runtime> {
1345
1390
: TargetMetadata<Runtime>(Kind), Description(description) {}
1346
1391
1347
1392
// / An out-of-line description of the type.
1348
- ConstTargetMetadataPointer<Runtime, TargetValueTypeDescriptor>
1349
- Description;
1393
+ TargetSignedPointer<Runtime, const TargetValueTypeDescriptor<Runtime> * __ptrauth_swift_type_descriptor> Description;
1350
1394
1351
1395
static bool classof (const TargetMetadata<Runtime> *metadata) {
1352
1396
return metadata->getKind () == MetadataKind::Struct
@@ -1358,6 +1402,11 @@ struct TargetValueMetadata : public TargetMetadata<Runtime> {
1358
1402
getDescription () const {
1359
1403
return Description;
1360
1404
}
1405
+
1406
+ typename Runtime::StoredSignedPointer
1407
+ getDescriptionAsSignedPointer () const {
1408
+ return Description;
1409
+ }
1361
1410
};
1362
1411
using ValueMetadata = TargetValueMetadata<InProcess>;
1363
1412
@@ -2189,7 +2238,7 @@ struct TargetTypeMetadataRecord {
2189
2238
DirectNominalTypeDescriptor;
2190
2239
2191
2240
// / An indirect reference to a nominal type descriptor.
2192
- RelativeDirectPointerIntPair<TargetContextDescriptor<Runtime> * const ,
2241
+ RelativeDirectPointerIntPair<TargetSignedPointer<Runtime, TargetContextDescriptor<Runtime> * __ptrauth_swift_type_descriptor> ,
2193
2242
TypeReferenceKind>
2194
2243
IndirectNominalTypeDescriptor;
2195
2244
@@ -2242,24 +2291,25 @@ template<typename Runtime> class TargetGenericRequirementDescriptor;
2242
2291
// / pointer equivalent to \c TargetProtocolDescriptorRef.
2243
2292
template <typename Runtime>
2244
2293
class RelativeTargetProtocolDescriptorPointer {
2245
- union AnyProtocol {
2246
- TargetProtocolDescriptor<Runtime> descriptor;
2294
+ union {
2295
+ // / Relative pointer to a Swift protocol descriptor.
2296
+ // / The \c bool value will be false to indicate that the protocol
2297
+ // / is a Swift protocol, or true to indicate that this references
2298
+ // / an Objective-C protocol.
2299
+ RelativeContextPointerIntPair<Runtime, bool , TargetProtocolDescriptor>
2300
+ swiftPointer;
2301
+ #if SWIFT_OBJC_INTEROP
2302
+ // / Relative pointer to an ObjC protocol descriptor.
2303
+ // / The \c bool value will be false to indicate that the protocol
2304
+ // / is a Swift protocol, or true to indicate that this references
2305
+ // / an Objective-C protocol.
2306
+ RelativeIndirectablePointerIntPair<Protocol, bool > objcPointer;
2307
+ #endif
2247
2308
};
2248
2309
2249
- // / The relative pointer itself.
2250
- // /
2251
- // / The \c AnyProtocol value type ensures that we can reference any
2252
- // / protocol descriptor; it will be reinterpret_cast to the appropriate
2253
- // / protocol descriptor type.
2254
- // /
2255
- // / The \c bool integer value will be false to indicate that the protocol
2256
- // / is a Swift protocol, or true to indicate that this references
2257
- // / an Objective-C protocol.
2258
- RelativeIndirectablePointerIntPair<AnyProtocol, bool > pointer;
2259
-
2260
2310
#if SWIFT_OBJC_INTEROP
2261
2311
bool isObjC () const {
2262
- return pointer .getInt ();
2312
+ return objcPointer .getInt ();
2263
2313
}
2264
2314
#endif
2265
2315
@@ -2269,13 +2319,13 @@ class RelativeTargetProtocolDescriptorPointer {
2269
2319
#if SWIFT_OBJC_INTEROP
2270
2320
if (isObjC ()) {
2271
2321
return TargetProtocolDescriptorRef<Runtime>::forObjC (
2272
- protocol_const_cast (pointer .getPointer ()));
2322
+ const_cast <Protocol*>(objcPointer .getPointer ()));
2273
2323
}
2274
2324
#endif
2275
2325
2276
2326
return TargetProtocolDescriptorRef<Runtime>::forSwift (
2277
2327
reinterpret_cast <ConstTargetMetadataPointer<
2278
- Runtime, TargetProtocolDescriptor>>(pointer .getPointer ()));
2328
+ Runtime, TargetProtocolDescriptor>>(swiftPointer .getPointer ()));
2279
2329
}
2280
2330
2281
2331
operator TargetProtocolDescriptorRef<Runtime>() const {
@@ -2293,7 +2343,7 @@ struct TargetTypeReference {
2293
2343
2294
2344
// / An indirect reference to a TypeContextDescriptor or ProtocolDescriptor.
2295
2345
RelativeDirectPointer<
2296
- ConstTargetMetadataPointer <Runtime, TargetContextDescriptor>>
2346
+ TargetSignedPointer <Runtime, TargetContextDescriptor<Runtime> * __ptrauth_swift_type_descriptor >>
2297
2347
IndirectTypeDescriptor;
2298
2348
2299
2349
// / An indirect reference to an Objective-C class.
@@ -2391,7 +2441,7 @@ struct TargetProtocolConformanceDescriptor final
2391
2441
2392
2442
private:
2393
2443
// / The protocol being conformed to.
2394
- RelativeIndirectablePointer<ProtocolDescriptor > Protocol;
2444
+ TargetRelativeContextPointer<Runtime, TargetProtocolDescriptor > Protocol;
2395
2445
2396
2446
// Some description of the type that conforms to the protocol.
2397
2447
TargetTypeReference<Runtime> TypeRef;
@@ -2424,7 +2474,8 @@ struct TargetProtocolConformanceDescriptor final
2424
2474
return TypeRef.getTypeDescriptor (getTypeKind ());
2425
2475
}
2426
2476
2427
- const TargetContextDescriptor<Runtime> **_getTypeDescriptorLocation () const {
2477
+ TargetContextDescriptor<Runtime> * __ptrauth_swift_type_descriptor *
2478
+ _getTypeDescriptorLocation () const {
2428
2479
if (getTypeKind () != TypeReferenceKind::IndirectTypeDescriptor)
2429
2480
return nullptr ;
2430
2481
return TypeRef.IndirectTypeDescriptor .get ();
@@ -4490,11 +4541,20 @@ struct DynamicReplacementChainEntry {
4490
4541
struct DynamicReplacementKey {
4491
4542
RelativeDirectPointer<DynamicReplacementChainEntry, false > root;
4492
4543
uint32_t flags;
4544
+
4545
+ uint16_t getExtraDiscriminator () const {
4546
+ return flags & 0x0000FFFF ;
4547
+ }
4493
4548
};
4494
4549
4495
4550
// / A record describing a dynamic function replacement.
4496
4551
class DynamicReplacementDescriptor {
4497
- RelativeIndirectablePointer<DynamicReplacementKey, false > replacedFunctionKey;
4552
+ RelativeIndirectablePointer<
4553
+ const DynamicReplacementKey, false , int32_t ,
4554
+ TargetSignedPointer<InProcess,
4555
+ DynamicReplacementKey *
4556
+ __ptrauth_swift_dynamic_replacement_key>>
4557
+ replacedFunctionKey;
4498
4558
RelativeDirectPointer<void , false > replacementFunction;
4499
4559
RelativeDirectPointer<DynamicReplacementChainEntry, false > chainEntry;
4500
4560
uint32_t flags;
0 commit comments