[asan] Intercept all Heap* related imports from ucrtbase.dll
authorReid Kleckner <rnk@google.com>
Thu, 24 Mar 2016 20:19:48 +0000 (20:19 +0000)
committerReid Kleckner <rnk@google.com>
Thu, 24 Mar 2016 20:19:48 +0000 (20:19 +0000)
commit3b0290570b031a579b17e5cfad0e381576779489
treefcdb3bc4db093cf91c2d51ee0ed187eb2f9ac8a6
parentf4cc7525535a590624b4bdfdb0cef73b8dcd17a1
[asan] Intercept all Heap* related imports from ucrtbase.dll

ucrtbase.dll appears to be built with some kind of cross-module
inlining, because there are calls to imported Heap* routines sprinkled
throughout the code. This inlining defeats our attempts to hotpatch
malloc, _malloc_base, and related functions. Failing to intercept an
allocation or deallocation results in a crash when the program attempts
to deallocate or reallocate memory with the wrong allocator.

This change patches the IAT of ucrtbase.dll to replace the addresses of
the imported Heap* functions with implementations provided by ASan.  We
don't globally intercept the win32 Heap* functions because they are
typically used by system DLLs that run before ASan initializes.
Eventually, we may want to intercept them, but for now I think this is
the minimal change that will keep ASan stable.

Reviewers: samsonov

Differential Revision: http://reviews.llvm.org/D18413

llvm-svn: 264327
compiler-rt/lib/asan/asan_allocator.cc
compiler-rt/lib/asan/asan_allocator.h
compiler-rt/lib/asan/asan_malloc_win.cc
compiler-rt/lib/interception/interception_win.cc
compiler-rt/lib/interception/interception_win.h