Commit Graph

63 Commits

Author SHA1 Message Date
Dan Liew a35df433bf [ASan] On Darwin record global allocator pointer and size in introspection struct.
This implements `mi_extra_init(...)` for the ASan allocator on
Darwin and uses the `__lsan::GetAllocatorGlobalRange(...)` function
to retrieve the allocator pointer and size.

rdar://problem/45284065

llvm-svn: 351713
2019-01-21 01:41:12 +00:00
Dan Liew 5a3857c9b2 On Darwin add allocator address and size fields to
`sanitizer_malloc_introspection_t` and initialize them to zero.

We allow sanitizer implementations to perform different initialization
by defining `COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT` to be `1`
and providing an implementation of `mi_extra_init(...)`.

We use these changes in future patches to implement malloc zone enumeration.

rdar://problem/45284065

llvm-svn: 351712
2019-01-21 01:41:08 +00:00
Dan Liew 4dd0bf9487 On Darwin allow for sanitizer malloc implementations to provide a zone
enumerator.

This is done by defining `COMMON_MALLOC_HAS_ZONE_ENUMERATOR` to `1` and
then by providing an implementation of the `mi_enumerator(...)` function.
If a custom implementation isn't desired the macro is set to `0` which
causes a stub version (that fails) to be used.

Currently all Darwin sanitizers that have malloc implementations define
this to be `0` so there is no functionality change.

rdar://problem/45284065

llvm-svn: 351711
2019-01-21 01:41:01 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Dan Liew 8bffb63497 Introduce a way to allow the ASan dylib on Darwin platforms to be loaded via `dlopen()`.
Summary:

The purpose of this option is provide a way for the ASan dylib
to be loaded via `dlopen()` without triggering most initialization
steps (e.g. shadow memory set up) that normally occur when the
ASan dylib is loaded.

This new functionality is exposed by

- A `SANITIZER_SUPPORTS_INIT_FOR_DLOPEN` macro which indicates if the
  feature is supported. This only true for Darwin currently.
- A `HandleDlopenInit()` function which should return true if the library
  is being loaded via `dlopen()` and
  `SANITIZER_SUPPORTS_INIT_FOR_DLOPEN` is supported. Platforms that
  support this may perform any initialization they wish inside this
  function.

Although disabling initialization is something that could potentially
apply to other sanitizers it appears to be unnecessary for other
sanitizers so this patch only makes the change for ASan.

rdar://problem/45284065

Reviewers: kubamracek, george.karpenkov, kcc, eugenis, krytarowski

Subscribers: #sanitizers, llvm-commits

Differential Revision: https://reviews.llvm.org/D54469

llvm-svn: 348078
2018-12-01 15:45:42 +00:00
Alex Shlyapnikov 79a7c4fe73 [Sanitizers] Add more standard compliant posix_memalign implementation for LSan.
Summary:
Add more standard compliant posix_memalign implementation for LSan and
use corresponding sanitizer's posix_memalign implenetations in allocation
wrappers on Mac.

Reviewers: eugenis, fjricci

Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits

Differential Revision: https://reviews.llvm.org/D44335

llvm-svn: 327338
2018-03-12 21:59:06 +00:00
Alexander Potapenko 6f3fa20c76 [ASan] Retire mac_ignore_invalid_free, remove some dead code.
mac_ignore_invalid_free was helpful when ASan runtime used to intercept
CFAllocator and sometimes corrupted its memory. This behavior had been long
gone, and the flag was unused.
This patch also deletes ReportMacCfReallocUnknown(), which was used by the
CFAllocator realloc() wrapper.

llvm-svn: 254722
2015-12-04 16:17:55 +00:00
Kuba Brecka 465cb8a6fa [tsan] Use malloc zone interceptors on OS X, part 1 (refactoring)
TSan needs to use a custom malloc zone on OS X, which is already implemented in ASan.  This patch is a refactoring patch (NFC) that extracts this from ASan into sanitizer_common, where we can reuse it in TSan.

Reviewed at http://reviews.llvm.org/D14330

llvm-svn: 252052
2015-11-04 15:43:45 +00:00
Juergen Ributzka 6e25858b5c Revert "[ASan] Add the new __asan_mz_* symbols to asan_interface_internal.h"
Reverting r228137 to unbreak the build bots.

