Index: lib/msan/msan.h =================================================================== --- lib/msan/msan.h +++ lib/msan/msan.h @@ -54,16 +54,34 @@ #elif SANITIZER_LINUX && defined(__aarch64__) -# if SANITIZER_AARCH64_VMA == 39 +// Maps all possible aarch64 VMA regions for both 39 and 42-bit VMA. +// For debug the parentesis number after the APP region indicates which is +// expected mapping for 39 or 42 bit. const MappingDesc kMemoryLayout[] = { - {0x0000000000ULL, 0x4000000000ULL, MappingDesc::INVALID, "invalid"}, - {0x4000000000ULL, 0x4300000000ULL, MappingDesc::SHADOW, "shadow"}, - {0x4300000000ULL, 0x4600000000ULL, MappingDesc::ORIGIN, "origin"}, - {0x4600000000ULL, 0x5500000000ULL, MappingDesc::INVALID, "invalid"}, - {0x5500000000ULL, 0x5600000000ULL, MappingDesc::APP, "app"}, - {0x5600000000ULL, 0x7000000000ULL, MappingDesc::INVALID, "invalid"}, - {0x7000000000ULL, 0x8000000000ULL, MappingDesc::APP, "app"} + {0x00000000000ULL, 0x04000000000ULL, MappingDesc::INVALID, "invalid"}, + {0x04000000000ULL, 0x04100000000ULL, MappingDesc::SHADOW, "shadow-1"}, + {0x04100000000ULL, 0x04300000000ULL, MappingDesc::SHADOW, "shadow-2"}, + {0x04300000000ULL, 0x04400000000ULL, MappingDesc::ORIGIN, "origin-1"}, + {0x04400000000ULL, 0x04600000000ULL, MappingDesc::ORIGIN, "origin-2"}, + {0x04600000000ULL, 0x05500000000ULL, MappingDesc::INVALID, "invalid"}, + {0x05500000000ULL, 0x05600000000ULL, MappingDesc::APP, "app-1 (39)"}, + {0x05600000000ULL, 0x07000000000ULL, MappingDesc::INVALID, "invalid"}, + {0x07000000000ULL, 0x08000000000ULL, MappingDesc::APP, "app-2 (39)"}, + {0x08000000000ULL, 0x2AA00000000ULL, MappingDesc::INVALID, "invalid"}, + // The segments below are only valid and mapped for 42-bit VMA kernels. + {0x2AA00000000ULL, 0x2AB00000000ULL, MappingDesc::APP, "app-3 (42)"}, + {0x2AB00000000ULL, 0x2C300000000ULL, MappingDesc::INVALID, "invalid"}, + {0x2C300000000ULL, 0x2C400000000ULL, MappingDesc::SHADOW, "shadow-3"}, + {0x2C400000000ULL, 0x2C600000000ULL, MappingDesc::INVALID, "invalid"}, + {0x2C600000000ULL, 0x2C700000000ULL, MappingDesc::ORIGIN, "origin-3"}, + {0x2C700000000ULL, 0x3C100000000ULL, MappingDesc::INVALID, "invalid"}, + {0x3C100000000ULL, 0x3C300000000ULL, MappingDesc::SHADOW, "shadow-4"}, + {0x3C300000000ULL, 0x3C400000000ULL, MappingDesc::INVALID, "invalid"}, + {0x3C400000000ULL, 0x3C600000000ULL, MappingDesc::ORIGIN, "origin-5"}, + {0x3C600000000ULL, 0x3F000000000ULL, MappingDesc::INVALID, "invalid"}, + {0x3F000000000ULL, 0x40000000000ULL, MappingDesc::APP, "app-4 (42)"}, }; + // Maps low and high app ranges to contiguous space with zero base: // Low: 55 0000 0000 - 55 ffff ffff -> 1 0000 0000 - 1 ffff ffff // High: 70 0000 0000 - 7f ffff ffff -> 0 0000 0000 - f ffff ffff @@ -72,27 +90,6 @@ # define MEM_TO_SHADOW(mem) (LINEARIZE_MEM((mem)) + 0x4000000000ULL) # define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x300000000ULL) -# elif SANITIZER_AARCH64_VMA == 42 -const MappingDesc kMemoryLayout[] = { - {0x00000000000ULL, 0x10000000000ULL, MappingDesc::INVALID, "invalid"}, - {0x10000000000ULL, 0x11b00000000ULL, MappingDesc::SHADOW, "shadow"}, - {0x11b00000000ULL, 0x12000000000ULL, MappingDesc::INVALID, "invalid"}, - {0x12000000000ULL, 0x13b00000000ULL, MappingDesc::ORIGIN, "origin"}, - {0x13b00000000ULL, 0x2aa00000000ULL, MappingDesc::INVALID, "invalid"}, - {0x2aa00000000ULL, 0x2ab00000000ULL, MappingDesc::APP, "app"}, - {0x2ab00000000ULL, 0x3f000000000ULL, MappingDesc::INVALID, "invalid"}, - {0x3f000000000ULL, 0x40000000000ULL, MappingDesc::APP, "app"}, -}; -// Maps low and high app ranges to contigous space with zero base: -// 2 aa00 0000 00 - 2 ab00 0000 00: -> 1a00 0000 00 - 1aff ffff ff -// 3 f000 0000 00 - 4 0000 0000 00: -> 0000 0000 00 - 0fff ffff ff -# define LINEARIZE_MEM(mem) \ - (((uptr)(mem) & ~0x3E000000000ULL) ^ 0x1000000000ULL) -# define MEM_TO_SHADOW(mem) (LINEARIZE_MEM((mem)) + 0x10000000000ULL) -# define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x2000000000ULL) - -# endif // SANITIZER_AARCH64_VMA - #elif SANITIZER_LINUX && defined(__powerpc64__) const MappingDesc kMemoryLayout[] = { Index: lib/msan/msan.cc =================================================================== --- lib/msan/msan.cc +++ lib/msan/msan.cc @@ -380,8 +380,6 @@ CacheBinaryName(); InitializeFlags(); - CheckVMASize(); - __sanitizer_set_report_path(common_flags()->log_path); InitializeInterceptors(); Index: lib/msan/msan_linux.cc =================================================================== --- lib/msan/msan_linux.cc +++ lib/msan/msan_linux.cc @@ -119,12 +119,18 @@ return false; } + const uptr maxVirtualAddress = GetMaxVirtualAddress(); + for (unsigned i = 0; i < kMemoryLayoutSize; ++i) { uptr start = kMemoryLayout[i].start; uptr end = kMemoryLayout[i].end; uptr size= end - start; MappingDesc::Type type = kMemoryLayout[i].type; + // Check if the segment should be mapped based on platform constraints. + if (start >= maxVirtualAddress) + continue; + bool map = type == MappingDesc::SHADOW || (init_origins && type == MappingDesc::ORIGIN); bool protect = type == MappingDesc::INVALID || Index: test/msan/mmap.cc =================================================================== --- test/msan/mmap.cc +++ test/msan/mmap.cc @@ -24,16 +24,10 @@ return addr < 0x000100000000ULL || addr >= 0x300000000000ULL; #elif defined(__aarch64__) unsigned long vma = SystemVMA(); - if (vma == 39) - return (addr >= 0x5500000000ULL && addr < 0x5600000000ULL) || - (addr > 0x7000000000ULL); - else if (vma == 42) - return (addr >= 0x2aa00000000ULL && addr < 0x2ab00000000ULL) || - (addr > 0x3f000000000ULL); - else { - fprintf(stderr, "unsupported vma: %lu\n", vma); - exit(1); - } + return (addr >= 0x05500000000ULL && addr < 0x5600000000ULL) || + (addr >= 0x07000000000ULL && addr < 0x08000000000ULL) || + (addr >= 0x2aa00000000ULL && addr < 0x2ab00000000ULL) || + (addr >= 0x3f000000000ULL); #endif } Index: test/msan/strlen_of_shadow.cc =================================================================== --- test/msan/strlen_of_shadow.cc +++ test/msan/strlen_of_shadow.cc @@ -20,21 +20,9 @@ (((uintptr_t)(mem) & ~0x200000000000ULL) ^ 0x100000000000ULL) return (char *)(LINEARIZE_MEM(p) + 0x080000000000ULL); #elif defined(__aarch64__) - unsigned long vma = SystemVMA(); - -#define LINEARIZE_MEM_39(mem) \ +#define LINEARIZE_MEM(mem) \ (((uintptr_t)(mem) & ~0x7C00000000ULL) ^ 0x100000000ULL) -#define LINEARIZE_MEM_42(mem) \ - (((uintptr_t)(mem) & ~0x3E000000000ULL) ^ 0x1000000000ULL) - - if (vma == 39) - return (char *)(LINEARIZE_MEM_39(p) + 0x4000000000ULL); - else if (vma == 42) - return (char *)(LINEARIZE_MEM_42(p) + 0x10000000000ULL); - else { - fprintf(stderr, "unsupported vma: %lu\n", vma); - exit(1); - } + return (char *)(LINEARIZE_MEM(p) + 0x4000000000ULL); #endif }