Skip to content

Commit c59b01f

Browse files
committed
[Runtime] Ptrauth for runAsyncAndBlock.
rdar://72357371
1 parent 74b7341 commit c59b01f

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ namespace SpecialPointerAuthDiscriminators {
11791179
const uint16_t JobInvokeFunction = 0xcc64; // = 52324
11801180
const uint16_t TaskResumeFunction = 0x2c42; // = 11330
11811181
const uint16_t TaskResumeContext = 0x753a; // = 30010
1182+
const uint16_t AsyncRunAndBlockFunction = 0x0f08; // 3848
11821183
const uint16_t AsyncContextParent = 0xbda2; // = 48546
11831184
const uint16_t AsyncContextResume = 0xd707; // = 55047
11841185
const uint16_t AsyncContextYield = 0xe207; // = 57863

include/swift/Runtime/Config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,17 @@ static inline T swift_auth_data_non_address(T value, unsigned extra) {
327327
#endif
328328
}
329329

330+
template <typename T>
331+
SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE static inline T
332+
swift_auth_code(T value, unsigned extra) {
333+
#if SWIFT_PTRAUTH
334+
return (T)ptrauth_auth_function((void *)value,
335+
ptrauth_key_process_independent_code, extra);
336+
#else
337+
return value;
338+
#endif
339+
}
340+
330341
#endif
331342

332343
#endif // SWIFT_RUNTIME_CONFIG_H

stdlib/public/Concurrency/Task.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,22 @@ static void runAndBlock_start(AsyncTask *task, ExecutorRef executor,
430430
if (functionContext) {
431431
function = reinterpret_cast<RunAndBlockSignature::FunctionType*>(
432432
const_cast<void*>(callerContext->Function));
433+
function = swift_auth_code(
434+
function, SpecialPointerAuthDiscriminators::AsyncRunAndBlockFunction);
433435
calleeContextSize =
434436
static_cast<ThickAsyncFunctionContext*>(functionContext)
435437
->ExpectedContextSize;
436438

437439
// Otherwise, the function pointer is an async function pointer.
438440
} else {
439-
auto fnPtr = reinterpret_cast<const RunAndBlockSignature::FunctionPointer*>(
440-
callerContext->Function);
441+
auto fnPtr =
442+
reinterpret_cast<const RunAndBlockSignature::FunctionPointer *>(
443+
const_cast<void *>(callerContext->Function));
444+
#if SWIFT_PTRAUTH
445+
fnPtr = (const RunAndBlockSignature::FunctionPointer *)ptrauth_auth_data(
446+
(void *)fnPtr, ptrauth_key_process_independent_code,
447+
SpecialPointerAuthDiscriminators::AsyncRunAndBlockFunction);
448+
#endif
441449
function = fnPtr->Function;
442450
calleeContextSize = fnPtr->ExpectedContextSize;
443451
}

test/Concurrency/Runtime/class_resilience.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
// REQUIRES: executable_test
1212
// REQUIRES: concurrency
13-
14-
// REQUIRES: OS=macosx
13+
// XFAIL: windows
14+
// XFAIL: linux
1515

1616
import StdlibUnittest
1717
import resilient_class

test/Concurrency/Runtime/protocol_resilience.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
// REQUIRES: executable_test
1212
// REQUIRES: concurrency
13-
14-
// REQUIRES: OS=macosx
13+
// XFAIL: windows
14+
// UNSUPPORTED: linux
1515

1616
import StdlibUnittest
1717
import resilient_protocol

0 commit comments

Comments
 (0)