@@ -130,6 +130,7 @@ typedef void* dispatch_queue_t;
130
130
typedef void * dispatch_source_t ;
131
131
typedef u64 dispatch_time_t ;
132
132
typedef void (*dispatch_function_t )(void *block);
133
+ typedef void (*dispatch_apply_function_t )(void *, size_t );
133
134
typedef void * (*worker_t )(void *block);
134
135
typedef unsigned long dispatch_mach_reason;
135
136
typedef void *dispatch_mach_msg_t ;
@@ -149,7 +150,11 @@ typedef void (^dispatch_mach_handler_t)(dispatch_mach_reason reason,
149
150
// A wrapper for the ObjC blocks used to support libdispatch.
150
151
typedef struct {
151
152
void *block;
152
- dispatch_function_t func;
153
+ union {
154
+ dispatch_function_t dispatch_func;
155
+ dispatch_apply_function_t dispatch_apply_func;
156
+ static_assert (sizeof (dispatch_func) == sizeof (dispatch_apply_func));
157
+ };
153
158
u32 parent_tid;
154
159
} asan_block_context_t ;
155
160
@@ -177,7 +182,7 @@ void asan_dispatch_call_block_and_release(void *block) {
177
182
block, (void *)pthread_self ());
178
183
asan_register_worker_thread (context->parent_tid , &stack);
179
184
// Call the original dispatcher for the block.
180
- context->func (context->block );
185
+ context->dispatch_func (context->block );
181
186
asan_free (context, &stack);
182
187
}
183
188
@@ -193,7 +198,7 @@ asan_block_context_t *alloc_asan_context(void *ctxt, dispatch_function_t func,
193
198
asan_block_context_t *asan_ctxt =
194
199
(asan_block_context_t *) asan_malloc (sizeof (asan_block_context_t ), stack);
195
200
asan_ctxt->block = ctxt;
196
- asan_ctxt->func = func;
201
+ asan_ctxt->dispatch_func = func;
197
202
asan_ctxt->parent_tid = GetCurrentTidOrInvalid ();
198
203
return asan_ctxt;
199
204
}
@@ -249,14 +254,17 @@ extern "C" void asan_dispatch_apply_f_work(void *context, size_t iteration) {
249
254
GET_STACK_TRACE_THREAD;
250
255
asan_block_context_t *asan_ctxt = (asan_block_context_t *)context;
251
256
asan_register_worker_thread (asan_ctxt->parent_tid , &stack);
252
- (( void (*)( void *, size_t )) asan_ctxt->func ) (asan_ctxt->block , iteration);
257
+ asan_ctxt->dispatch_apply_func (asan_ctxt->block , iteration);
253
258
}
254
259
255
260
INTERCEPTOR (void , dispatch_apply_f, size_t iterations, dispatch_queue_t queue,
256
- void *ctxt, void (* work)( void *, size_t ) ) {
261
+ void *ctxt, dispatch_apply_function_t work) {
257
262
GET_STACK_TRACE_THREAD;
258
263
asan_block_context_t *asan_ctxt =
259
- alloc_asan_context (ctxt, (dispatch_function_t )work, &stack);
264
+ (asan_block_context_t *)asan_malloc (sizeof (asan_block_context_t ), &stack);
265
+ asan_ctxt->block = ctxt;
266
+ asan_ctxt->dispatch_apply_func = work;
267
+ asan_ctxt->parent_tid = GetCurrentTidOrInvalid ();
260
268
REAL (dispatch_apply_f)(iterations, queue, (void *)asan_ctxt,
261
269
asan_dispatch_apply_f_work);
262
270
}
0 commit comments