Skip to content

Commit f3c687d

Browse files
committed
Add pointer auth for isolated deinit work function
1 parent a004c18 commit f3c687d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,9 @@ namespace SpecialPointerAuthDiscriminators {
17041704
const uint16_t RelativeProtocolWitnessTable = 0xb830; // = 47152
17051705

17061706
const uint16_t TypeLayoutString = 0x8b65; // = 35685
1707+
1708+
/// Isolated deinit body function pointer
1709+
const uint16_t DeinitWorkFunction = 0x8438; // = 33848
17071710
}
17081711

17091712
/// The number of arguments that will be passed directly to a generic

include/swift/Runtime/Config.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ extern uintptr_t __COMPATIBILITY_LIBRARIES_CANNOT_CHECK_THE_IS_SWIFT_BIT_DIRECTL
324324
#define __ptrauth_swift_type_layout_string \
325325
__ptrauth(ptrauth_key_process_independent_data, 1, \
326326
SpecialPointerAuthDiscriminators::TypeLayoutString)
327+
#define __ptrauth_swift_deinit_work_function \
328+
__ptrauth(ptrauth_key_function_pointer, 1, \
329+
SpecialPointerAuthDiscriminators::DeinitWorkFunction)
327330

328331
#if __has_attribute(ptrauth_struct)
329332
#define swift_ptrauth_struct(key, discriminator) \
@@ -364,6 +367,7 @@ extern uintptr_t __COMPATIBILITY_LIBRARIES_CANNOT_CHECK_THE_IS_SWIFT_BIT_DIRECTL
364367
#define swift_ptrauth_sign_opaque_read_resume_function(__fn, __buffer) (__fn)
365368
#define swift_ptrauth_sign_opaque_modify_resume_function(__fn, __buffer) (__fn)
366369
#define __ptrauth_swift_type_layout_string
370+
#define __ptrauth_swift_deinit_work_function
367371
#define swift_ptrauth_struct(key, discriminator)
368372
#define swift_ptrauth_struct_derived(from)
369373
#endif
@@ -542,6 +546,17 @@ swift_auth_code(T value, unsigned extra) {
542546
#endif
543547
}
544548

549+
template <typename T>
550+
SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE static inline T
551+
swift_auth_code_function(T value, unsigned extra) {
552+
#if SWIFT_PTRAUTH
553+
return (T)ptrauth_auth_function((void *)value,
554+
ptrauth_key_function_pointer, extra);
555+
#else
556+
return value;
557+
#endif
558+
}
559+
545560
/// Does this platform support backtrace-on-crash?
546561
#ifdef __APPLE__
547562
# include <TargetConditionals.h>

stdlib/public/Concurrency/Actor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/Runtime/Concurrency.h"
1919
#include <atomic>
2020
#include <new>
21+
#include <ptrauth.h>
2122

2223
#include "../CompatibilityOverride/CompatibilityOverride.h"
2324
#include "swift/ABI/Actor.h"
@@ -2351,6 +2352,9 @@ static void swift_task_deinitOnExecutorImpl(void *object,
23512352
DeinitWorkFunction *work,
23522353
SerialExecutorRef newExecutor,
23532354
size_t rawFlags) {
2355+
// Sign the function pointer
2356+
work = swift_auth_code_function(
2357+
work, SpecialPointerAuthDiscriminators::DeinitWorkFunction);
23542358
// If the current executor is compatible with running the new executor,
23552359
// we can just immediately continue running with the resume function
23562360
// we were passed in.

0 commit comments

Comments
 (0)