diff options
Diffstat (limited to 'lib/msan/msan_linux.cc')
-rw-r--r-- | lib/msan/msan_linux.cc | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/lib/msan/msan_linux.cc b/lib/msan/msan_linux.cc index 367dc90..46f501e4 100644 --- a/lib/msan/msan_linux.cc +++ b/lib/msan/msan_linux.cc @@ -17,7 +17,6 @@ #include "msan.h" -#include <algorithm> #include <elf.h> #include <link.h> #include <stdio.h> @@ -46,7 +45,13 @@ static const uptr kOriginsBeg = kBad2Beg; static const uptr kOriginsEnd = kBad2End; bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins) { - if (flags()->verbosity) { + if ((uptr) & InitShadow < kMemBeg) { + Printf("FATAL: Code below application range: %p < %p. Non-PIE build?\n", + &InitShadow, (void *)kMemBeg); + return false; + } + + if (common_flags()->verbosity) { Printf("__msan_init %p\n", &__msan_init); Printf("Memory : %p %p\n", kMemBeg, kMemEnd); Printf("Bad2 : %p %p\n", kBad2Beg, kBad2End); @@ -92,41 +97,6 @@ void InstallAtExitHandler() { atexit(MsanAtExit); } -void UnpoisonMappedDSO(link_map *map) { - typedef ElfW(Phdr) Elf_Phdr; - typedef ElfW(Ehdr) Elf_Ehdr; - char *base = (char *)map->l_addr; - Elf_Ehdr *ehdr = (Elf_Ehdr *)base; - char *phdrs = base + ehdr->e_phoff; - char *phdrs_end = phdrs + ehdr->e_phnum * ehdr->e_phentsize; - - // Find the segment with the minimum base so we can "relocate" the p_vaddr - // fields. Typically ET_DYN objects (DSOs) have base of zero and ET_EXEC - // objects have a non-zero base. - uptr preferred_base = ~0ULL; - for (char *iter = phdrs; iter != phdrs_end; iter += ehdr->e_phentsize) { - Elf_Phdr *phdr = (Elf_Phdr *)iter; - if (phdr->p_type == PT_LOAD) - preferred_base = std::min(preferred_base, (uptr)phdr->p_vaddr); - } - - // Compute the delta from the real base to get a relocation delta. - sptr delta = (uptr)base - preferred_base; - // Now we can figure out what the loader really mapped. - for (char *iter = phdrs; iter != phdrs_end; iter += ehdr->e_phentsize) { - Elf_Phdr *phdr = (Elf_Phdr *)iter; - if (phdr->p_type == PT_LOAD) { - uptr seg_start = phdr->p_vaddr + delta; - uptr seg_end = seg_start + phdr->p_memsz; - // None of these values are aligned. We consider the ragged edges of the - // load command as defined, since they are mapped from the file. - seg_start = RoundDownTo(seg_start, GetPageSizeCached()); - seg_end = RoundUpTo(seg_end, GetPageSizeCached()); - __msan_unpoison((void *)seg_start, seg_end - seg_start); - } - } -} - } // namespace __msan #endif // __linux__ |