Fix a SIGSEGV at background-to-foreground collector transition.

The mem map that's used to create the backup main rosalloc space is
set to PROT_NONE by the compaction and the rosalloc space creation
attempts to write the debug magic number in the first page.

This is a debug build only issue.

Cherry pick commit c1276c838d1d0896048b8c14458432b94274e869.

Bug: 16854263
Change-Id: Ide2545d92bcafd3a095ac7f0c89c5b43d6dd78de
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index bf8cca7..02cd25c 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1634,9 +1634,16 @@
         RemoveSpace(bump_pointer_space_);
         bump_pointer_space_ = nullptr;
         const char* name = kUseRosAlloc ? kRosAllocSpaceName[1] : kDlMallocSpaceName[1];
+        // Temporarily unprotect the backup mem map so rosalloc can write the debug magic number.
+        if (kIsDebugBuild && kUseRosAlloc) {
+          mem_map->Protect(PROT_READ | PROT_WRITE);
+        }
         main_space_backup_.reset(CreateMallocSpaceFromMemMap(mem_map.get(), kDefaultInitialSize,
                                                              mem_map->Size(), mem_map->Size(),
                                                              name, true));
+        if (kIsDebugBuild && kUseRosAlloc) {
+          mem_map->Protect(PROT_NONE);
+        }
         mem_map.release();
       }
       break;