Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 56 additions & 30 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,24 @@ template <typename Runtime> struct TargetOpaqueMetadata;
template <typename Runtime> struct TargetValueMetadata;
template <typename Runtime> struct TargetForeignClassMetadata;
template <typename Runtime> struct TargetForeignReferenceTypeMetadata;
template <typename Runtime> struct TargetContextDescriptor;
template <typename Runtime> class TargetTypeContextDescriptor;
template <typename Runtime> class TargetClassDescriptor;
template <typename Runtime> class TargetValueTypeDescriptor;
template <typename Runtime> class TargetEnumDescriptor;
template <typename Runtime> class TargetStructDescriptor;
template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(ContextDescriptor)
TargetContextDescriptor;
template <typename Runtime>
class swift_ptrauth_struct_context_descriptor(TypeContextDescriptor)
TargetTypeContextDescriptor;
template <typename Runtime>
class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
TargetClassDescriptor;
template <typename Runtime>
class swift_ptrauth_struct_context_descriptor(ValueTypeDescriptor)
TargetValueTypeDescriptor;
template <typename Runtime>
class swift_ptrauth_struct_context_descriptor(EnumDescriptor)
TargetEnumDescriptor;
template <typename Runtime>
class swift_ptrauth_struct_context_descriptor(StructDescriptor)
TargetStructDescriptor;
template <typename Runtime> struct TargetGenericMetadataPattern;
template <typename Runtime> struct TargetProtocolConformanceDescriptor;

Expand Down Expand Up @@ -1632,7 +1644,9 @@ TargetTupleTypeMetadata<Runtime>::getOffsetToNumElements() -> StoredSize {
return offsetof(TargetTupleTypeMetadata<Runtime>, NumElements);
}

template <typename Runtime> struct TargetProtocolDescriptor;
template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(ProtocolDescriptor)
TargetProtocolDescriptor;

