Fall back to true anonymous mmap if out of file descriptors.

MemMap::MapAnonymous needs a file descriptor to create an ashmem
region to label otherwise anonymous mmaps for debugging purposes. If
the process has no file descriptors available, fall back to
traditional anonymous mmap rather than failing.

Test: m test-art-host, m test-art-target
Bug: 32013594
Bug: 32302133
Change-Id: I6b2c770fc031eb8d429407f3a0e7408c52cb1985
diff --git a/runtime/mem_map.cc b/runtime/mem_map.cc
index bb07fcb..ae732b0 100644
--- a/runtime/mem_map.cc
+++ b/runtime/mem_map.cc
@@ -318,11 +318,18 @@
     debug_friendly_name += name;
     fd.Reset(ashmem_create_region(debug_friendly_name.c_str(), page_aligned_byte_count),
              /* check_usage */ false);
+
     if (fd.Fd() == -1) {
-      *error_msg = StringPrintf("ashmem_create_region failed for '%s': %s", name, strerror(errno));
-      return nullptr;
+      // We failed to create the ashmem region. Print a warning, but continue
+      // anyway by creating a true anonymous mmap with an fd of -1. It is
+      // better to use an unlabelled anonymous map than to fail to create a
+      // map at all.
+      PLOG(WARNING) << "ashmem_create_region failed for '" << name << "'";
+    } else {
+      // We succeeded in creating the ashmem region. Use the created ashmem
+      // region as backing for the mmap.
+      flags &= ~MAP_ANONYMOUS;
     }
-    flags &= ~MAP_ANONYMOUS;
   }
 
   // We need to store and potentially set an error number for pretty printing of errors