Make MemMap::MapAnonymous() fail if the requested address is not available.
Change MapAnonymous() so that a requested address vs. actual map
address mismatch will cause a failure. The existing MapAnonymous()
call sites do not check this. This should prevent potential rare case
bugs where mmap does not happen to map a region at an specified
address.
There's a potential bug that if MapAnonymous() does not guarantee the
requested address (and there's a gap between the image/oat files and
the zygote/malloc space), then GC could in theory allocate a large
object space in the gap. This would break the GC notion of the immune
space. This change will prevent this by causing all non-moving spaces
to be (really) adjacent, with no gaps in between, which CL 87711
missed.
Change-Id: Id4adb0e30adbad497334d7e00def4c0c66b15719
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc
index 4de46e3..0c8a4f0 100644
--- a/runtime/elf_file.cc
+++ b/runtime/elf_file.cc
@@ -835,7 +835,7 @@
if ((program_header.p_flags & PF_R) != 0) {
prot |= PROT_READ;
}
- int flags = MAP_FIXED;
+ int flags = 0;
if (writable_) {
prot |= PROT_WRITE;
flags |= MAP_SHARED;
@@ -853,7 +853,7 @@
program_header.p_memsz,
prot, flags, file_->Fd(),
program_header.p_offset,
- true,
+ true, // implies MAP_FIXED
file_->GetPath().c_str(),
error_msg));
if (segment.get() == nullptr) {