llvm-project/compiler-rt/lib/hwasan
Teresa Johnson 5d2be1a188 [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI)
Summary:
This refactors some common support related to shadow memory setup from
asan and hwasan into sanitizer_common. This should not only reduce code
duplication but also make these facilities available for new compiler-rt
uses (e.g. heap profiling).

In most cases the separate copies of the code were either identical, or
at least functionally identical. A few notes:

In ProtectGap, the asan version checked the address against an upper
bound (kZeroBaseMaxShadowStart, which is (2^18). I have created a copy
of kZeroBaseMaxShadowStart in hwasan_mapping.h, with the same value, as
it isn't clear why that code should not do the same check. If it
shouldn't, I can remove this and guard this check so that it only
happens for asan.

In asan's InitializeShadowMemory, in the dynamic shadow case it was
setting __asan_shadow_memory_dynamic_address to 0 (which then sets both
macro SHADOW_OFFSET as well as macro kLowShadowBeg to 0) before calling
FindDynamicShadowStart(). AFAICT this is only needed because
FindDynamicShadowStart utilizes kHighShadowEnd to
get the shadow size, and kHighShadowEnd is a macro invoking
MEM_TO_SHADOW(kHighMemEnd) which in turn invokes:
(((kHighMemEnd) >> SHADOW_SCALE) + (SHADOW_OFFSET))
I.e. it computes the shadow space needed by kHighMemEnd (the shift), and
adds the offset. Since we only want the shadow space here, the earlier
setting of SHADOW_OFFSET to 0 via __asan_shadow_memory_dynamic_address
accomplishes this. In the hwasan version, it simply gets the shadow
space via "MemToShadowSize(kHighMemEnd)", where MemToShadowSize just
does the shift. I've simplified the asan handling to do the same
thing, and therefore was able to remove the setting of the SHADOW_OFFSET
via __asan_shadow_memory_dynamic_address to 0.

Reviewers: vitalybuka, kcc, eugenis

Subscribers: dberris, #sanitizers, llvm-commits, davidxl

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D83247
2020-07-16 11:47:05 -07:00
..
scripts hwasan_symbolize: allow 0x in the address field 2020-02-03 18:23:48 -08:00
.clang-format [sanitizer] Remove unneeded blank lines 2018-05-09 00:44:26 +00:00
CMakeLists.txt [HWASan] Add sizeof(global) in report even if symbols missing. 2020-06-09 13:02:13 -07:00
hwasan.cpp [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI) 2020-07-16 11:47:05 -07:00
hwasan.h [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI) 2020-07-16 11:47:05 -07:00
hwasan.syms.extra
hwasan_allocator.cpp [hwasan] Untag destination address in hwasan_posix_memalign. 2020-05-08 16:35:48 -07:00
hwasan_allocator.h [hwasan] Remove system allocator fallback. 2019-10-18 22:36:25 +00:00
hwasan_blacklist.txt
hwasan_checks.h hwasan: Improve precision of checks using short granule tags. 2019-07-09 20:22:36 +00:00
hwasan_dynamic_shadow.cpp [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI) 2020-07-16 11:47:05 -07:00
hwasan_dynamic_shadow.h hwasan: Add __hwasan_init_static() function. 2019-01-31 23:37:12 +00:00
hwasan_exceptions.cpp hwasan: Add missing SANITIZER_INTERFACE_ATTRIBUTE on __hwasan_personality_wrapper. 2019-10-18 22:51:38 +00:00
hwasan_flags.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
hwasan_flags.inc [hwasan] Disable malloc-fill by default. 2020-06-05 11:27:16 -07:00
hwasan_globals.cpp [HWASan] Add sizeof(global) in report even if symbols missing. 2020-06-09 13:02:13 -07:00
hwasan_globals.h [HWASan] Add sizeof(global) in report even if symbols missing. 2020-06-09 13:02:13 -07:00
hwasan_interceptors.cpp [hwasan] Remove lazy thread-initialisation 2019-11-04 10:58:46 +00:00
hwasan_interceptors_vfork.S [hwasan] Disable vfork code when building w/o interceptors. 2019-03-01 02:06:58 +00:00
hwasan_interface_internal.h [compiler-rt] Expose __hwasan_tag_mismatch_stub 2019-10-24 11:16:06 +01:00
hwasan_linux.cpp [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI) 2020-07-16 11:47:05 -07:00
hwasan_malloc_bisect.h Runtime flags for malloc bisection. 2019-02-15 18:38:14 +00:00
hwasan_mapping.h [compiler-rt][asan][hwasan] Refactor shadow setup into sanitizer_common (NFCI) 2020-07-16 11:47:05 -07:00
hwasan_memintrinsics.cpp hwasan: Rename source files from cc to cpp 2019-02-27 15:44:03 +00:00
hwasan_new_delete.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
hwasan_poisoning.cpp hwasan: Rename source files from cc to cpp 2019-02-27 15:44:03 +00:00
hwasan_poisoning.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
hwasan_report.cpp [NFC] Rename variable to workaround old gcc bug 2020-06-10 12:14:53 -07:00
hwasan_report.h hwasan: Improve precision of checks using short granule tags. 2019-07-09 20:22:36 +00:00
hwasan_setjmp.S [compiler-rt] libhwasan interceptor ABI intercept longjmp/setjmp 2019-10-30 14:04:40 +00:00
hwasan_tag_mismatch_aarch64.S [compiler-rt] Expose __hwasan_tag_mismatch_stub 2019-10-24 11:16:06 +01:00
hwasan_thread.cpp [hwasan] Reset current thread pointer on thread exit. 2020-05-08 10:31:25 -07:00
hwasan_thread.h hwasan: Remove dead code. NFCI. 2020-01-17 15:12:38 -08:00
hwasan_thread_list.cpp hwasan: Rename source files from cc to cpp 2019-02-27 15:44:03 +00:00
hwasan_thread_list.h [hwasan] Madvise away thread aux data 2019-01-25 02:05:48 +00:00
hwasan_type_test.cpp [compiler-rt] libhwasan interceptor ABI intercept longjmp/setjmp 2019-10-30 14:04:40 +00:00