[msan] Check for conflicting memory mappings.

Check for conflicting memory mappings before attempting to map shadow.
Helps avoid segfault on Linux with disabled ASLR.

llvm-svn: 171100
This commit is contained in:
Evgeniy Stepanov 2012-12-26 06:37:23 +00:00
parent a11cd57a78
commit 794a73124b
2 changed files with 9 additions and 1 deletions

View File

@ -240,8 +240,10 @@ void __msan_init() {
if (!InitShadow(/* prot1 */false, /* prot2 */true, /* map_shadow */true,
__msan_track_origins)) {
// FIXME: prot1 = false is only required when running under DR.
Printf("FATAL: MemorySanitizer can not mmap the shadow memory\n");
Printf("FATAL: MemorySanitizer can not mmap the shadow memory.\n");
Printf("FATAL: Make sure to compile with -fPIE and to link with -pie.\n");
Printf("FATAL: Disabling ASLR is known to cause this error.\n");
Printf("FATAL: If running under GDB, try 'set disable-randomization off'.\n");
DumpProcessMap();
Die();
}

View File

@ -51,6 +51,12 @@ bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins) {
Printf("Bad1 : %p %p\n", kBad1Beg, kBad1End);
}
if (!MemoryRangeIsAvailable(kShadowBeg,
init_origins ? kOriginsEnd : kShadowEnd)) {
Printf("FATAL: Shadow memory range is not available.\n");
return false;
}
if (prot1 && !Mprotect(kBad1Beg, kBad1End - kBad1Beg))
return false;
if (prot2 && !Mprotect(kBad2Beg, kBad2End - kBad2Beg))