@@ -111,21 +111,33 @@ static HeapObject *_swift_tryRetain_(HeapObject *object)
111
111
#ifdef SWIFT_STDLIB_OVERRIDABLE_RETAIN_RELEASE
112
112
113
113
#define CALL_IMPL (name, args ) do { \
114
- void *fptr; \
115
- memcpy (&fptr, (void *)&_ ## name, sizeof (fptr)); \
116
- extern char _ ## name ## _as_char asm (" __" #name " _" ); \
117
- fptr = __ptrauth_swift_runtime_function_entry_strip (fptr); \
118
- if (SWIFT_UNLIKELY (fptr != &_ ## name ## _as_char)) \
119
- return _ ## name args; \
120
- return _ ## name ## _ args; \
114
+ if (SWIFT_UNLIKELY (_swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstrumentsOnly.load (std::memory_order_relaxed))) \
115
+ return _ ## name args; \
116
+ return _ ## name ## _ args; \
121
117
} while (0 )
122
118
119
+ #define CALL_IMPL_CHECK (name, args ) do { \
120
+ void *fptr; \
121
+ memcpy (&fptr, (void *)&_ ## name, sizeof (fptr)); \
122
+ extern char _ ## name ## _as_char asm (" __" #name " _" ); \
123
+ fptr = __ptrauth_swift_runtime_function_entry_strip (fptr); \
124
+ if (SWIFT_UNLIKELY (fptr != &_ ## name ## _as_char)) { \
125
+ if (SWIFT_UNLIKELY (!_swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstrumentsOnly.load (std::memory_order_relaxed))) { \
126
+ _swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstrumentsOnly.store (true , std::memory_order_relaxed); \
127
+ } \
128
+ return _ ## name args; \
129
+ } \
130
+ return _ ## name ## _ args; \
131
+ } while (0 )
123
132
#else
124
133
125
134
// If retain/release etc. aren't overridable, just call the real implementation.
126
135
#define CALL_IMPL (name, args ) \
127
136
return _ ## name ## _ args;
128
137
138
+ #define CALL_IMPL_CHECK (name, args ) \
139
+ return _ ## name ## _ args;
140
+
129
141
#endif
130
142
131
143
#if SWIFT_STDLIB_HAS_MALLOC_TYPE
@@ -230,6 +242,9 @@ HeapObject *(*SWIFT_RT_DECLARE_ENTRY _swift_allocObject)(
230
242
HeapMetadata const *metadata, size_t requiredSize,
231
243
size_t requiredAlignmentMask) = _swift_allocObject_;
232
244
245
+ SWIFT_RUNTIME_EXPORT
246
+ std::atomic<bool > _swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstrumentsOnly = false ;
247
+
233
248
SWIFT_RUNTIME_EXPORT
234
249
HeapObject *(*SWIFT_RT_DECLARE_ENTRY _swift_retain)(HeapObject *object) =
235
250
_swift_retain_;
@@ -280,7 +295,7 @@ static HeapObject *_swift_allocObject_(HeapMetadata const *metadata,
280
295
HeapObject *swift::swift_allocObject (HeapMetadata const *metadata,
281
296
size_t requiredSize,
282
297
size_t requiredAlignmentMask) {
283
- CALL_IMPL (swift_allocObject, (metadata, requiredSize, requiredAlignmentMask));
298
+ CALL_IMPL_CHECK (swift_allocObject, (metadata, requiredSize, requiredAlignmentMask));
284
299
}
285
300
286
301
HeapObject *
0 commit comments