@@ -1217,6 +1217,17 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
hwaddr addr, uint64_t size);
/**
+ * memory_region_find_by_name: Locates the first #MemoryRegion within @mr
+ * whose name matches @name
+ *
+ * @mr: the root MemoryRegion
+ * @name: name of the target MemoryRegion
+ *
+ * Returns the matched memory region or NULL
+ */
+MemoryRegion *memory_region_find_by_name(MemoryRegion *mr, const char *name);
+
+/**
* memory_global_dirty_log_sync: synchronize the dirty log for all memory
*
* Synchronizes the dirty page log for all address spaces.
@@ -2166,6 +2166,22 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
return ret;
}
+MemoryRegion *memory_region_find_by_name(MemoryRegion *root,
+ const char *name)
+{
+ MemoryRegion *other;
+
+ QTAILQ_FOREACH(other, &root->subregions, subregions_link) {
+ if (!strcmp(other->name, name)) {
+ memory_region_ref(other);
+ return other;
+ } else {
+ memory_region_find_by_name(other, name);
+ }
+ }
+ return NULL;
+}
+
bool memory_region_present(MemoryRegion *container, hwaddr addr)
{
MemoryRegion *mr;
This new helper makes possible to search for a MemoryRegion matching a given name within a root MemoryRegion. Signed-off-by: Eric Auger <eric.auger@redhat.com> --- include/exec/memory.h | 11 +++++++++++ memory.c | 16 ++++++++++++++++ 2 files changed, 27 insertions(+)