llvm-svn: 228172
2015-02-04 19:14:35 +00:00
Alexander Potapenko 42fa73cef0 [ASan] Add the new __asan_mz_* symbols to asan_interface_internal.h
to fix the interface_symbols_darwin.c test.

llvm-svn: 228137
2015-02-04 12:42:12 +00:00
Alexander Potapenko 270000c194 [ASan] Remove ifdefs for MAC_OS_X_VERSION_10_6, as ASan assumes OSX >= 10.6
llvm-svn: 227968
2015-02-03 12:47:15 +00:00
Alexander Potapenko f203ba35f1 [ASan] Add __asan_ prefix for "mz_*" allocation/deallocation functions
and make them global so that they're not removed by `strip -x`.

llvm-svn: 227967
2015-02-03 12:38:10 +00:00
Alexey Samsonov 656c29b08f Replace InternalScopedBuffer<char> with InternalScopedString where applicable.
Summary: No functionality change.

Test Plan: make check-all

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits

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

llvm-svn: 223164
2014-12-02 22:20:11 +00:00
Kostya Serebryany b9e31d7fcd [asan] use some LIKELY/UNLIKELY
llvm-svn: 208776
2014-05-14 14:03:31 +00:00
Alexander Potapenko 4672bacaef [ASan] Get rid of asan_mac.h, which contents have been moved to sanitizer_mac.h
llvm-svn: 200757
2014-02-04 11:35:59 +00:00
Alexander Potapenko 768e315a74 [ASan] Move GetMacosVersion() to sanitizer_common.
llvm-svn: 200700
2014-02-03 15:32:19 +00:00
Evgeniy Stepanov 364bfdf4c9 [asan] Fix a bunch of style issues.
llvm-svn: 199380
2014-01-16 13:17:13 +00:00
Evgeniy Stepanov c61623b170 [asan] Implement delayed activation of AddressSanitizer
This change adds ASAN_OPTIONS=start_deactivated=1 flag. When present, ASan will
start in "deactivated" mode, with no heap poisoning, no quarantine, no stack
trace gathering, and minimal redzones. All this features come back when
__asan_init is called for the constructor of an instrumented library.

The primary use case for this feature is Android. Code itself is not
Android-specific, and this patch includes a Linux test for it.

llvm-svn: 199377
2014-01-16 12:31:50 +00:00
Alexander Potapenko d0c91acb58 [ASan] Do not protect the malloc zone created by malloc_zone_create() on Snow Leopard and earlier systems.
Fixes https://code.google.com/p/address-sanitizer/issues/detail?id=208

llvm-svn: 185621
2013-07-04 10:16:12 +00:00
Alexander Potapenko 2b064a2b4e [ASan][OSX] Make sure the zones created by malloc_create_zone() are write-protected.
Add a test.

llvm-svn: 185140
2013-06-28 10:01:09 +00:00
Alexander Potapenko 593f833e9b [ASan][OSX] Fix the incorrect malloc_create_zone() implementation that led to out-of-bounds mprotect()s
(https://code.google.com/p/address-sanitizer/issues/detail?id=203)
Add a test.

llvm-svn: 185138
2013-06-28 09:21:31 +00:00
Alexey Samsonov 21cb74318c [ASan] Kill the remainders of platform defines in favor of SANITIZER_ defines
llvm-svn: 178629
2013-04-03 07:29:53 +00:00
Alexey Samsonov 54afba8b62 [ASan] Switch ASan to generic ThreadRegistry from sanitizer_common. Delete ASan-specific AsanThreadRegistry.
llvm-svn: 177634
2013-03-21 11:23:41 +00:00
Alexey Samsonov 920b3b9a0c [ASan] Move malloc stats collection away from AsanThreadRegistry class.
llvm-svn: 177508
2013-03-20 10:11:24 +00:00
Evgeniy Stepanov 95eaa21637 [sanitizer] More renamed macros.
llvm-svn: 177401
2013-03-19 14:54:17 +00:00
Evgeniy Stepanov 0af672326a [sanitizer] Replace more platform checks with SANITIZER_ constants.
llvm-svn: 177400
2013-03-19 14:33:38 +00:00
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