Skip to content

Commit f1d263b

Browse files
committed
[Async CC] Fixed ptrauth for dynamic ptrs in partial applies.
A partial apply of an async non-direct function entails storing a pointer to the function's AsyncFunctionPointer into the thick context using a specific (IGM.getOptions().PointerAuth.PartialApplyCapture) ptrauth schema. Previously, the incorrect schema (derived from the function type) was used to auth the ptr-to-AsyncFunctionPointer and then to again sign the ptr-to-function. Here that error is corrected. Now, the pointer-to-AsyncFunctionPointer is auth'd using that specific schema and then the extracted function pointer is again signed again using it.
1 parent eac9cfc commit f1d263b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ class PartialApplicationForwarderEmission {
769769
virtual void addArgument(llvm::Value *argValue, unsigned index) = 0;
770770
virtual SILParameterInfo getParameterInfo(unsigned index) = 0;
771771
virtual llvm::Value *getContext() = 0;
772-
virtual llvm::Value *getDynamicFunctionPointer() = 0;
772+
virtual llvm::Value *getDynamicFunctionPointer(PointerAuthInfo &authInfo) = 0;
773773
virtual llvm::Value *getDynamicFunctionContext() = 0;
774774
virtual void addDynamicFunctionContext(Explosion &explosion,
775775
DynamicFunctionKind kind) = 0;
@@ -931,7 +931,9 @@ class SyncPartialApplicationForwarderEmission
931931
return substType->getParameters()[index];
932932
}
933933
llvm::Value *getContext() override { return origParams.claimNext(); }
934-
llvm::Value *getDynamicFunctionPointer() override { return args.takeLast(); }
934+
llvm::Value *getDynamicFunctionPointer(PointerAuthInfo &authInfo) override {
935+
return args.takeLast();
936+
}
935937
llvm::Value *getDynamicFunctionContext() override { return args.takeLast(); }
936938
void addDynamicFunctionContext(Explosion &explosion,
937939
DynamicFunctionKind kind) override {
@@ -1127,15 +1129,14 @@ class AsyncPartialApplicationForwarderEmission
11271129
llvm::Value *getContext() override {
11281130
return loadValue(layout.getLocalContextLayout());
11291131
}
1130-
llvm::Value *getDynamicFunctionPointer() override {
1132+
llvm::Value *getDynamicFunctionPointer(PointerAuthInfo &authInfo) override {
11311133
assert(dynamicFunction && dynamicFunction->pointer);
11321134
auto *context = dynamicFunction->context;
11331135
if (!context) {
11341136
return dynamicFunction->pointer;
11351137
}
11361138
auto *rawFunction = subIGF.Builder.CreateBitCast(
11371139
dynamicFunction->pointer, origSig.getType()->getPointerTo());
1138-
auto authInfo = PointerAuthInfo::forFunctionPointer(IGM, origType);
11391140
auto functionPointer =
11401141
FunctionPointer(FunctionPointer::KindTy::AsyncFunctionPointer,
11411142
rawFunction, authInfo, origSig);
@@ -1719,19 +1720,19 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
17191720

17201721
// Otherwise, it was the last thing we added to the layout.
17211722

1722-
// The dynamic function pointer is packed "last" into the context,
1723-
// and we pulled it out as an argument. Just pop it off.
1724-
auto fnPtr = emission->getDynamicFunctionPointer();
1725-
1726-
// It comes out of the context as an i8*. Cast to the function type.
1727-
fnPtr = subIGF.Builder.CreateBitCast(fnPtr, fnTy);
1728-
17291723
assert(lastCapturedFieldPtr);
17301724
auto authInfo = PointerAuthInfo::emit(subIGF,
17311725
IGM.getOptions().PointerAuth.PartialApplyCapture,
17321726
lastCapturedFieldPtr,
17331727
PointerAuthEntity::Special::PartialApplyCapture);
17341728

1729+
// The dynamic function pointer is packed "last" into the context,
1730+
// and we pulled it out as an argument. Just pop it off.
1731+
auto fnPtr = emission->getDynamicFunctionPointer(authInfo);
1732+
1733+
// It comes out of the context as an i8*. Cast to the function type.
1734+
fnPtr = subIGF.Builder.CreateBitCast(fnPtr, fnTy);
1735+
17351736
return FunctionPointer(FunctionPointer::KindTy::Function, fnPtr, authInfo,
17361737
origSig);
17371738
}();

0 commit comments

Comments
 (0)