2019-08-14 10:47:11 +02:00
|
|
|
//===-- asan_mac.cpp ------------------------------------------------------===//
|
2012-11-12 16:53:47 +01:00
|
|
|
//
|
2019-08-14 10:47:11 +02:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-11-12 16:53:47 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Mac-specific details.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
|
|
|
#if SANITIZER_MAC
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
#include "asan_interceptors.h"
|
|
|
|
#include "asan_internal.h"
|
|
|
|
#include "asan_mapping.h"
|
|
|
|
#include "asan_stack.h"
|
|
|
|
#include "asan_thread.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_common/sanitizer_atomic.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2014-05-22 09:09:21 +02:00
|
|
|
#include "sanitizer_common/sanitizer_mac.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#include <dlfcn.h>
|
2015-11-23 10:07:18 +01:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <libkern/OSAtomic.h>
|
2012-11-12 16:53:47 +01:00
|
|
|
#include <mach-o/dyld.h>
|
2016-11-08 23:04:09 +01:00
|
|
|
#include <mach-o/getsect.h>
|
2012-11-12 16:53:47 +01:00
|
|
|
#include <mach-o/loader.h>
|
2015-11-23 10:07:18 +01:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h> // for free()
|
2012-11-12 16:53:47 +01:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/ucontext.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
// from <crt_externs.h>, but we don't have that file on iOS
|
|
|
|
extern "C" {
|
|
|
|
extern char ***_NSGetArgv(void);
|
|
|
|
extern char ***_NSGetEnviron(void);
|
|
|
|
}
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
namespace __asan {
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
void InitializePlatformInterceptors() {}
|
2016-11-08 23:04:09 +01:00
|
|
|
void InitializePlatformExceptionHandlers() {}
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
bool IsSystemHeapAddress (uptr addr) { return false; }
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// No-op. Mac does not support static linkage anyway.
|
|
|
|
void *AsanDoesNotSupportStaticLinkage() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
uptr FindDynamicShadowStart() {
|
2020-10-16 10:03:04 +02:00
|
|
|
return MapDynamicShadow(MemToShadowSize(kHighMemEnd), SHADOW_SCALE,
|
|
|
|
/*min_shadow_base_alignment*/ 0, kHighMemEnd);
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
}
|
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
// No-op. Mac does not support static linkage anyway.
|
|
|
|
void AsanCheckDynamicRTPrereqs() {}
|
|
|
|
|
|
|
|
// No-op. Mac does not support static linkage anyway.
|
|
|
|
void AsanCheckIncompatibleRT() {}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {
|
|
|
|
// Find the Mach-O header for the image containing the needle
|
|
|
|
Dl_info info;
|
|
|
|
int err = dladdr(needle, &info);
|
|
|
|
if (err == 0) return;
|
|
|
|
|
|
|
|
#if __LP64__
|
|
|
|
const struct mach_header_64 *mh = (struct mach_header_64 *)info.dli_fbase;
|
|
|
|
#else
|
|
|
|
const struct mach_header *mh = (struct mach_header *)info.dli_fbase;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Look up the __asan_globals section in that image and register its globals
|
|
|
|
unsigned long size = 0;
|
|
|
|
__asan_global *globals = (__asan_global *)getsectiondata(
|
|
|
|
mh,
|
|
|
|
"__DATA", "__asan_globals",
|
|
|
|
&size);
|
|
|
|
|
|
|
|
if (!globals) return;
|
|
|
|
if (size % sizeof(__asan_global) != 0) return;
|
|
|
|
op(globals, size / sizeof(__asan_global));
|
|
|
|
}
|
|
|
|
|
2020-10-16 10:03:04 +02:00
|
|
|
void FlushUnneededASanShadowMemory(uptr p, uptr size) {
|
|
|
|
// Since asan's mapping is compacting, the shadow chunk may be
|
|
|
|
// not page-aligned, so we only flush the page-aligned portion.
|
|
|
|
ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
|
|
|
|
}
|
|
|
|
|
2013-01-23 12:41:33 +01:00
|
|
|
void ReadContextStack(void *context, uptr *stack, uptr *ssize) {
|
2012-11-23 15:46:25 +01:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
// Support for the following functions from libdispatch on Mac OS:
|
|
|
|
// dispatch_async_f()
|
|
|
|
// dispatch_async()
|
|
|
|
// dispatch_sync_f()
|
|
|
|
// dispatch_sync()
|
|
|
|
// dispatch_after_f()
|
|
|
|
// dispatch_after()
|
|
|
|
// dispatch_group_async_f()
|
|
|
|
// dispatch_group_async()
|
|
|
|
// TODO(glider): libdispatch API contains other functions that we don't support
|
|
|
|
// yet.
|
|
|
|
//
|
|
|
|
// dispatch_sync() and dispatch_sync_f() are synchronous, although chances are
|
|
|
|
// they can cause jobs to run on a thread different from the current one.
|
|
|
|
// TODO(glider): if so, we need a test for this (otherwise we should remove
|
|
|
|
// them).
|
|
|
|
//
|
|
|
|
// The following functions use dispatch_barrier_async_f() (which isn't a library
|
|
|
|
// function but is exported) and are thus supported:
|
|
|
|
// dispatch_source_set_cancel_handler_f()
|
|
|
|
// dispatch_source_set_cancel_handler()
|
|
|
|
// dispatch_source_set_event_handler_f()
|
|
|
|
// dispatch_source_set_event_handler()
|
|
|
|
//
|
|
|
|
// The reference manual for Grand Central Dispatch is available at
|
|
|
|
// http://developer.apple.com/library/mac/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html
|
|
|
|
// The implementation details are at
|
|
|
|
// http://libdispatch.macosforge.org/trac/browser/trunk/src/queue.c
|
|
|
|
|
|
|
|
typedef void* dispatch_group_t;
|
|
|
|
typedef void* dispatch_queue_t;
|
|
|
|
typedef void* dispatch_source_t;
|
|
|
|
typedef u64 dispatch_time_t;
|
|
|
|
typedef void (*dispatch_function_t)(void *block);
|
|
|
|
typedef void* (*worker_t)(void *block);
|
|
|
|
|
|
|
|
// A wrapper for the ObjC blocks used to support libdispatch.
|
|
|
|
typedef struct {
|
|
|
|
void *block;
|
|
|
|
dispatch_function_t func;
|
|
|
|
u32 parent_tid;
|
|
|
|
} asan_block_context_t;
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
ALWAYS_INLINE
|
2012-11-12 16:53:47 +01:00
|
|
|
void asan_register_worker_thread(int parent_tid, StackTrace *stack) {
|
2013-11-04 22:33:31 +01:00
|
|
|
AsanThread *t = GetCurrentThread();
|
2012-11-12 16:53:47 +01:00
|
|
|
if (!t) {
|
2015-10-21 09:32:45 +02:00
|
|
|
t = AsanThread::Create(/* start_routine */ nullptr, /* arg */ nullptr,
|
|
|
|
parent_tid, stack, /* detached */ true);
|
2012-11-12 16:53:47 +01:00
|
|
|
t->Init();
|
2019-08-14 10:47:11 +02:00
|
|
|
asanThreadRegistry().StartThread(t->tid(), GetTid(), ThreadType::Worker,
|
|
|
|
nullptr);
|
2013-11-04 22:33:31 +01:00
|
|
|
SetCurrentThread(t);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For use by only those functions that allocated the context via
|
|
|
|
// alloc_asan_context().
|
|
|
|
extern "C"
|
|
|
|
void asan_dispatch_call_block_and_release(void *block) {
|
2013-01-10 13:44:08 +01:00
|
|
|
GET_STACK_TRACE_THREAD;
|
2012-11-12 16:53:47 +01:00
|
|
|
asan_block_context_t *context = (asan_block_context_t*)block;
|
2014-05-22 09:09:21 +02:00
|
|
|
VReport(2,
|
|
|
|
"asan_dispatch_call_block_and_release(): "
|
|
|
|
"context: %p, pthread_self: %p\n",
|
|
|
|
block, pthread_self());
|
2012-11-12 16:53:47 +01:00
|
|
|
asan_register_worker_thread(context->parent_tid, &stack);
|
|
|
|
// Call the original dispatcher for the block.
|
|
|
|
context->func(context->block);
|
2013-01-10 13:44:08 +01:00
|
|
|
asan_free(context, &stack, FROM_MALLOC);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __asan
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
using namespace __asan;
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// Wrap |ctxt| and |func| into an asan_block_context_t.
|
|
|
|
// The caller retains control of the allocated context.
|
|
|
|
extern "C"
|
|
|
|
asan_block_context_t *alloc_asan_context(void *ctxt, dispatch_function_t func,
|
2014-11-13 21:41:38 +01:00
|
|
|
BufferedStackTrace *stack) {
|
2012-11-12 16:53:47 +01:00
|
|
|
asan_block_context_t *asan_ctxt =
|
|
|
|
(asan_block_context_t*) asan_malloc(sizeof(asan_block_context_t), stack);
|
|
|
|
asan_ctxt->block = ctxt;
|
|
|
|
asan_ctxt->func = func;
|
2013-11-04 22:33:31 +01:00
|
|
|
asan_ctxt->parent_tid = GetCurrentTidOrInvalid();
|
2012-11-12 16:53:47 +01:00
|
|
|
return asan_ctxt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define interceptor for dispatch_*_f function with the three most common
|
|
|
|
// parameters: dispatch_queue_t, context, dispatch_function_t.
|
|
|
|
#define INTERCEPT_DISPATCH_X_F_3(dispatch_x_f) \
|
|
|
|
INTERCEPTOR(void, dispatch_x_f, dispatch_queue_t dq, void *ctxt, \
|
|
|
|
dispatch_function_t func) { \
|
2013-01-10 13:44:08 +01:00
|
|
|
GET_STACK_TRACE_THREAD; \
|
2012-11-12 16:53:47 +01:00
|
|
|
asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); \
|
2015-10-21 09:32:45 +02:00
|
|
|
if (Verbosity() >= 2) { \
|
2012-11-12 16:53:47 +01:00
|
|
|
Report(#dispatch_x_f "(): context: %p, pthread_self: %p\n", \
|
|
|
|
asan_ctxt, pthread_self()); \
|
2014-05-22 09:09:21 +02:00
|
|
|
PRINT_CURRENT_STACK(); \
|
|
|
|
} \
|
|
|
|
return REAL(dispatch_x_f)(dq, (void*)asan_ctxt, \
|
|
|
|
asan_dispatch_call_block_and_release); \
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPT_DISPATCH_X_F_3(dispatch_async_f)
|
|
|
|
INTERCEPT_DISPATCH_X_F_3(dispatch_sync_f)
|
|
|
|
INTERCEPT_DISPATCH_X_F_3(dispatch_barrier_async_f)
|
|
|
|
|
|
|
|
INTERCEPTOR(void, dispatch_after_f, dispatch_time_t when,
|
|
|
|
dispatch_queue_t dq, void *ctxt,
|
|
|
|
dispatch_function_t func) {
|
2013-01-10 13:44:08 +01:00
|
|
|
GET_STACK_TRACE_THREAD;
|
2012-11-12 16:53:47 +01:00
|
|
|
asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack);
|
2015-10-21 09:32:45 +02:00
|
|
|
if (Verbosity() >= 2) {
|
2012-11-12 16:53:47 +01:00
|
|
|
Report("dispatch_after_f: %p\n", asan_ctxt);
|
|
|
|
PRINT_CURRENT_STACK();
|
|
|
|
}
|
|
|
|
return REAL(dispatch_after_f)(when, dq, (void*)asan_ctxt,
|
|
|
|
asan_dispatch_call_block_and_release);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(void, dispatch_group_async_f, dispatch_group_t group,
|
|
|
|
dispatch_queue_t dq, void *ctxt,
|
|
|
|
dispatch_function_t func) {
|
2013-01-10 13:44:08 +01:00
|
|
|
GET_STACK_TRACE_THREAD;
|
2012-11-12 16:53:47 +01:00
|
|
|
asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack);
|
2015-10-21 09:32:45 +02:00
|
|
|
if (Verbosity() >= 2) {
|
2012-11-12 16:53:47 +01:00
|
|
|
Report("dispatch_group_async_f(): context: %p, pthread_self: %p\n",
|
|
|
|
asan_ctxt, pthread_self());
|
|
|
|
PRINT_CURRENT_STACK();
|
|
|
|
}
|
|
|
|
REAL(dispatch_group_async_f)(group, dq, (void*)asan_ctxt,
|
|
|
|
asan_dispatch_call_block_and_release);
|
|
|
|
}
|
|
|
|
|
2013-02-13 11:46:01 +01:00
|
|
|
#if !defined(MISSING_BLOCKS_SUPPORT)
|
2012-11-12 16:53:47 +01:00
|
|
|
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_source_set_cancel_handler(dispatch_source_t ds,
|
|
|
|
void(^work)(void));
|
|
|
|
void dispatch_source_set_event_handler(dispatch_source_t ds, void(^work)(void));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_ASAN_BLOCK(work) \
|
|
|
|
void (^asan_block)(void); \
|
2013-11-04 22:33:31 +01:00
|
|
|
int parent_tid = GetCurrentTidOrInvalid(); \
|
2012-11-12 16:53:47 +01:00
|
|
|
asan_block = ^(void) { \
|
2013-01-10 13:44:08 +01:00
|
|
|
GET_STACK_TRACE_THREAD; \
|
2012-11-12 16:53:47 +01:00
|
|
|
asan_register_worker_thread(parent_tid, &stack); \
|
|
|
|
work(); \
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(void, dispatch_async,
|
|
|
|
dispatch_queue_t dq, void(^work)(void)) {
|
2014-09-23 19:59:53 +02:00
|
|
|
ENABLE_FRAME_POINTER;
|
2012-11-12 16:53:47 +01:00
|
|
|
GET_ASAN_BLOCK(work);
|
|
|
|
REAL(dispatch_async)(dq, asan_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(void, dispatch_group_async,
|
|
|
|
dispatch_group_t dg, dispatch_queue_t dq, void(^work)(void)) {
|
2014-09-23 19:59:53 +02:00
|
|
|
ENABLE_FRAME_POINTER;
|
2012-11-12 16:53:47 +01:00
|
|
|
GET_ASAN_BLOCK(work);
|
|
|
|
REAL(dispatch_group_async)(dg, dq, asan_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(void, dispatch_after,
|
|
|
|
dispatch_time_t when, dispatch_queue_t queue, void(^work)(void)) {
|
2014-09-23 19:59:53 +02:00
|
|
|
ENABLE_FRAME_POINTER;
|
2012-11-12 16:53:47 +01:00
|
|
|
GET_ASAN_BLOCK(work);
|
|
|
|
REAL(dispatch_after)(when, queue, asan_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(void, dispatch_source_set_cancel_handler,
|
|
|
|
dispatch_source_t ds, void(^work)(void)) {
|
2015-10-21 09:32:45 +02:00
|
|
|
if (!work) {
|
|
|
|
REAL(dispatch_source_set_cancel_handler)(ds, work);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-23 19:59:53 +02:00
|
|
|
ENABLE_FRAME_POINTER;
|
2012-11-12 16:53:47 +01:00
|
|
|
GET_ASAN_BLOCK(work);
|
|
|
|
REAL(dispatch_source_set_cancel_handler)(ds, asan_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(void, dispatch_source_set_event_handler,
|
|
|
|
dispatch_source_t ds, void(^work)(void)) {
|
2014-09-23 19:59:53 +02:00
|
|
|
ENABLE_FRAME_POINTER;
|
2012-11-12 16:53:47 +01:00
|
|
|
GET_ASAN_BLOCK(work);
|
|
|
|
REAL(dispatch_source_set_event_handler)(ds, asan_block);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
#endif // SANITIZER_MAC
|