1 //===-- hwasan_mapping.h ----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file is a part of HWAddressSanitizer and defines memory mapping.
12 //===----------------------------------------------------------------------===//
14 #ifndef HWASAN_MAPPING_H
15 #define HWASAN_MAPPING_H
17 #include "sanitizer_common/sanitizer_internal_defs.h"
18 #include "hwasan_interface_internal.h"
20 // Typical mapping on Linux/x86_64:
21 // with dynamic shadow mapped at [0x770d59f40000, 0x7f0d59f40000]:
22 // || [0x7f0d59f40000, 0x7fffffffffff] || HighMem ||
23 // || [0x7efe2f934000, 0x7f0d59f3ffff] || HighShadow ||
24 // || [0x7e7e2f934000, 0x7efe2f933fff] || ShadowGap ||
25 // || [0x770d59f40000, 0x7e7e2f933fff] || LowShadow ||
26 // || [0x000000000000, 0x770d59f3ffff] || LowMem ||
28 // Typical mapping on Android/AArch64
29 // with dynamic shadow mapped: [0x007477480000, 0x007c77480000]:
30 // || [0x007c77480000, 0x007fffffffff] || HighMem ||
31 // || [0x007c3ebc8000, 0x007c7747ffff] || HighShadow ||
32 // || [0x007bbebc8000, 0x007c3ebc7fff] || ShadowGap ||
33 // || [0x007477480000, 0x007bbebc7fff] || LowShadow ||
34 // || [0x000000000000, 0x00747747ffff] || LowMem ||
36 // Reasonable values are 4 (for 1/16th shadow) and 6 (for 1/64th).
37 constexpr uptr kShadowScale = 4;
38 constexpr uptr kShadowAlignment = 1ULL << kShadowScale;
42 inline uptr MemToShadow(uptr untagged_addr) {
43 return (untagged_addr >> kShadowScale) +
44 __hwasan_shadow_memory_dynamic_address;
46 inline uptr ShadowToMem(uptr shadow_addr) {
47 return (shadow_addr - __hwasan_shadow_memory_dynamic_address) << kShadowScale;
49 inline uptr MemToShadowSize(uptr size) {
50 return size >> kShadowScale;
53 bool MemIsApp(uptr p);
55 } // namespace __hwasan
57 #endif // HWASAN_MAPPING_H