Skip to content

Commit b8ec80a

Browse files
committed
[Async CC] Resigned ptr passed to swift_task_create[_f].
When emitting Builtin.createAsyncTask[Future], the function passed to the builtin is passed along to swift_task_create[_f]. The latter is expecting a AsyncFunctionType<void()>, which is an alias for void (AsyncTask *, ExecutorRef, AsyncContext *) Previously, no ptrauth logic was emitted when emitting the builtins, so the function pointer was not signed in the way expected by swift_task_create[_f]. The result was a ptrauth failure on arm64e. Here, that problem is fixed by resigning the function pointer in the way the runtime expects.
1 parent f1d263b commit b8ec80a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,14 +3666,34 @@ llvm::Value *irgen::emitTaskCreate(
36663666
auto layout = getAsyncContextLayout(
36673667
IGF.IGM, taskFunctionCanSILType, taskFunctionCanSILType, subs);
36683668

3669+
CanSILFunctionType taskContinuationFunctionTy = [&]() {
3670+
ASTContext &ctx = IGF.IGM.IRGen.SIL.getASTContext();
3671+
auto extInfo =
3672+
ASTExtInfoBuilder()
3673+
.withRepresentation(FunctionTypeRepresentation::CFunctionPointer)
3674+
.build();
3675+
// FIXME: Use the appropriate signature for TaskContinuationFunction:
3676+
//
3677+
// using TaskContinuationFunction =
3678+
// SWIFT_CC(swift)
3679+
// void (AsyncTask *, ExecutorRef, AsyncContext *);
3680+
auto ty = FunctionType::get({}, ctx.TheEmptyTupleType, extInfo);
3681+
return IGF.IGM.getLoweredType(ty).castTo<SILFunctionType>();
3682+
}();
3683+
36693684
// Call the function.
36703685
llvm::CallInst *result;
36713686
llvm::Value *theSize, *theFunction;
3687+
auto taskFunctionPointer = FunctionPointer::forExplosionValue(
3688+
IGF, taskFunction, taskFunctionCanSILType);
36723689
std::tie(theFunction, theSize) =
36733690
getAsyncFunctionAndSize(IGF, SILFunctionTypeRepresentation::Thick,
3674-
FunctionPointer::forExplosionValue(
3675-
IGF, taskFunction, taskFunctionCanSILType),
3676-
localContextInfo);
3691+
taskFunctionPointer, localContextInfo);
3692+
if (auto authInfo = PointerAuthInfo::forFunctionPointer(
3693+
IGF.IGM, taskContinuationFunctionTy)) {
3694+
theFunction = emitPointerAuthResign(
3695+
IGF, theFunction, taskFunctionPointer.getAuthInfo(), authInfo);
3696+
}
36773697
theFunction = IGF.Builder.CreateBitOrPointerCast(
36783698
theFunction, IGF.IGM.TaskContinuationFunctionPtrTy);
36793699
theSize = IGF.Builder.CreateZExtOrBitCast(theSize, IGF.IGM.SizeTy);

0 commit comments

Comments
 (0)