Skip to content

Commit 34996bf

Browse files
committed
[Concurrency] Give Actor enqueue(partialTask:) its own ptrauth discriminator.
For actor class's implementations of `enqueue(partialTask:)`, use a fixed ptrauth discriminator. Paired with the fixed vtable location, this allows one to invoke this operation on any native actor instance without knowing the specific type.
1 parent aeef419 commit 34996bf

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,9 @@ namespace SpecialPointerAuthDiscriminators {
11771177

11781178
/// Resilient class stub initializer callback
11791179
const uint16_t ResilientClassStubInitCallback = 0xC671;
1180+
1181+
/// Actor enqueue(partialTask:).
1182+
const uint16_t ActorEnqueuePartialTask = 0x8f3d;
11801183
}
11811184

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

lib/IRGen/GenPointerAuth.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ PointerAuthEntity::getDeclDiscriminator(IRGenModule &IGM) const {
400400
assert(!constant.isForeign &&
401401
"discriminator for foreign declaration not supported yet!");
402402

403+
// Special case: methods that are witnesses to Actor.enqueue(partialTask:)
404+
// have their own descriminator, which is shared across all actor classes.
405+
if (constant.hasFuncDecl()) {
406+
auto func = dyn_cast<FuncDecl>(constant.getFuncDecl());
407+
if (func->isActorEnqueuePartialTaskWitness()) {
408+
cache = IGM.getSize(
409+
Size(SpecialPointerAuthDiscriminators::ActorEnqueuePartialTask));
410+
return cache;
411+
}
412+
}
413+
403414
auto mangling = constant.mangle();
404415
cache = getDiscriminatorForString(IGM, mangling);
405416
return cache;

test/IRGen/ptrauth-actor.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %swift -swift-version 5 -target arm64e-apple-macos11.0 -parse-stdlib %s -emit-ir -disable-llvm-optzns -enable-experimental-concurrency -o - | %FileCheck %s
2+
3+
// REQUIRES: CODEGENERATOR=ARM
4+
// REQUIRES: concurrency
5+
// REQUIRES: CPU=arm64e
6+
// REQUIRES: OS=macosx
7+
8+
import _Concurrency
9+
import Swift
10+
11+
public actor class A1 {
12+
var x: Int = 17
13+
}
14+
15+
open actor class A3<T>: Actor {
16+
open func f() { }
17+
}
18+
19+
// enqueue(partialTask:) has the same discriminator across all classes.
20+
// CHECK: s4main2A1C7enqueue11partialTasky12_Concurrency012PartialAsyncE0V_tF.ptrauth{{.*}}i64 36669
21+
22+
// CHECK: @"$s4main2A3CyxG12_Concurrency5ActorAaeFP7enqueue11partialTaskyAE012PartialAsyncG0V_tFTW"
23+
// CHECK-NOT: ret void
24+
// CHECK: call i64 @llvm.ptrauth.blend.i64(i64 %{{[0-9]+}}, i64 36669)

0 commit comments

Comments
 (0)