@@ -303,9 +303,39 @@ static inline void swift_ptrauth_copy(T *dest, const T *src, unsigned extra) {
303
303
#endif
304
304
}
305
305
306
- // / Initialize the destination with an address-discriminated signed pointer.
307
- // / This does not authenticate the source value, so be careful about how
308
- // / you construct it.
306
+ // / Copy an address-discriminated signed data pointer from the source
307
+ // / to the destination.
308
+ template <class T >
309
+ SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE
310
+ static inline void swift_ptrauth_copy_data (T *dest, const T *src,
311
+ unsigned extra) {
312
+ #if SWIFT_PTRAUTH
313
+ *dest = ptrauth_auth_and_resign (*src,
314
+ ptrauth_key_process_independent_data,
315
+ ptrauth_blend_discriminator (src, extra),
316
+ ptrauth_key_process_independent_data,
317
+ ptrauth_blend_discriminator (dest, extra));
318
+ #else
319
+ *dest = *src;
320
+ #endif
321
+ }
322
+
323
+ // / Copy an address-discriminated signed pointer from the source
324
+ // / to the destination.
325
+ template <class T >
326
+ SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE static inline void
327
+ swift_ptrauth_copy_code_or_data (T *dest, const T *src, unsigned extra,
328
+ bool isCode) {
329
+ if (isCode) {
330
+ return swift_ptrauth_copy (dest, src, extra);
331
+ } else {
332
+ return swift_ptrauth_copy_data (dest, src, extra);
333
+ }
334
+ }
335
+
336
+ // / Initialize the destination with an address-discriminated signed
337
+ // / function pointer. This does not authenticate the source value, so be
338
+ // / careful about how you construct it.
309
339
template <class T >
310
340
SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE
311
341
static inline void swift_ptrauth_init (T *dest, T value, unsigned extra) {
@@ -319,6 +349,35 @@ static inline void swift_ptrauth_init(T *dest, T value, unsigned extra) {
319
349
#endif
320
350
}
321
351
352
+ // / Initialize the destination with an address-discriminated signed
353
+ // / data pointer. This does not authenticate the source value, so be
354
+ // / careful about how you construct it.
355
+ template <class T >
356
+ SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE
357
+ static inline void swift_ptrauth_init_data (T *dest, T value, unsigned extra) {
358
+ // FIXME: assert that T is not a function-pointer type?
359
+ #if SWIFT_PTRAUTH
360
+ *dest = ptrauth_sign_unauthenticated (value,
361
+ ptrauth_key_process_independent_data,
362
+ ptrauth_blend_discriminator (dest, extra));
363
+ #else
364
+ *dest = value;
365
+ #endif
366
+ }
367
+
368
+ // / Initialize the destination with an address-discriminated signed
369
+ // / pointer. This does not authenticate the source value, so be
370
+ // / careful about how you construct it.
371
+ template <class T >
372
+ SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE static inline void
373
+ swift_ptrauth_init_code_or_data (T *dest, T value, unsigned extra, bool isCode) {
374
+ if (isCode) {
375
+ return swift_ptrauth_init (dest, value, extra);
376
+ } else {
377
+ return swift_ptrauth_init_data (dest, value, extra);
378
+ }
379
+ }
380
+
322
381
template <typename T>
323
382
SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE
324
383
static inline T swift_auth_data_non_address (T value, unsigned extra) {
0 commit comments