Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 6 additions & 48 deletions compiler-rt/lib/asan/asan_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ void FlushUnneededASanShadowMemory(uptr p, uptr size) {
// dispatch_after()
// dispatch_group_async_f()
// dispatch_group_async()
// dispatch_apply()
// dispatch_apply_f()
// TODO(glider): libdispatch API contains other functions that we don't support
// yet.
//
Expand All @@ -130,7 +128,6 @@ typedef void* dispatch_queue_t;
typedef void* dispatch_source_t;
typedef u64 dispatch_time_t;
typedef void (*dispatch_function_t)(void *block);
typedef void (*dispatch_apply_function_t)(void *, size_t);
typedef void* (*worker_t)(void *block);
typedef unsigned long dispatch_mach_reason;
typedef void *dispatch_mach_msg_t;
Expand All @@ -150,11 +147,7 @@ typedef void (^dispatch_mach_handler_t)(dispatch_mach_reason reason,
// A wrapper for the ObjC blocks used to support libdispatch.
typedef struct {
void *block;
union {
dispatch_function_t dispatch_func;
dispatch_apply_function_t dispatch_apply_func;
static_assert(sizeof(dispatch_func) == sizeof(dispatch_apply_func));
};
dispatch_function_t func;
u32 parent_tid;
} asan_block_context_t;

Expand Down Expand Up @@ -182,8 +175,8 @@ void asan_dispatch_call_block_and_release(void *block) {
block, (void*)pthread_self());
asan_register_worker_thread(context->parent_tid, &stack);
// Call the original dispatcher for the block.
context->dispatch_func(context->block);
asan_free(context, &stack);
context->func(context->block);
asan_free(context, &stack, FROM_MALLOC);
}

} // namespace __asan
Expand All @@ -198,7 +191,7 @@ asan_block_context_t *alloc_asan_context(void *ctxt, dispatch_function_t func,
asan_block_context_t *asan_ctxt =
(asan_block_context_t*) asan_malloc(sizeof(asan_block_context_t), stack);
asan_ctxt->block = ctxt;
asan_ctxt->dispatch_func = func;
asan_ctxt->func = func;
asan_ctxt->parent_tid = GetCurrentTidOrInvalid();
return asan_ctxt;
}
Expand Down Expand Up @@ -250,34 +243,13 @@ INTERCEPTOR(void, dispatch_group_async_f, dispatch_group_t group,
asan_dispatch_call_block_and_release);
}

extern "C" void asan_dispatch_apply_f_work(void *context, size_t iteration) {
GET_STACK_TRACE_THREAD;
asan_block_context_t *asan_ctxt = (asan_block_context_t *)context;
asan_register_worker_thread(asan_ctxt->parent_tid, &stack);
asan_ctxt->dispatch_apply_func(asan_ctxt->block, iteration);
}

INTERCEPTOR(void, dispatch_apply_f, size_t iterations, dispatch_queue_t queue,
void *ctxt, dispatch_apply_function_t work) {
GET_STACK_TRACE_THREAD;
asan_block_context_t *asan_ctxt =
(asan_block_context_t *)asan_malloc(sizeof(asan_block_context_t), &stack);
asan_ctxt->block = ctxt;
asan_ctxt->dispatch_apply_func = work;
asan_ctxt->parent_tid = GetCurrentTidOrInvalid();
REAL(dispatch_apply_f)(iterations, queue, (void *)asan_ctxt,
asan_dispatch_apply_f_work);
}

# if !defined(MISSING_BLOCKS_SUPPORT)
#if !defined(MISSING_BLOCKS_SUPPORT)
extern "C" {
void dispatch_async(dispatch_queue_t dq, void(^work)(void));
void dispatch_group_async(dispatch_group_t dg, dispatch_queue_t dq,
void(^work)(void));
void dispatch_after(dispatch_time_t when, dispatch_queue_t queue,
void(^work)(void));
void dispatch_apply(size_t iterations, dispatch_queue_t queue,
void (^block)(size_t iteration));
void dispatch_source_set_cancel_handler(dispatch_source_t ds,
void(^work)(void));
void dispatch_source_set_event_handler(dispatch_source_t ds, void(^work)(void));
Expand Down Expand Up @@ -360,20 +332,6 @@ INTERCEPTOR(void *, dispatch_mach_create_f, const char *label,
});
}

INTERCEPTOR(void, dispatch_apply, size_t iterations, dispatch_queue_t queue,
void (^block)(size_t iteration)) {
ENABLE_FRAME_POINTER;
int parent_tid = GetCurrentTidOrInvalid();

void (^asan_block)(size_t) = ^(size_t iteration) {
GET_STACK_TRACE_THREAD;
asan_register_worker_thread(parent_tid, &stack);
block(iteration);
};

REAL(dispatch_apply)(iterations, queue, asan_block);
}

# endif
#endif

#endif // SANITIZER_APPLE
6 changes: 0 additions & 6 deletions compiler-rt/lib/asan/tests/asan_mac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ TEST(AddressSanitizerMac, GCDDispatchAfter) {
EXPECT_DEATH(TestGCDDispatchAfter(), "Shadow byte legend");
}

TEST(AddressSanitizerMac, GCDDispatchApply) {
// Make sure the whole ASan report is printed, i.e. that we don't die
// on a CHECK.
EXPECT_DEATH(TestGCDDispatchApply(), "Shadow byte legend");
}

TEST(AddressSanitizerMac, GCDSourceEvent) {
// Make sure the whole ASan report is printed, i.e. that we don't die
// on a CHECK.
Expand Down
1 change: 0 additions & 1 deletion compiler-rt/lib/asan/tests/asan_mac_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern "C" {
void TestGCDReuseWqthreadsAsync();
void TestGCDReuseWqthreadsSync();
void TestGCDDispatchAfter();
void TestGCDDispatchApply();
void TestGCDInTSDDestructor();
void TestGCDSourceEvent();
void TestGCDSourceCancel();
Expand Down
10 changes: 0 additions & 10 deletions compiler-rt/lib/asan/tests/asan_mac_test_helpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,6 @@ void TestGCDDispatchAfter() {
wait_forever();
}

void TestGCDDispatchApply() {
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
__block char *buffer = (char *)malloc(4);
dispatch_apply(8, queue, ^(size_t i) {
access_memory(&buffer[i]);
});

free(buffer); // not reached
}

void worker_do_deallocate(void *ptr) {
free(ptr);
}
Expand Down
54 changes: 0 additions & 54 deletions compiler-rt/test/asan/TestCases/Darwin/dispatch_apply_threadno.c

This file was deleted.