Skip to content

Commit b718c50

Browse files
committed
[embedded] Fix arm64e pointer signing in embedded heap object destruction
1 parent e4dc627 commit b718c50

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

stdlib/public/SwiftShims/swift/shims/EmbeddedShims.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ extern "C" {
3333

3434
typedef void SWIFT_CC (*HeapObjectDestroyer)(SWIFT_CONTEXT void *object);
3535

36-
static inline void _swift_runtime_invoke_heap_object_destroy(
37-
const void *destroy, void *self) {
38-
((HeapObjectDestroyer)destroy)(self);
36+
static inline void _swift_embedded_invoke_heap_object_destroy(void *object) {
37+
void *metadata = *(void **)object;
38+
void **destroy_location = &((void **)metadata)[1];
39+
#if __has_feature(ptrauth_calls)
40+
(*(__ptrauth(0,1,0xbbbf) HeapObjectDestroyer *)destroy_location)(object);
41+
#else
42+
(*(HeapObjectDestroyer *)destroy_location)(object);
43+
#endif
3944
}
4045

4146
#ifdef __cplusplus

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public func swift_release(object: Builtin.RawPointer) {
117117
if o.pointee.refcount == HeapObject.immortalRefCount { return }
118118
o.pointee.refcount -= 1
119119
if (o.pointee.refcount & HeapObject.refcountMask) == 0 {
120-
_swift_runtime_invoke_heap_object_destroy(o.pointee.metadata.pointee.destroy, o)
120+
_swift_embedded_invoke_heap_object_destroy(o)
121121
}
122122
}
123123

0 commit comments

Comments
 (0)