Ignore non-exec and /dev/ maps.

When caching elf maps, do not try and cache a map that is not readable
and writable or is in /dev/. The only exception is to allow caching
maps which begins with /dev/ashmem/.

Bug: 26589772
Change-Id: I670bc5869d125f48f72ee583156db1d4806ca7b9
diff --git a/src/elfxx.h b/src/elfxx.h
index e0343b4..dec1b45 100644
--- a/src/elfxx.h
+++ b/src/elfxx.h
@@ -150,6 +150,18 @@
     unw_addr_space_t as, void* as_arg, struct map_info* map, unw_word_t ip) {
   intrmask_t saved_mask;
 
+  // Don't even try and cache this unless the map is readable and executable.
+  if ((map->flags & (PROT_READ | PROT_EXEC)) != (PROT_READ | PROT_EXEC)) {
+    return false;
+  }
+
+  // Do not try and cache the map if it's a file from /dev/ that is not
+  // /dev/ashmem/.
+  if (map->path != NULL && strncmp ("/dev/", map->path, 5) == 0
+      && strncmp ("ashmem/", map->path + 5, 7) != 0) {
+    return false;
+  }
+
   // Lock while loading the cached elf image.
   lock_acquire (&map->ei_lock, saved_mask);
   if (!map->ei.load_attempted) {