Files
swift-mirror/test/Interpreter/Inputs/retain_release_wrappers.c
Mike Ash 13b58a0b5c [Runtime] Fix strong and unowned refcount overflow on 32-bit.
Fix overflow detection on unowned refcounts so that we create a side table when incrementing from 126. Implement strong refcount overflow to the side table.

The unowned refcount is never supposed to be 127, because that (sometimes) represents the immortal refcount. We attempt to detect that by checking newValue == Offsets::UnownedRefCountMask, but the mask is shifted so that condition is never true. We managed to hit the side table case when incrementing from 127, because it looks like the immortal case. But that broke when we fixed immortal side table initialization in b41079a8f54ae2d61c68cdda46c74232084af020. With that change, we now create an immortal side table when overflowing the unowned refcount, then try to increment the unowned refcount in that immortal side table, which traps.

rdar://123788910
2024-03-01 09:42:45 -05:00

47 lines
1.3 KiB
C

#include <stdint.h>
void *swift_retain_n(void *, uint32_t);
void swift_release_n(void *, uint32_t);
void *swift_nonatomic_retain_n(void *, uint32_t);
void swift_nonatomic_release_n(void *, uint32_t);
void *swift_unownedRetain_n(void *, uint32_t);
void swift_unownedRelease_n(void *, uint32_t);
void *swift_nonatomic_unownedRetain_n(void *, uint32_t);
void swift_nonatomic_unownedRelease_n(void *, uint32_t);
// Wrappers so we can call these from Swift without upsetting the ARC optimizer.
void *wrapper_swift_retain_n(void *obj, uint32_t n) {
return swift_retain_n(obj, n);
}
void wrapper_swift_release_n(void *obj, uint32_t n) {
swift_release_n(obj, n);
}
void *wrapper_swift_nonatomic_retain_n(void *obj, uint32_t n) {
return swift_nonatomic_retain_n(obj, n);
}
void wrapper_swift_nonatomic_release_n(void *obj, uint32_t n) {
swift_nonatomic_release_n(obj, n);
}
void *wrapper_swift_unownedRetain_n(void *obj, uint32_t n) {
return swift_unownedRetain_n(obj, n);
}
void wrapper_swift_unownedRelease_n(void *obj, uint32_t n) {
swift_unownedRelease_n(obj, n);
}
void *wrapper_swift_nonatomic_unownedRetain_n(void *obj, uint32_t n) {
return swift_nonatomic_unownedRetain_n(obj, n);
}
void wrapper_swift_nonatomic_unownedRelease_n(void *obj, uint32_t n) {
swift_nonatomic_unownedRelease_n(obj, n);
}