[Runtime][IRGen] Sign type context descriptor pointers.

Ensure that context descriptor pointers are signed in the runtime by putting the ptrauth_struct attribute on the types.

We use the new __builtin_ptrauth_struct_key/disc to conditionally apply ptrauth_struct to TrailingObjects based on the signing of the base type, so that pointers to TrailingObjects get signed when used with a context descriptor pointer.

We add new runtime entrypoints that take signed pointers where appropriate, and have the compiler emit calls to the new entrypoints when targeting a sufficiently new OS.

rdar://111480914
This commit is contained in:
Mike Ash
2023-06-30 11:58:17 -04:00
parent 6f8fd07bdf
commit fe7e13bba5
29 changed files with 519 additions and 75 deletions

View File

@@ -1147,8 +1147,8 @@ swift_conformsToProtocolMaybeInstantiateSuperclasses(
}
static const WitnessTable *
swift_conformsToProtocolImpl(const Metadata *const type,
const ProtocolDescriptor *protocol) {
swift_conformsToProtocolCommonImpl(const Metadata *const type,
const ProtocolDescriptor *protocol) {
const WitnessTable *table;
bool hasUninstantiatedSuperclass;
@@ -1173,6 +1173,26 @@ swift_conformsToProtocolImpl(const Metadata *const type,
return table;
}
static const WitnessTable *
swift_conformsToProtocol2Impl(const Metadata *const type,
const ProtocolDescriptor *protocol) {
protocol = swift_auth_data_non_address(
protocol, SpecialPointerAuthDiscriminators::ProtocolDescriptor);
return swift_conformsToProtocolCommonImpl(type, protocol);
}
static const WitnessTable *
swift_conformsToProtocolImpl(const Metadata *const type,
const void *protocol) {
// This call takes `protocol` without a ptrauth signature. We declare
// it as `void *` to avoid the implicit ptrauth we get from the
// ptrauth_struct attribute. The static_cast implicitly signs the
// pointer when we call through to the implementation in
// swift_conformsToProtocolCommon.
return swift_conformsToProtocolCommonImpl(
type, static_cast<const ProtocolDescriptor *>(protocol));
}
const ContextDescriptor *
swift::_searchConformancesByMangledTypeName(Demangle::NodePointer node) {
auto traceState = runtime::trace::protocol_conformance_scan_begin(node);