summaryrefslogtreecommitdiff
path: root/lib/asan/asan_mac.cc
AgeCommit message (Collapse)Author
2017-07-12[asan] For iOS/AArch64, if the dynamic shadow doesn't fit, restrict the VM spaceKuba Mracek
On iOS/AArch64, the address space is very limited and has a dynamic maximum address based on the configuration of the device. We're already using a dynamic shadow, and we find a large-enough "gap" in the VM where we place the shadow memory. In some cases and some device configuration, we might not be able to find a large-enough gap: E.g. if the main executable is linked against a large number of libraries that are not part of the system, these libraries can fragment the address space, and this happens before ASan starts initializing. This patch has a solution, where we have a "backup plan" when we cannot find a large-enough gap: We will restrict the address space (via MmapFixedNoAccess) to a limit, for which the shadow limit will fit. Differential Revision: https://reviews.llvm.org/D35098 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307865 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-21[compiler-rt][asan] Add support for desallocation of unhandled pointersEtienne Bergeron
Summary: On windows 10, the ucrt DLL is performing allocations before the function hooking and there are multiple allocations not handled by Asan. When a free occur at the end of the process, asan is reporting desallocations not malloc-ed. Reviewers: rnk, kcc Reviewed By: rnk, kcc Subscribers: kcc, llvm-commits, kubamracek, chrisha, dberris Differential Revision: https://reviews.llvm.org/D25946 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295730 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02[tsan] Properly describe GCD worker threads in reportsKuba Mracek
When dealing with GCD worker threads, TSan currently prints weird things like "created by thread T-1" and "[failed to restore the stack]" in reports. This patch avoids that and instead prints "Thread T3 (...) is a GCD worker thread". Differential Revision: https://reviews.llvm.org/D29103 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293882 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27[compiler-rt] Move logic which replace memcpy interceptor with memmove from ↵Vitaly Buka
asan to sanitizer_common. Reviewers: eugenis Subscribers: kubabrecka, dberris, llvm-commits Differential Revision: https://reviews.llvm.org/D28074 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290626 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-11[asan] Add exception handler to map memory on demand on Win64.Etienne Bergeron
Memory will be committed on demand when exception happens while accessing shadow memeory region. Patch by: Wei Wang Differential Revision: http://reviews.llvm.org/D21942 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@275107 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-28[asan] Add runtime support for __asan_(un)register_image_globalsRyan Govostes
This change introduces routines that register and unregister all instrumented globals in a loaded executable image. These routines are only implemented on Darwin, where globals metadata is expected to be placed in the __DATA,__asan_globals section. Review: http://reviews.llvm.org/D16841 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@264644 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-02[asan] Add iOS support.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@259451 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-04[ASan] Fix the links to bugs and wikipages.Alexander Potapenko
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@254735 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-03[tsan] Use re-exec method to enable interceptors on older versions of OS XKuba Brecka
In AddressSanitizer, we have the MaybeReexec method to detect when we're running without DYLD_INSERT_LIBRARIES (in which case interceptors don't work) and re-execute with the environment variable set. On OS X 10.11+, this is no longer necessary, but to have ThreadSanitizer supported on older versions of OS X, let's use the same method as well. This patch moves the implementation from `asan/` into `sanitizer_common/`. Differential Revision: http://reviews.llvm.org/D15123 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@254600 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-27[asan] Sort headers.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@251446 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-07Revert r246961 "[asan] Intercept and wrap XPC callback blocks".Kuba Brecka
There is a build failure for the simulator. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@246967 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-07[asan] Intercept and wrap XPC callback blocksKuba Brecka
On recent OS X systems, blocks used as callbacks for XPC events (set up e.g. via xpc_connection_set_event_handler) are not later executed via the public libdispatch API (dispatch_async, etc). Because we don't intercept the path where the block is executed, we can fail to register the newly created dispatch thread. To fix that, let's intercept libxpc's APIs that take a block as a callback handler, and let's wrap these blocks in the same way as we do for libdispatch API. Differential Revision: http://reviews.llvm.org/D12490 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@246961 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-03[asan] Fix dyld version detection on OS XKuba Brecka
We currently have a dyld check in DyldNeedsEnvVariable that detects whether we are on a new OS X (10.11+) where we don't need to re-exec. For iOS simulator, we have a dlsym() hack that checks for a specific symbol, but this turns out to be fragile and problematic, because dlsym can sometimes call malloc(), which is not a good idea this early in the process runtime. Let's instead of this do a direct comparison of dyld's version, which is exported in a public symbol `dyldVersionNumber`. Differential Revision: http://reviews.llvm.org/D11719 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@243879 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-21[asan] Remove AsanPlatformThreadInitReid Kleckner
Since the CoreFoundation allocator replacement was moved in r173134, all implementations of this function have been empty. Reviewers: samsonov Differential Revision: http://reviews.llvm.org/D11375 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@242811 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-06[asan] Add OS X 10.11's new dyld interposition supportKuba Brecka
On OS X 10.11 (which is currently a public beta), the dynamic linker has been improved so that it doesn't require the use of DYLD_INSERT_LIBRARIES in order for interposition/wrappers to work. This patch adds support of this behavior into ASan – we no longer need to re-exec in case the env. variable is not set. Reviewed at http://reviews.llvm.org/D10924 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@241487 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-23Working on reconciling out-of-tree patches to compiler-rt for building for iOS.Chris Bieneman
Summary: This is one of many changes needed for compiler-rt to get it building on iOS. This change ifdefs out headers and functionality that aren't available on iOS, and adds support for iOS and the iOS simulator to as an. Note: this change does not enable building for iOS, as there are more changes to come. Reviewers: glider, kubabrecka, bogner, samsonov Reviewed By: samsonov Subscribers: samsonov, zaks.anna, llvm-commits Differential Revision: http://reviews.llvm.org/D10515 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@240469 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-23Working on reconciling out-of-tree patches to compiler-rt for building for iOS.Chris Bieneman
Summary: This is one of many changes needed for compiler-rt to get it building on iOS. This change does the following: - Don't include crt_externs on iOS (it isn't available) - Support ARM thread state objects Note: this change does not enable building for iOS, as there are more changes to come. Reviewers: glider, kubabrecka, bogner, samsonov Reviewed By: samsonov Subscribers: samsonov, aemerson, llvm-commits Differential Revision: http://reviews.llvm.org/D10510 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@240467 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-16[ASan] NFC: Factor out platform-specific interceptorsTimur Iskhodzhanov
Reviewed at http://reviews.llvm.org/D8321 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@232377 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-02asan: fix signal handling during stoptheworldDmitry Vyukov
The problem is that without SA_RESTORER flag, kernel ignores the handler. So tracer actually did not setup any handler. Add SA_RESTORER flag when setting up handlers. Add a test that causes SIGSEGV in stoptheworld callback. Move SignalContext from asan to sanitizer_common to print better diagnostics about signal in the tracer thread. http://reviews.llvm.org/D8005 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@230978 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-10Fix ASan's Noinst unit testsKuba Brecka
We currently skip all "Noinst" unit tests on OS X, which was probably caused when we removed the "allow_reexec" flag. The MaybeReexec function fails to re-execute when the runtime is linked statically, because there is no dylib to use. This patch adds an explicit DisableReexec function that is used from asan_noinst_test.cc and the runtime then doesn't try to re-execute. Reviewed at http://reviews.llvm.org/D7493 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@228740 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-06[compiler-rt] Make MaybeReexec properly process DYLD_INSERT_LIBRARIES when ↵Kuba Brecka
using non-absolute paths MaybeReexec() in asan_mac.cc checks for presence of the ASan dylib in DYLD_INSERT_LIBRARIES, and if it is there, it will process this env. var. and remove the dylib from its value, so that spawned children don't have this variable set. However, the current implementation only works when using a canonical absolute path to the dylib, it fails to remove the dylib for example when using @executable_path. This patch changes the processing of DYLD_INSERT_LIBRARIES to comparing values only based on filenames (ignoring directories). Reviewed at http://reviews.llvm.org/D7160 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@228392 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-22Fix/workaround for OS X truncated stacktraces taken by external toolsKuba Brecka
This patch is a proposed solution for https://code.google.com/p/address-sanitizer/issues/detail?id=375: When the stacktraces are captured and printed by ASan itself, they are fine, but when the program has already printed the report (or is just printing it), capturing a stacktrace via other means is broken. "Other means" include OS X CrashReporter, debuggers or calling backtrace() within the program. For example calling backtrace() from a sanitizer_set_death_callback function prints a very truncated stacktrace. Reviewed at http://reviews.llvm.org/D7103 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@226878 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-20[asan] Allow changing verbosity in activation flags.Evgeniy Stepanov
This change removes some debug output in asan_flags.cc that was reading the verbosity level before all the flags were parsed. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@226566 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-09Remove AsanInterceptsSignal in favor of (equivalent) IsDeadlySignal.Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@225556 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-22AddressSanitizer: Abort after failed exec() and get rid of the allow_reexec ↵Kuba Brecka
ASan flag As mentioned in https://code.google.com/p/address-sanitizer/issues/detail?id=365, when the re-exec that adds the required DYLD_INSERT_LIBRARIES variable fails, ASan currently continues to run, but things are broken (some memory can be overwritten, interceptors don't work, ...). This patch aborts if the execv() fails and prints an error message that DYLD_INSERT_LIBRARIES is required. It also removes the "alllow_reexec" flag, since using it causes the same issues. Reviewed at http://reviews.llvm.org/D6752 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224712 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-22AddressSanitizer: Properly handle dispatch_source_set_cancel_handler with aKuba Brecka
NULL handler Per https://developer.apple.com/library/mac/documentation/Performance/Reference/GCD_libdispatch_Ref/index.html, the dispatch_source_set_cancel_handler() API *can* be called with a NULL handler. In that case, the libdispatch removes an already existing cancellation handler, if there was one. ASan's interceptor always creates a new block that always tries to call the original handler. In case the original block is NULL, a segmentation fault happens. Let's fix that by not wrapping a NULL-block at all. It looks like all the other libdispatch APIs (which we intercept) do *not* allow NULL. So it's really only the dispatch_source_set_cancel_handler one that needs this fix. Reviewed at http://reviews.llvm.org/D6747 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224711 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-05[ASan] Refactor thread starting code.Sergey Matveev
Move thread context creation into AsanThread::Create(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223483 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-19Make the ASan OS X DYLD_INSERT_LIBRARIES detection path-independentKuba Brecka
Reviewed at http://reviews.llvm.org/D6238 ASan on Darwin during launch reads DYLD_INSERT_LIBRARIES env. variable and if it's not set or if the ASan dylib is not present in there, it relaunches the process. The check whether the dylib is present in the variable is now trying to find a full path in there. This fails in the scenarios where we want to copy the dylib to the executable's directory or somewhere else and set the DYLD_INSERT_LIBRARIES manually, see http://reviews.llvm.org/D6018. Let's change the search in DYLD_INSERT_LIBRARIES to only look for the filename of the dylib and not the full path. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@222297 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-27Unbreak the darwin build.Adrian Prantl
Patch by Ismail Pazarbasi! git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@220683 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-10[ASan] Force the compiler to generate frame pointer in certain Mac-specific ↵Alexey Samsonov
interceptors. Patch by Kuba Brecka! git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212664 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-01[ASan] Optional support for dynamic ASan runtime on Linux.Alexey Samsonov
Based on http://llvm-reviews.chandlerc.com/D3042 by Yuri Gribov! git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@205308 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-04[ASan] Get rid of asan_mac.h, which contents have been moved to sanitizer_mac.hAlexander Potapenko
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200757 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-03[ASan] Move GetMacosVersion() to sanitizer_common.Alexander Potapenko
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200700 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-28[ASan] Move the signal handling-related flags to sanitizer_common.Alexander Potapenko
This change is a part of refactoring intended to have common signal handling behavior in all tools. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200295 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-26[ASan] Delete asan_intercepted_functions.h, move the code into ↵Alexander Potapenko
asan_interceptors.h Fixes https://code.google.com/p/address-sanitizer/issues/detail?id=188. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@198048 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-05[sanitizer] Introduce VReport and VPrintf macros and use them in sanitizer code.Sergey Matveev
Instead of "if (common_flags()->verbosity) Report(...)" we now have macros. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@196497 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-15tsan: move verbosity flag to CommonFlagsDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192701 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-16[ASan] Cache the OSX version to avoid calling sysctl() on every ↵Alexander Potapenko
GetMacosVersion() call. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@186389 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-16[ASan] Add support for OS X Mavericks to GetMacosVersion.Alexander Potapenko
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@186386 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-08[sanitizer] Move GetStackTrace from ASan to sanitizer_common.Sergey Matveev
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@181424 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-05[sanitizer] found a bug by code inspection: CHECK(a=b) instead of ↵Kostya Serebryany
CHECK(a==b). Was puzzled why lint did not catch it. Turns out this check was disabled for asan source. fix all cases and enable the check git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@178872 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-03[ASan] Kill the remainders of platform defines in favor of SANITIZER_ definesAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@178629 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-28Remove all 'static' before ALWAYS_INLINETimur Iskhodzhanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@178290 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-21[ASan] Switch ASan to generic ThreadRegistry from sanitizer_common. Delete ↵Alexey Samsonov
ASan-specific AsanThreadRegistry. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177634 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-20[ASan] Move malloc stats collection away from AsanThreadRegistry class.Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177508 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-19[sanitizer] More renamed macros.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177401 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-19[sanitizer] Replace more platform checks with SANITIZER_ constants.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177400 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-21[ASan] Refactoring: nuke the redundant function declarations in ↵Alexander Potapenko
asan_intercepted_functions.h that had been used on OS X only. The INTERCEPTOR() macro on OS X is now responsible for declaring the wrapped function, the wrapper and the pair of pointers to them in __DATA,__interposition section. Thus adding an interceptor requires editing a single file now. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@175740 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-19[asan] instrument memory accesses with unusual sizesKostya Serebryany
This patch makes asan instrument memory accesses with unusual sizes (e.g. 5 bytes or 10 bytes), e.g. long double or packed structures. Instrumentation is done with two 1-byte checks (first and last bytes) and if the error is found __asan_report_load_n(addr, real_size) or __asan_report_store_n(addr, real_size) is called. asan-rt part Also fix lint. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@175508 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-15[ASan] make variables unsigned to silence warnings - attempt 2Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@175285 91177308-0d34-0410-b5e6-96231b3b80d8