Fix the memory protection issue in RosAllocSpace::CreateFromMemMap()
From the implementation of RosAllocSpace::CreateFromMemMap(), the memory
beyond the starting_size should be protected.
But the argument of mprotect is wrongly set to be "capacity -
initial_size", logically it should be "capacity - starting_size"
This patch also fix the same issue in dlmalloc
Change-Id: Icbd4ba790f344d4fa79d9896657f638a03d6f8aa
Author: Lin Zang <lin.zang@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
diff --git a/runtime/gc/space/dlmalloc_space.cc b/runtime/gc/space/dlmalloc_space.cc
index 931ed21..1493019 100644
--- a/runtime/gc/space/dlmalloc_space.cc
+++ b/runtime/gc/space/dlmalloc_space.cc
@@ -53,10 +53,10 @@
return nullptr;
}
- // Protect memory beyond the initial size.
+ // Protect memory beyond the starting size. morecore will add r/w permissions when necessory
byte* end = mem_map->Begin() + starting_size;
- if (capacity - initial_size > 0) {
- CHECK_MEMORY_CALL(mprotect, (end, capacity - initial_size, PROT_NONE), name);
+ if (capacity - starting_size > 0) {
+ CHECK_MEMORY_CALL(mprotect, (end, capacity - starting_size, PROT_NONE), name);
}
// Everything is set so record in immutable structure and leave
diff --git a/runtime/gc/space/rosalloc_space.cc b/runtime/gc/space/rosalloc_space.cc
index 86e441e..cc6c1d9 100644
--- a/runtime/gc/space/rosalloc_space.cc
+++ b/runtime/gc/space/rosalloc_space.cc
@@ -56,10 +56,10 @@
return NULL;
}
- // Protect memory beyond the initial size.
+ // Protect memory beyond the starting size. MoreCore will add r/w permissions when necessory
byte* end = mem_map->Begin() + starting_size;
- if (capacity - initial_size > 0) {
- CHECK_MEMORY_CALL(mprotect, (end, capacity - initial_size, PROT_NONE), name);
+ if (capacity - starting_size > 0) {
+ CHECK_MEMORY_CALL(mprotect, (end, capacity - starting_size, PROT_NONE), name);
}
// Everything is set so record in immutable structure and leave