Commit Graph

37 Commits

Author SHA1 Message Date
Alexander Potapenko cae42d23a6 [ASan] Use dylib interposition to hook memory allocation in the dynamic runtime.
This CL drastically simplifies the way we're hooking the memory allocation routines in ASan on Mac by using dylib interposition to replace the main malloc_zone_* functions. This allows us to avoid replacing the default CFAllocator and drop the CF dependency at all.

Committing this patch will result in the static runtime being broken. A follow-up CL will switch ASan to use the dynamic runtime library.

llvm-svn: 173134
2013-01-22 09:14:54 +00:00
Kostya Serebryany 3674c6b13b [asan] add a flag alloc_dealloc_mismatch (off by default for now) which finds malloc/delete, new/free, new/delete[], etc mismatches
llvm-svn: 170869
2012-12-21 08:53:59 +00:00
Kostya Serebryany 6852bce2f2 [asan] fix mac build
llvm-svn: 170118
2012-12-13 10:01:20 +00:00
Kostya Serebryany baf583c443 [asan] add two asan flags: fast_unwind_on_fatal and fast_unwind_on_malloc to allow using the slow CFI-based unwinder
llvm-svn: 170117
2012-12-13 09:34:23 +00:00
Kostya Serebryany f22c697f58 [asan] get rid of some of the uses of kPageSize. The intent is to get rid of it completely to support platforms with multiple possible page sizes.
llvm-svn: 168517
2012-11-23 15:38:49 +00:00
Alexander Potapenko 1eef2b813c [ASan] Rename ReplaceCFAllocator to MaybeReplaceCFAllocator.
Replace the allocator only if the replace_cfallocator flag is set (in some cases it wasn't checked)

llvm-svn: 166550
2012-10-24 09:35:23 +00:00
Alexey Samsonov 83ecabe6e6 [Sanitizer] Remove unneeded returns after UNIMPLEMENTED macro
llvm-svn: 165493
2012-10-09 08:51:08 +00:00
Alexander Potapenko f3a96894a6 Give more accurate malloc statistics to malloc_zone_statistics().
Fix a warning in macros instantiation.

llvm-svn: 163716
2012-09-12 15:29:50 +00:00
Alexey Samsonov 4787d0fbef [ASan] more macro/casting magic to suppress warnings
llvm-svn: 163706
2012-09-12 14:10:14 +00:00
Alexander Potapenko 814451909a Initial support for malloc_zone_statistics. All counters are set to zero now.
This is required to overcome a crash in mstats() (http://code.google.com/p/address-sanitizer/issues/detail?id=109)

llvm-svn: 163690
2012-09-12 09:38:51 +00:00
Alexander Potapenko 5a9b616d6b For invalid pointers passed to free_common check whether they are actually skewed to hold an additional CFAllocatorRef.
If so, fix the pointer and pass it to asan_free.

See http://code.google.com/p/address-sanitizer/issues/detail?id=70 for more background.

llvm-svn: 162839
2012-08-29 12:36:24 +00:00
Kostya Serebryany bb6f165952 [asan] get rid of AsanPrintf in favor of Printf from sanitizer_common
llvm-svn: 162746
2012-08-28 11:34:40 +00:00
Alexander Potapenko c62210e3ff Commit the source and CMake changes that will allow to build ASan runtime
as a shared library on Mac OS. This will provide an alternative to
mach_override.

llvm-svn: 162091
2012-08-17 09:00:08 +00:00
Alexander Potapenko 33c028fa05 Remove the setjmp.h dependency, fix the comment.
llvm-svn: 161662
2012-08-10 12:46:39 +00:00
Alexander Potapenko 2cdd4f165e Temporary fix for http://code.google.com/p/address-sanitizer/issues/detail?id=99:
when trying to free memory that actually belongs to the system purgeable zone, use malloc_zone_free(malloc_default_purgeable_zone(), ptr) instead of asan_free().

llvm-svn: 161661
2012-08-10 11:33:01 +00:00
Alexey Samsonov f343eb7df4 [ASan] Move mac-specific error reports to asan_report.cc as well
llvm-svn: 161576
2012-08-09 12:15:40 +00:00
Alexander Potapenko 51e6488b31 Intercept CFAllocator for each thread in the program.
Test that child threads use the ASan allocator, that allocated memory can be passed to another thread and deallocated on it.
This should fix http://code.google.com/p/address-sanitizer/issues/detail?id=81

llvm-svn: 160630
2012-07-23 14:07:58 +00:00
Alexey Samsonov 34efb8e9b9 [ASan] Use common flags parsing machinery.
llvm-svn: 159933
2012-07-09 14:36:04 +00:00
Alexander Potapenko 740d166c3e Small fix: do not replace the default CFAllocator if it has been replaced already.
llvm-svn: 159824
2012-07-06 13:52:28 +00:00
Alexander Potapenko dc211a8db4 Because CFAllocatorCreate() should also be called after __CFInitialize() on Lion,
do so by factoring the CFAllocator logic into ReplaceCFAllocator(), which is called from
either the __CFInitialize wrapper or __asan_init(), depending on which of them is called later.

llvm-svn: 159822
2012-07-06 13:24:28 +00:00
Alexander Potapenko 89f9270366 A portable way to check whether __CFInitialize has been called: compare kCFAllocatorSystemDefault._base._cfisa to 0.
This should fix http://code.google.com/p/address-sanitizer/issues/detail?id=87 on both Lion and Snow Leopard.

llvm-svn: 159821
2012-07-06 13:04:12 +00:00
Alexander Potapenko d2ff0b087a Do not check for __CFRuntimeClassTableSize on non-10.6 systems, where this symbol is private.
This change may cause http://code.google.com/p/address-sanitizer/issues/detail?id=87 to re-appear on Lion.

llvm-svn: 159819
2012-07-06 11:58:54 +00:00
Alexander Potapenko 25b567dd0d Fix http://code.google.com/p/address-sanitizer/issues/detail?id=87 by making sure we replace the default CFAllocator only after __CFInitialize has been called.
llvm-svn: 159749
2012-07-05 14:46:56 +00:00
Alexander Potapenko 77769caaef Do not call malloc_zone_from_ptr() for the pointers passed to mz_size() and mz_free().
These callbacks assume that the memory belongs to asan_zone, so it's incorrect to pass it to another one.
If a need for this appears (e.g. system libraries free the memory using wrong zone), it should be documented.

llvm-svn: 159713
2012-07-04 13:58:07 +00:00
Alexander Potapenko 1bde28b464 Factor the common code out of cf_free and mz_free.
Introduce the mac_ignore_invalid_free flag (0 by default) which makes both cf_free and mz_free ignore invalid free invocations and leak memory.

llvm-svn: 158885
2012-06-21 01:01:20 +00:00
Alexander Potapenko f9f2fbacb3 Actually intercept free() to ensure that the deallocations caused by other functions directly calling it are routed to our allocator.
For the allocations that do not belong to any malloc zone check whether they're padded with a pointer to ASan's CFAllocator. If so, free the original (unpadded) pointer.
This should fix AddressSanitizerMac.NSURLDeallocation and issue 70.

llvm-svn: 158863
2012-06-20 22:29:09 +00:00
Alexey Samsonov 51ae983718 [Sanitizer]: Introduce a common internal printf function. For now, also use tool-specific wrappers TsanPrintf (its output is controlled by TSan flags) and AsanPrintf (which copies its results to the ASan-private buffer). Supported formats: %[z]{d,u,x}, %s, %p. Re-write all format strings in TSan according to this format (this should have no effect on 64-bit platforms).
llvm-svn: 158065
2012-06-06 13:11:29 +00:00
Alexey Samsonov 485d3dc363 Remove file-type tags for .cc files in ASan run-time library
llvm-svn: 157927
2012-06-04 13:50:10 +00:00
Kostya Serebryany 8d03204204 [asan] more renaming
llvm-svn: 157746
2012-05-31 14:35:53 +00:00
Alexander Potapenko c6eb6a8287 Add internal_memset and replace the uses of REAL(memset) with it where the performance allows.
llvm-svn: 153641
2012-03-29 12:20:47 +00:00
Eli Friedman e781266905 Make sure to properly ifdef out an unused function on OSX < 10.6. PR12136. Patch from Jeremy Huddleston.
llvm-svn: 152085
2012-03-06 01:21:14 +00:00
Alexey Samsonov 8489f2a564 AddressSanitizer: start factoring out interception machinery
llvm-svn: 150083
2012-02-08 19:52:01 +00:00
Alexey Samsonov e725478e2f AddressSanitizer: replace all "real_X" calls with "REAL(X)"
llvm-svn: 150073
2012-02-08 13:45:31 +00:00
Alexey Samsonov 209c514a1d AddressSanitizer: add support for malloc_usable_size() function
llvm-svn: 148287
2012-01-17 06:39:10 +00:00
Daniel Dunbar fc4a4a3cbc asan: #if 0 out some unused functions (we build with -Werror).
llvm-svn: 145645
2011-12-01 23:35:47 +00:00
Kostya Serebryany 5dfa4da0b9 [asan] flatten the asan-rt build slightly
llvm-svn: 145631
2011-12-01 21:40:52 +00:00
Kostya Serebryany 019b76f5fd AddressSanitizer run-time library. Not yet integrated with the compiler-rt build system, but can be built using the old makefile. See details in README.txt
llvm-svn: 145463
2011-11-30 01:07:02 +00:00