2014-08-26 18:21:37 +08:00
|
|
|
//===-- asan_win_dll_thunk.cc ---------------------------------------------===//
|
2013-08-13 21:47:03 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// This file defines a family of thunks that should be statically linked into
|
|
|
|
// the DLLs that have ASan instrumentation in order to delegate the calls to the
|
|
|
|
// shared runtime that lives in the main binary.
|
2015-12-05 01:37:40 +08:00
|
|
|
// See https://github.com/google/sanitizers/issues/209 for the details.
|
2013-08-13 21:47:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
#ifdef SANITIZER_DLL_THUNK
|
2014-07-10 18:33:48 +08:00
|
|
|
#include "asan_init_version.h"
|
2014-11-18 18:33:15 +08:00
|
|
|
#include "interception/interception.h"
|
2017-01-21 05:09:36 +08:00
|
|
|
#include "sanitizer_common/sanitizer_win_defs.h"
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
#include "sanitizer_common/sanitizer_win_dll_thunk.h"
|
|
|
|
#include "sanitizer_common/sanitizer_platform_interceptors.h"
|
2013-08-13 21:47:03 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
// ASan own interface functions.
|
|
|
|
#define INTERFACE_FUNCTION(Name) INTERCEPT_SANITIZER_FUNCTION(Name)
|
2017-02-03 07:01:34 +08:00
|
|
|
#define INTERFACE_WEAK_FUNCTION(Name) INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
#include "asan_interface.inc"
|
2013-08-13 21:47:03 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
// Memory allocation functions.
|
|
|
|
INTERCEPT_WRAP_V_W(free)
|
|
|
|
INTERCEPT_WRAP_V_W(_free_base)
|
|
|
|
INTERCEPT_WRAP_V_WW(_free_dbg)
|
2013-08-13 23:29:42 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
INTERCEPT_WRAP_W_W(malloc)
|
|
|
|
INTERCEPT_WRAP_W_W(_malloc_base)
|
|
|
|
INTERCEPT_WRAP_W_WWWW(_malloc_dbg)
|
2013-08-13 23:29:42 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
INTERCEPT_WRAP_W_WW(calloc)
|
|
|
|
INTERCEPT_WRAP_W_WW(_calloc_base)
|
|
|
|
INTERCEPT_WRAP_W_WWWWW(_calloc_dbg)
|
|
|
|
INTERCEPT_WRAP_W_WWW(_calloc_impl)
|
2013-08-13 23:29:42 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
INTERCEPT_WRAP_W_WW(realloc)
|
|
|
|
INTERCEPT_WRAP_W_WW(_realloc_base)
|
|
|
|
INTERCEPT_WRAP_W_WWW(_realloc_dbg)
|
|
|
|
INTERCEPT_WRAP_W_WWW(_recalloc)
|
|
|
|
INTERCEPT_WRAP_W_WWW(_recalloc_base)
|
2013-08-13 23:29:42 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
INTERCEPT_WRAP_W_W(_msize)
|
|
|
|
INTERCEPT_WRAP_W_W(_expand)
|
|
|
|
INTERCEPT_WRAP_W_W(_expand_dbg)
|
2014-03-27 22:01:11 +08:00
|
|
|
|
|
|
|
// TODO(timurrrr): Might want to add support for _aligned_* allocation
|
|
|
|
// functions to detect a bit more bugs. Those functions seem to wrap malloc().
|
2013-08-13 23:29:42 +08:00
|
|
|
|
|
|
|
// TODO(timurrrr): Do we need to add _Crt* stuff here? (see asan_malloc_win.cc).
|
2013-08-13 21:47:03 +08:00
|
|
|
|
2014-05-22 21:57:22 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(atoi);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(atol);
|
2014-05-22 22:49:56 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(frexp);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(longjmp);
|
2016-07-15 06:29:22 +08:00
|
|
|
#if SANITIZER_INTERCEPT_MEMCHR
|
2014-05-22 21:57:22 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(memchr);
|
2016-07-15 06:29:22 +08:00
|
|
|
#endif
|
2014-05-22 21:57:22 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(memcmp);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(memcpy);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(memmove);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(memset);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strcat); // NOLINT
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strchr);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strcmp);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strcpy); // NOLINT
|
2015-05-28 18:21:59 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strcspn);
|
2016-03-22 08:52:47 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strdup);
|
2014-05-22 21:57:22 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strlen);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strncat);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strncmp);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strncpy);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strnlen);
|
2015-05-28 18:21:59 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strpbrk);
|
2016-03-22 06:42:15 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strrchr);
|
2015-05-28 18:21:59 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strspn);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strstr);
|
2014-05-22 21:57:22 +08:00
|
|
|
INTERCEPT_LIBRARY_FUNCTION(strtol);
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(wcslen);
|
2014-05-22 20:03:40 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
#ifdef _WIN64
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(__C_specific_handler);
|
|
|
|
#else
|
|
|
|
INTERCEPT_LIBRARY_FUNCTION(_except_handler3);
|
|
|
|
// _except_handler4 checks -GS cookie which is different for each module, so we
|
|
|
|
// can't use INTERCEPT_LIBRARY_FUNCTION(_except_handler4).
|
|
|
|
INTERCEPTOR(int, _except_handler4, void *a, void *b, void *c, void *d) {
|
|
|
|
__asan_handle_no_return();
|
|
|
|
return REAL(_except_handler4)(a, b, c, d);
|
2014-05-20 22:26:19 +08:00
|
|
|
}
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
#endif
|
2014-05-20 22:26:19 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
// Window specific functions not included in asan_interface.inc.
|
|
|
|
INTERCEPT_WRAP_W_V(__asan_should_detect_stack_use_after_return)
|
|
|
|
INTERCEPT_WRAP_W_V(__asan_get_shadow_memory_dynamic_address)
|
2014-06-02 22:40:07 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
using namespace __sanitizer;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
int __asan_option_detect_stack_use_after_return;
|
|
|
|
uptr __asan_shadow_memory_dynamic_address;
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
static int asan_dll_thunk_init() {
|
|
|
|
typedef void (*fntype)();
|
|
|
|
static fntype fn = 0;
|
|
|
|
// asan_dll_thunk_init is expected to be called by only one thread.
|
|
|
|
if (fn) return 0;
|
|
|
|
|
|
|
|
// Ensure all interception was executed.
|
|
|
|
__dll_thunk_init();
|
|
|
|
|
|
|
|
fn = (fntype) dllThunkGetRealAddrOrDie("__asan_init");
|
|
|
|
fn();
|
|
|
|
__asan_option_detect_stack_use_after_return =
|
|
|
|
(__asan_should_detect_stack_use_after_return() != 0);
|
|
|
|
__asan_shadow_memory_dynamic_address =
|
|
|
|
(uptr)__asan_get_shadow_memory_dynamic_address();
|
|
|
|
|
|
|
|
#ifndef _WIN64
|
|
|
|
INTERCEPT_FUNCTION(_except_handler4);
|
|
|
|
#endif
|
|
|
|
// In DLLs, the callbacks are expected to return 0,
|
|
|
|
// otherwise CRT initialization fails.
|
2014-06-02 22:40:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
|
2014-06-02 22:40:07 +08:00
|
|
|
#pragma section(".CRT$XIB", long, read) // NOLINT
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
__declspec(allocate(".CRT$XIB")) int (*__asan_preinit)() = asan_dll_thunk_init;
|
2014-06-02 22:40:07 +08:00
|
|
|
|
2016-11-16 05:54:58 +08:00
|
|
|
static void WINAPI asan_thread_init(void *mod, unsigned long reason,
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
void *reserved) {
|
|
|
|
if (reason == /*DLL_PROCESS_ATTACH=*/1) asan_dll_thunk_init();
|
2016-11-09 04:45:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma section(".CRT$XLAB", long, read) // NOLINT
|
2016-11-16 05:54:58 +08:00
|
|
|
__declspec(allocate(".CRT$XLAB")) void (WINAPI *__asan_tls_init)(void *,
|
2016-11-09 16:36:45 +08:00
|
|
|
unsigned long, void *) = asan_thread_init;
|
2016-11-09 04:45:45 +08:00
|
|
|
|
2017-01-21 05:09:36 +08:00
|
|
|
WIN_FORCE_LINK(__asan_dso_reg_hook)
|
2016-11-18 03:02:53 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
#endif // SANITIZER_DLL_THUNK
|