/// A protocol requirement descriptor. This describes a single protocol
/// requirement in a protocol descriptor. The index of the requirement in
Expand Down Expand Up @@ -1660,7 +1674,9 @@ struct TargetProtocolRequirement {

using ProtocolRequirement = TargetProtocolRequirement<InProcess>;

template<typename Runtime> struct TargetProtocolDescriptor;
template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(ProtocolDescriptor)
TargetProtocolDescriptor;
using ProtocolDescriptor = TargetProtocolDescriptor<InProcess>;

template<template <typename Runtime> class ObjCInteropKind, unsigned PointerSize>
Expand Down Expand Up @@ -2803,12 +2819,14 @@ using ExternalProtocolConformanceDescriptor = TargetProtocolConformanceDescripto
template<template <typename Runtime> class ObjCInteropKind, unsigned PointerSize>
using ExternalProtocolConformanceRecord = TargetProtocolConformanceRecord<External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;

template<typename Runtime>
struct TargetModuleContextDescriptor;
template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(ModuleContextDescriptor)
TargetModuleContextDescriptor;

/// Base class for all context descriptors.
template<typename Runtime>
struct TargetContextDescriptor {
template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(ContextDescriptor)
TargetContextDescriptor {
/// Flags describing the context, including its kind and format version.
ContextDescriptorFlags Flags;

Expand Down Expand Up @@ -2864,8 +2882,9 @@ inline bool isCImportedModuleName(llvm::StringRef name) {
}

/// Descriptor for a module context.
template<typename Runtime>
struct TargetModuleContextDescriptor final : TargetContextDescriptor<Runtime> {
template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(ModuleContextDescriptor)
TargetModuleContextDescriptor final : TargetContextDescriptor<Runtime> {
/// The module name.
RelativeDirectPointer<const char, /*nullable*/ false> Name;

Expand Down Expand Up @@ -2905,8 +2924,9 @@ TargetContextDescriptor<Runtime>::getModuleContext() const {
}

/// Descriptor for an extension context.
template<typename Runtime>
struct TargetExtensionContextDescriptor final
template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(ExtensionContextDescriptor)
TargetExtensionContextDescriptor final
: TargetContextDescriptor<Runtime>,
TrailingGenericContextObjects<TargetExtensionContextDescriptor<Runtime>>
{
Expand Down Expand Up @@ -2944,8 +2964,9 @@ struct TargetMangledContextName {
TargetRelativeDirectPointer<Runtime, const char, /*nullable*/ false> name;
};

template<typename Runtime>
struct TargetAnonymousContextDescriptor final
template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(AnonymousContextDescriptor)
TargetAnonymousContextDescriptor final
: TargetContextDescriptor<Runtime>,
TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>,
TargetGenericContextDescriptorHeader,
Expand Down Expand Up @@ -3025,8 +3046,9 @@ using ExternalAnonymousContextDescriptor = TargetAnonymousContextDescriptor<Exte
/// Only Swift protocols are defined by a protocol descriptor, whereas
/// Objective-C (including protocols defined in Swift as @objc) use the
/// Objective-C protocol layout.
template<typename Runtime>
struct TargetProtocolDescriptor final
template <typename Runtime>
struct swift_ptrauth_struct_context_descriptor(ProtocolDescriptor)
TargetProtocolDescriptor final
: TargetContextDescriptor<Runtime>,
swift::ABI::TrailingObjects<
TargetProtocolDescriptor<Runtime>,
Expand Down Expand Up @@ -3114,11 +3136,12 @@ struct TargetProtocolDescriptor final
return cd->getKind() == ContextDescriptorKind::Protocol;
}
};

/// The descriptor for an opaque type.
template <typename Runtime>
struct TargetOpaqueTypeDescriptor final
: TargetContextDescriptor<Runtime>,
struct swift_ptrauth_struct_context_descriptor(OpaqueTypeDescriptor)
TargetOpaqueTypeDescriptor final
: TargetContextDescriptor<Runtime>,
TrailingGenericContextObjects<TargetOpaqueTypeDescriptor<Runtime>,
TargetGenericContextDescriptorHeader,
RelativeDirectPointer<const char>>
Expand Down Expand Up @@ -3694,8 +3717,8 @@ struct TargetCanonicalSpecializedMetadatasCachingOnceToken {
};

template <typename Runtime>
class TargetTypeContextDescriptor
: public TargetContextDescriptor<Runtime> {
class swift_ptrauth_struct_context_descriptor(TypeContextDescriptor)
TargetTypeContextDescriptor : public TargetContextDescriptor<Runtime> {
public:
/// The name of the type.
TargetRelativeDirectPointer<Runtime, const char, /*nullable*/ false> Name;
Expand Down Expand Up @@ -3917,7 +3940,8 @@ struct TargetObjCResilientClassStubInfo {
};

template <typename Runtime>
class TargetClassDescriptor final
class swift_ptrauth_struct_context_descriptor(ClassDescriptor)
TargetClassDescriptor final
: public TargetTypeContextDescriptor<Runtime>,
public TrailingGenericContextObjects<TargetClassDescriptor<Runtime>,
TargetTypeGenericContextDescriptorHeader,
Expand Down Expand Up @@ -4307,8 +4331,8 @@ class TargetClassDescriptor final
using ClassDescriptor = TargetClassDescriptor<InProcess>;

template <typename Runtime>
class TargetValueTypeDescriptor
: public TargetTypeContextDescriptor<Runtime> {
class swift_ptrauth_struct_context_descriptor(ValueTypeDescriptor)
TargetValueTypeDescriptor : public TargetTypeContextDescriptor<Runtime>{
public:
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
return cd->getKind() == ContextDescriptorKind::Struct ||
Expand All @@ -4318,7 +4342,8 @@ class TargetValueTypeDescriptor
using ValueTypeDescriptor = TargetValueTypeDescriptor<InProcess>;

template <typename Runtime>
class TargetStructDescriptor final
class swift_ptrauth_struct_context_descriptor(StructDescriptor)
TargetStructDescriptor final
: public TargetValueTypeDescriptor<Runtime>,
public TrailingGenericContextObjects<TargetStructDescriptor<Runtime>,
TargetTypeGenericContextDescriptorHeader,
Expand Down Expand Up @@ -4445,7 +4470,8 @@ class TargetStructDescriptor final
using StructDescriptor = TargetStructDescriptor<InProcess>;

template <typename Runtime>
class TargetEnumDescriptor final
class swift_ptrauth_struct_context_descriptor(EnumDescriptor)
TargetEnumDescriptor final
: public TargetValueTypeDescriptor<Runtime>,
public TrailingGenericContextObjects<TargetEnumDescriptor<Runtime>,
TargetTypeGenericContextDescriptorHeader,
Expand Down
6 changes: 4 additions & 2 deletions include/swift/ABI/MetadataRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ struct TargetAnyClassMetadataObjCInterop;
template <typename Runtime, typename TargetAnyClassMetadataVariant>
struct TargetClassMetadata;
template <typename Runtime>
struct TargetContextDescriptor;
struct swift_ptrauth_struct_context_descriptor(ContextDescriptor)
TargetContextDescriptor;
template <typename Runtime>
struct TargetProtocolDescriptor;
struct swift_ptrauth_struct_context_descriptor(ProtocolDescriptor)
TargetProtocolDescriptor;

namespace detail {
template <typename Runtime, bool ObjCInterop = Runtime::ObjCInterop>
Expand Down
6 changes: 6 additions & 0 deletions include/swift/ABI/MetadataValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,12 @@ namespace SpecialPointerAuthDiscriminators {
/// Protocol conformance descriptors.
const uint16_t ProtocolConformanceDescriptor = 0xc6eb;

const uint16_t ProtocolDescriptor = 0xe909; // = 59657

// Type descriptors as arguments.
const uint16_t OpaqueTypeDescriptor = 0xbdd1; // = 48593
const uint16_t ContextDescriptor = 0xb5e3; // = 46563

/// Pointer to value witness table stored in type metadata.
///
/// Computed with ptrauth_string_discriminator("value_witness_table_t").
Expand Down
3 changes: 2 additions & 1 deletion include/swift/ABI/TrailingObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ class TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy>
/// See the file comment for details on the usage of the
/// TrailingObjects type.
template <typename BaseTy, typename... TrailingTys>
class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<
class swift_ptrauth_struct_derived(BaseTy) TrailingObjects
: private trailing_objects_internal::TrailingObjectsImpl<
trailing_objects_internal::AlignmentCalcHelper<
TrailingTys...>::Alignment,
BaseTy, TrailingObjects<BaseTy, TrailingTys...>,
Expand Down
5 changes: 4 additions & 1 deletion include/swift/ABI/TypeIdentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
#define SWIFT_ABI_TYPEIDENTITY_H

#include "swift/Basic/LLVM.h"
#include "swift/Runtime/Config.h"
#include <llvm/ADT/Optional.h>
#include <llvm/ADT/StringRef.h>

namespace swift {
template <class> class TargetTypeContextDescriptor;
template <typename Runtime>
class swift_ptrauth_struct_context_descriptor(TypeContextDescriptor)
TargetTypeContextDescriptor;
struct InProcess;
using TypeContextDescriptor = TargetTypeContextDescriptor<InProcess>;

Expand Down
8 changes: 8 additions & 0 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,14 @@ class ASTContext final {
/// variadic generic types.
AvailabilityContext getVariadicGenericTypeAvailability();

/// Get the runtime availability of the conformsToProtocol runtime entrypoint
/// that takes a signed protocol descriptor pointer.
AvailabilityContext getSignedConformsToProtocolAvailability();

/// Get the runtime availability of runtime entrypoints that take signed type
/// descriptors.
AvailabilityContext getSignedDescriptorAvailability();

/// Get the runtime availability of features introduced in the Swift 5.2
/// compiler for the target platform.
AvailabilityContext getSwift52Availability();
Expand Down
9 changes: 9 additions & 0 deletions include/swift/AST/IRGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ struct PointerAuthOptions : clang::PointerAuthOptions {
/// Protocol conformance descriptors when passed as arguments.
PointerAuthSchema ProtocolConformanceDescriptorsAsArguments;

/// Protocol descriptors when passed as arguments.
PointerAuthSchema ProtocolDescriptorsAsArguments;

/// Opaque type descriptors when passed as arguments.
PointerAuthSchema OpaqueTypeDescriptorsAsArguments;

/// Type context descriptors when passed as arguments.
PointerAuthSchema ContextDescriptorsAsArguments;

/// Resumption functions from yield-once coroutines.
PointerAuthSchema YieldOnceResumeFunctions;

Expand Down
19 changes: 17 additions & 2 deletions include/swift/Runtime/Casting.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,26 @@ const Metadata *swift_getObjectType(HeapObject *object);
/// \param type The metadata for the type for which to do the conformance
/// check.
/// \param protocol The protocol descriptor for the protocol to check
/// conformance for.
/// conformance for. This pointer does not have ptrauth applied.
SWIFT_RUNTIME_EXPORT
const WitnessTable *swift_conformsToProtocol(const Metadata *type,
const ProtocolDescriptor *protocol);
const void *protocol);

/// Check whether a type conforms to a given native Swift protocol. Identical to
/// swift_conformsToProtocol, except that the protocol parameter has a ptrauth
/// signature on ARM64e that is signed with a process independent key.
SWIFT_RUNTIME_EXPORT
const WitnessTable *
swift_conformsToProtocol2(const Metadata *type,
const ProtocolDescriptor *protocol);

/// Check whether a type conforms to a given native Swift protocol. Identical to
/// swift_conformsToProtocol, except that the protocol parameter has a ptrauth
/// signature on ARM64e that is signed with a process dependent key.
SWIFT_RUNTIME_EXPORT
const WitnessTable *
swift_conformsToProtocolCommon(const Metadata *type,
const ProtocolDescriptor *protocol);
} // end namespace swift

#endif // SWIFT_RUNTIME_CASTING_H
Loading