]> git.proxmox.com Git - mirror_qemu.git/commitdiff
memory: add memory_region_is_mapped() API
authorIgor Mammedov <imammedo@redhat.com>
Mon, 2 Jun 2014 13:25:06 +0000 (15:25 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 19 Jun 2014 13:41:47 +0000 (16:41 +0300)
which allows to check if MemoryRegion is already mapped.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
include/exec/memory.h
memory.c

index 549ae734e61786d2153e022ab5f92a82077f2693..f4c8d4933e92967d70c9b72654ae65f56ae638d3 100644 (file)
@@ -847,6 +847,14 @@ void memory_region_set_alias_offset(MemoryRegion *mr,
  */
 bool memory_region_present(MemoryRegion *container, hwaddr addr);
 
+/**
+ * memory_region_is_mapped: returns true if #MemoryRegion is mapped
+ * into any address space.
+ *
+ * @mr: a #MemoryRegion which should be checked if it's mapped
+ */
+bool memory_region_is_mapped(MemoryRegion *mr);
+
 /**
  * memory_region_find: translate an address/size relative to a
  * MemoryRegion into a #MemoryRegionSection.
index 4895e253765640d104d85148727c9471d237e94e..3e8cd5680bbdd2eccaf9357d5ae0fd10451f58a5 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -493,7 +493,7 @@ static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)
             return as;
         }
     }
-    abort();
+    return NULL;
 }
 
 /* Render a memory region into the global view.  Ranges in @view obscure
@@ -1593,6 +1593,11 @@ bool memory_region_present(MemoryRegion *container, hwaddr addr)
     return true;
 }
 
+bool memory_region_is_mapped(MemoryRegion *mr)
+{
+    return mr->container ? true : false;
+}
+
 MemoryRegionSection memory_region_find(MemoryRegion *mr,
                                        hwaddr addr, uint64_t size)
 {
@@ -1610,6 +1615,9 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
     }
 
     as = memory_region_to_address_space(root);
+    if (!as) {
+        return ret;
+    }
     range = addrrange_make(int128_make64(addr), int128_make64(size));
 
     view = address_space_get_flatview(as);