Skip to content

Commit 101cf45

Browse files
Merge pull request #61204 from aschwaighofer/sign_function_pointer_for_enum_tag_runtime_calls
IRGen: Sign function pointers passed to swift_(store/get)EnumTagSinglePayloadGeneric calls
2 parents 67e361a + 7d28333 commit 101cf45

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,12 @@ namespace SpecialPointerAuthDiscriminators {
14361436

14371437
/// Functions accessible at runtime (i.e. distributed method accessors).
14381438
const uint16_t AccessibleFunctionRecord = 0x438c; // = 17292
1439+
1440+
/// C type GetExtraInhabitantTag function descriminator
1441+
const uint16_t GetExtraInhabitantTagFunction = 0x392e; // = 14638
1442+
1443+
/// C type StoreExtraInhabitantTag function descriminator
1444+
const uint16_t StoreExtraInhabitantTagFunction = 0x9bf6; // = 39926
14391445
}
14401446

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

include/swift/AST/IRGenOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ struct PointerAuthOptions : clang::PointerAuthOptions {
198198

199199
/// Non-unique extended existential type shapes in flight.
200200
PointerAuthSchema NonUniqueExtendedExistentialTypeShape;
201+
202+
/// C type GetExtraInhabitantTag function descriminator.
203+
PointerAuthSchema GetExtraInhabitantTagFunction;
204+
205+
/// C type StoreExtraInhabitantTag function descriminator.
206+
PointerAuthSchema StoreExtraInhabitantTagFunction;
201207
};
202208

203209
enum class JITDebugArtifact : unsigned {

lib/IRGen/GenOpaque.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,8 +1269,13 @@ irgen::emitGetEnumTagSinglePayloadGenericCall(IRGenFunction &IGF,
12691269
auto getExtraInhabitantTagFn =
12701270
getOrCreateGetExtraInhabitantTagFunction(IGF.IGM, payloadType,
12711271
payloadTI, emitter);
1272-
getExtraInhabitantTagFn =
1273-
IGF.IGM.getConstantSignedCFunctionPointer(getExtraInhabitantTagFn);
1272+
// Sign the getExtraInhabitantTag function with the C function pointer schema.
1273+
if (auto schema = IGF.IGM.getOptions().PointerAuth.FunctionPointers) {
1274+
if (schema.hasOtherDiscrimination())
1275+
schema = IGF.IGM.getOptions().PointerAuth.GetExtraInhabitantTagFunction;
1276+
getExtraInhabitantTagFn = IGF.IGM.getConstantSignedPointer(
1277+
getExtraInhabitantTagFn, schema, PointerAuthEntity(), nullptr);
1278+
}
12741279

12751280
// We assume this is never a reabstracted type.
12761281
auto type = payloadType.getASTType();
@@ -1344,8 +1349,14 @@ irgen::emitStoreEnumTagSinglePayloadGenericCall(IRGenFunction &IGF,
13441349
auto storeExtraInhabitantTagFn =
13451350
getOrCreateStoreExtraInhabitantTagFunction(IGF.IGM, payloadType,
13461351
payloadTI, emitter);
1347-
storeExtraInhabitantTagFn =
1348-
IGF.IGM.getConstantSignedCFunctionPointer(storeExtraInhabitantTagFn);
1352+
1353+
// Sign the getExtraInhabitantTag function with the C function pointer schema.
1354+
if (auto schema = IGF.IGM.getOptions().PointerAuth.FunctionPointers) {
1355+
if (schema.hasOtherDiscrimination())
1356+
schema = IGF.IGM.getOptions().PointerAuth.StoreExtraInhabitantTagFunction;
1357+
storeExtraInhabitantTagFn = IGF.IGM.getConstantSignedPointer(
1358+
storeExtraInhabitantTagFn, schema, PointerAuthEntity(), nullptr);
1359+
}
13491360

13501361
// We assume this is never a reabstracted type.
13511362
auto type = payloadType.getASTType();

lib/IRGen/IRGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,14 @@ static void setPointerAuthOptions(PointerAuthOptions &opts,
10031003
opts.ClangTypeTaskContinuationFunction = PointerAuthSchema(
10041004
codeKey, /*address*/ false, Discrimination::Constant,
10051005
SpecialPointerAuthDiscriminators::ClangTypeTaskContinuationFunction);
1006+
1007+
opts.GetExtraInhabitantTagFunction = PointerAuthSchema(
1008+
codeKey, /*address*/ false, Discrimination::Constant,
1009+
SpecialPointerAuthDiscriminators::GetExtraInhabitantTagFunction);
1010+
1011+
opts.StoreExtraInhabitantTagFunction = PointerAuthSchema(
1012+
codeKey, /*address*/ false, Discrimination::Constant,
1013+
SpecialPointerAuthDiscriminators::StoreExtraInhabitantTagFunction);
10061014
}
10071015

10081016
std::unique_ptr<llvm::TargetMachine>

0 commit comments

Comments
 (0)