From b718c506dae1f19e93f14c27fad378c421e78b8a Mon Sep 17 00:00:00 2001 From: Kuba Mracek Date: Tue, 26 Sep 2023 12:30:21 -0700 Subject: [PATCH] [embedded] Fix arm64e pointer signing in embedded heap object destruction --- stdlib/public/SwiftShims/swift/shims/EmbeddedShims.h | 11 ++++++++--- stdlib/public/core/EmbeddedRuntime.swift | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/stdlib/public/SwiftShims/swift/shims/EmbeddedShims.h b/stdlib/public/SwiftShims/swift/shims/EmbeddedShims.h index ce53f2a5a04..2d23a9f90fa 100644 --- a/stdlib/public/SwiftShims/swift/shims/EmbeddedShims.h +++ b/stdlib/public/SwiftShims/swift/shims/EmbeddedShims.h @@ -33,9 +33,14 @@ extern "C" { typedef void SWIFT_CC (*HeapObjectDestroyer)(SWIFT_CONTEXT void *object); -static inline void _swift_runtime_invoke_heap_object_destroy( - const void *destroy, void *self) { - ((HeapObjectDestroyer)destroy)(self); +static inline void _swift_embedded_invoke_heap_object_destroy(void *object) { + void *metadata = *(void **)object; + void **destroy_location = &((void **)metadata)[1]; +#if __has_feature(ptrauth_calls) + (*(__ptrauth(0,1,0xbbbf) HeapObjectDestroyer *)destroy_location)(object); +#else + (*(HeapObjectDestroyer *)destroy_location)(object); +#endif } #ifdef __cplusplus diff --git a/stdlib/public/core/EmbeddedRuntime.swift b/stdlib/public/core/EmbeddedRuntime.swift index 38ba7ec1d7a..353282829e1 100644 --- a/stdlib/public/core/EmbeddedRuntime.swift +++ b/stdlib/public/core/EmbeddedRuntime.swift @@ -117,7 +117,7 @@ public func swift_release(object: Builtin.RawPointer) { if o.pointee.refcount == HeapObject.immortalRefCount { return } o.pointee.refcount -= 1 if (o.pointee.refcount & HeapObject.refcountMask) == 0 { - _swift_runtime_invoke_heap_object_destroy(o.pointee.metadata.pointee.destroy, o) + _swift_embedded_invoke_heap_object_destroy(o) } }