Skip to content

Commit 87a0ba6

Browse files
authored
Merge pull request #68769 from kubamracek/embedded-arm64e-destroy
[embedded] Fix arm64e pointer signing in embedded heap object destruction
2 parents cae97a8 + a46abb0 commit 87a0ba6

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@
2828
extern "C" {
2929
#endif
3030

31-
#define SWIFT_CC __attribute__((swiftcall))
32-
#define SWIFT_CONTEXT __attribute__((swift_context))
33-
34-
typedef void SWIFT_CC (*HeapObjectDestroyer)(SWIFT_CONTEXT void *object);
35-
36-
static inline void _swift_runtime_invoke_heap_object_destroy(
37-
const void *destroy, void *self) {
38-
((HeapObjectDestroyer)destroy)(self);
31+
typedef void __attribute__((swiftcall)) (*HeapObjectDestroyer)(
32+
__attribute__((swift_context)) void *object);
33+
34+
static inline void _swift_embedded_invoke_heap_object_destroy(void *object) {
35+
void *metadata = *(void **)object;
36+
void **destroy_location = &((void **)metadata)[1];
37+
#if __has_feature(ptrauth_calls)
38+
(*(HeapObjectDestroyer __ptrauth(0,1,0xbbbf) *)destroy_location)(object);
39+
#else
40+
(*(HeapObjectDestroyer *)destroy_location)(object);
41+
#endif
3942
}
4043

4144
#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)