llvm-project/compiler-rt/lib/asan
Marco Vanotti db00fac2a2 [compiler-rt][asan] decommit shadow memory for unmaps in fuchsia.
This CL allows asan allocator in fuchsia to decommit shadow memory
for memory allocated using mmap.

Big allocations in asan end up being allocated via `mmap` and freed with
`munmap`. However, when that memory is freed, asan returns the
corresponding shadow memory back to the OS via a call to
`ReleaseMemoryPagesToOs`.

In fuchsia, `ReleaseMemoryPagesToOs` is a no-op: to be able to free
memory back to the OS, you have to hold a handle to the vmo you want to
modify, which is tricky at the ReleaseMemoryPagesToOs level as that
function is not exclusively used for shadow memory.

The function `__sanitizer_fill_shadow` fills a given shadow memory range
with a specific value, and if that value is 0 (unpoison) and the memory
range is bigger than a threshold parameter, it will decommit that memory
if it is all zeroes.

This CL modifies the `FlushUnneededASanShadowMemory` function in
`asan_poisoning.cpp` to add a call to `__sanitizer_fill_shadow` with
value and threshold = 0. This way, all the unneeded shadow memory gets
returned back to the OS.

A test for this behavior can be found in fxrev.dev/391974

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

Change-Id: Id6dd85693e78a222f0329d5b2201e0da753e01c0
2020-07-21 11:07:47 -07:00
..
scripts [asan_symbolize] Fix bug handling C++ symbols when using Atos. 2020-05-19 16:08:09 -07:00
tests Revert "Temporarily disable the following failing tests on Darwin:" 2020-07-07 10:15:46 -07:00
.clang-format [sanitizer] Remove unneeded blank lines 2018-05-09 00:44:26 +00:00
CMakeLists.txt compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
README.txt
asan.syms.extra
asan_activation.cpp compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_activation.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
asan_activation_flags.inc Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
asan_allocator.cpp [asan] fix a comment typo 2020-06-01 19:14:56 -07:00
asan_allocator.h Revert r369472 and r369441 2019-08-21 05:06:21 +00:00
asan_blacklist.txt
asan_debugging.cpp Update compiler-rt cpplint.py 2019-09-11 21:33:06 +00:00
asan_descriptions.cpp compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_descriptions.h Update compiler-rt cpplint.py 2019-09-11 21:33:06 +00:00
asan_errors.cpp [compiler-rt] Use GetNextInstructionPc in signal handlers 2019-10-02 21:20:37 +00:00
asan_errors.h Reland "[ASan] Do not misrepresent high value address dereferences as null dereferences" 2019-10-10 17:19:58 +00:00
asan_fake_stack.cpp compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_fake_stack.h compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_flags.cpp compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_flags.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
asan_flags.inc [compiler-rt] Better lint output for .inc files 2019-09-12 01:35:09 +00:00
asan_fuchsia.cpp [compiler-rt][asan] decommit shadow memory for unmaps in fuchsia. 2020-07-21 11:07:47 -07:00
asan_globals.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
asan_globals_win.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
asan_init_version.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
asan_interceptors.cpp [compiler-rt] Fix lint check failure on comments 2019-09-22 15:31:03 +00:00
asan_interceptors.h Stop tracking atexit/__cxa_atexit/pthread_atfork allocations in LSan/NetBSD 2019-09-21 07:30:42 +00:00
asan_interceptors_memintrinsics.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
asan_interceptors_memintrinsics.h Remove a few straggler ".cc"s in compiler-rt/lib 2019-08-01 17:53:25 +00:00
asan_interceptors_vfork.S [hwasan, asan] Intercept vfork. 2019-02-27 21:11:50 +00:00
asan_interface.inc [asan] Provide an interface to update an allocation stack trace. 2019-10-31 13:54:46 -07:00
asan_interface_internal.h [asan] Fix lint failure in asan_interface.h 2019-10-31 13:58:55 -07:00
asan_internal.h [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI) 2020-07-16 11:47:05 -07:00
asan_linux.cpp [compiler-rt][asan] decommit shadow memory for unmaps in fuchsia. 2020-07-21 11:07:47 -07:00
asan_lock.h
asan_mac.cpp [compiler-rt][asan] decommit shadow memory for unmaps in fuchsia. 2020-07-21 11:07:47 -07:00
asan_malloc_linux.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
asan_malloc_local.h [asan] Fix debug asan build link error 2019-05-22 20:29:12 +00:00
asan_malloc_mac.cpp compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_malloc_win.cpp Remove unused variables, as suggested by @mcgov. 2019-11-04 14:55:51 -05:00
asan_mapping.h [asan] Use dynamic shadow memory position on Apple Silicon macOS 2020-07-17 17:40:21 -07:00
asan_mapping_myriad.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
asan_mapping_sparc64.h [asan] Dedup MemToShadowSize 2020-07-17 02:40:08 -07:00
asan_memory_profile.cpp compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_new_delete.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
asan_poisoning.cpp [compiler-rt][asan] decommit shadow memory for unmaps in fuchsia. 2020-07-21 11:07:47 -07:00
asan_poisoning.h [ASan] Use __sanitizer_fill_shadow for FastPoisonShadow on Fuchsia 2019-07-11 07:30:11 +00:00
asan_posix.cpp [asan] Unpoison signal alternate stack. 2020-06-16 02:28:38 -07:00
asan_preinit.cpp compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_premap_shadow.cpp [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI) 2020-07-16 11:47:05 -07:00
asan_premap_shadow.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
asan_report.cpp [ASan] Fix issue where system log buffer was not cleared after reporting an issue. 2020-03-26 10:56:17 -07:00
asan_report.h [sanitizer] Implement reallocarray. 2019-05-01 17:33:01 +00:00
asan_rtems.cpp [compiler-rt][asan] decommit shadow memory for unmaps in fuchsia. 2020-07-21 11:07:47 -07:00
asan_rtl.cpp [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI) 2020-07-16 11:47:05 -07:00
asan_scariness_score.h [compiler-rt] Remove some cpplint filters 2019-09-12 02:20:36 +00:00
asan_shadow_setup.cpp [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI) 2020-07-16 11:47:05 -07:00
asan_stack.cpp compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_stack.h compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_stats.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
asan_stats.h Revert r369472 and r369441 2019-08-21 05:06:21 +00:00
asan_suppressions.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
asan_suppressions.h compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_thread.cpp [lsan] Support LeakSanitizer runtime on Fuchsia 2020-01-28 11:34:53 -08:00
asan_thread.h compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
asan_win.cpp [compiler-rt][asan] decommit shadow memory for unmaps in fuchsia. 2020-07-21 11:07:47 -07:00
asan_win_dll_thunk.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
asan_win_dynamic_runtime_thunk.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
asan_win_weak_interception.cpp compiler-rt: Rename .cc file in lib/asan to .cpp 2019-08-01 13:43:28 +00:00
weak_symbols.txt

README.txt

AddressSanitizer RT
================================
This directory contains sources of the AddressSanitizer (ASan) runtime library.

Directory structure:
README.txt       : This file.
Makefile.mk      : File for make-based build.
CMakeLists.txt   : File for cmake-based build.
asan_*.{cc,h}    : Sources of the asan runtime library.
scripts/*        : Helper scripts.
tests/*          : ASan unit tests.

Also ASan runtime needs the following libraries:
lib/interception/      : Machinery used to intercept function calls.
lib/sanitizer_common/  : Code shared between various sanitizers.

ASan runtime currently also embeds part of LeakSanitizer runtime for
leak detection (lib/lsan/lsan_common.{cc,h}).

ASan runtime can only be built by CMake. You can run ASan tests
from the root of your CMake build tree:

make check-asan

For more instructions see:
https://github.com/google/sanitizers/wiki/AddressSanitizerHowToBuild