From ac4c39a9d02d8c5400e25cdf45ea375ac58e07d7 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Fri, 17 Jan 2025 17:17:44 -0500 Subject: [PATCH 1/2] Remove arm64e ptrauth resigning from test content discovery. Finally got around to double-checking and we don't need to do ptrauth resigning on the `accessor` function pointers in the new test content section as dyld already does it for us at load time. --- Sources/Testing/Discovery.swift | 2 +- Sources/_TestingInternals/Discovery.cpp | 1 + Sources/_TestingInternals/include/Discovery.h | 19 ------------------- Sources/_TestingInternals/include/Includes.h | 4 ---- 4 files changed, 2 insertions(+), 24 deletions(-) diff --git a/Sources/Testing/Discovery.swift b/Sources/Testing/Discovery.swift index 5ce454d1c..2ad44b324 100644 --- a/Sources/Testing/Discovery.swift +++ b/Sources/Testing/Discovery.swift @@ -116,7 +116,7 @@ extension TestContentRecord where T: TestContent & ~Copyable { /// If this function is called more than once on the same instance, a new /// value is created on each call. func load(withHint hint: T.TestContentAccessorHint? = nil) -> T.TestContentAccessorResult? { - guard let accessor = _record.accessor.map(swt_resign) else { + guard let accessor = _record.accessor else { return nil } diff --git a/Sources/_TestingInternals/Discovery.cpp b/Sources/_TestingInternals/Discovery.cpp index 6173126c1..314b7794d 100644 --- a/Sources/_TestingInternals/Discovery.cpp +++ b/Sources/_TestingInternals/Discovery.cpp @@ -47,6 +47,7 @@ const void *_Nonnull const SWTTypeMetadataSectionBounds[2] = { #pragma mark - Swift ABI #if defined(__PTRAUTH_INTRINSICS__) +#include #define SWT_PTRAUTH_SWIFT_TYPE_DESCRIPTOR __ptrauth(ptrauth_key_process_independent_data, 1, 0xae86) #else #define SWT_PTRAUTH_SWIFT_TYPE_DESCRIPTOR diff --git a/Sources/_TestingInternals/include/Discovery.h b/Sources/_TestingInternals/include/Discovery.h index 9d84b9f8c..d333ff21f 100644 --- a/Sources/_TestingInternals/include/Discovery.h +++ b/Sources/_TestingInternals/include/Discovery.h @@ -31,25 +31,6 @@ SWT_ASSUME_NONNULL_BEGIN /// the memory at `outValue` when done. typedef bool (* SWTTestContentAccessor)(void *outValue, const void *_Null_unspecified hint); -/// Resign an accessor function from a test content record. -/// -/// - Parameters: -/// - accessor: The accessor function to resign. -/// -/// - Returns: A resigned copy of `accessor` on platforms that use pointer -/// authentication, and an exact copy of `accessor` elsewhere. -/// -/// - Bug: This C function is needed because Apple's pointer authentication -/// intrinsics are not available in Swift. ([141465242](rdar://141465242)) -SWT_SWIFT_NAME(swt_resign(_:)) -static SWTTestContentAccessor swt_resignTestContentAccessor(SWTTestContentAccessor accessor) { -#if defined(__APPLE__) && __has_include() - accessor = ptrauth_strip(accessor, ptrauth_key_function_pointer); - accessor = ptrauth_sign_unauthenticated(accessor, ptrauth_key_function_pointer, 0); -#endif - return accessor; -} - #if defined(__ELF__) && defined(__swift__) /// A function exported by the Swift runtime that enumerates all metadata /// sections loaded into the current process. diff --git a/Sources/_TestingInternals/include/Includes.h b/Sources/_TestingInternals/include/Includes.h index dfcbf50f0..b1f4c7973 100644 --- a/Sources/_TestingInternals/include/Includes.h +++ b/Sources/_TestingInternals/include/Includes.h @@ -127,10 +127,6 @@ #if !SWT_NO_LIBDISPATCH #include #endif - -#if __has_include() -#include -#endif #endif #if defined(__FreeBSD__) From d91d5a33842011c95407b5612a7157163f709e3d Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Fri, 17 Jan 2025 18:17:14 -0500 Subject: [PATCH 2/2] Delete SWTTestContentAccessor typealias too --- Sources/_TestingInternals/include/Discovery.h | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/Sources/_TestingInternals/include/Discovery.h b/Sources/_TestingInternals/include/Discovery.h index d333ff21f..8fc36d8c7 100644 --- a/Sources/_TestingInternals/include/Discovery.h +++ b/Sources/_TestingInternals/include/Discovery.h @@ -16,22 +16,9 @@ SWT_ASSUME_NONNULL_BEGIN -#pragma mark - Test content records - -/// The type of a test content accessor. -/// -/// - Parameters: -/// - outValue: On successful return, initialized to the value of the -/// represented test content record. -/// - hint: A hint value whose type and meaning depend on the type of test -/// record being accessed. -/// -/// - Returns: Whether or not the test record was initialized at `outValue`. If -/// this function returns `true`, the caller is responsible for deinitializing -/// the memory at `outValue` when done. -typedef bool (* SWTTestContentAccessor)(void *outValue, const void *_Null_unspecified hint); - #if defined(__ELF__) && defined(__swift__) +#pragma mark - ELF image enumeration + /// A function exported by the Swift runtime that enumerates all metadata /// sections loaded into the current process. ///