summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/memrange.h3
-rw-r--r--src/lib/memrange.c16
2 files changed, 19 insertions, 0 deletions
diff --git a/src/include/memrange.h b/src/include/memrange.h
index 46a992adb5..7f42aa2b0b 100644
--- a/src/include/memrange.h
+++ b/src/include/memrange.h
@@ -98,6 +98,9 @@ void memranges_init(struct memranges *ranges,
unsigned long mask, unsigned long match,
unsigned long tag);
+/* Clone a memrange. The new memrange has the same entries as the old one. */
+void memranges_clone(struct memranges *newranges, struct memranges *oldranges);
+
/* Remove and free all entries within the memranges structure. */
void memranges_teardown(struct memranges *ranges);
diff --git a/src/lib/memrange.c b/src/lib/memrange.c
index d3cda121f1..96d7524218 100644
--- a/src/lib/memrange.c
+++ b/src/lib/memrange.c
@@ -310,6 +310,22 @@ void memranges_init(struct memranges *ranges,
memranges_add_resources(ranges, mask, match, tag);
}
+/* Clone a memrange. The new memrange has the same entries as the old one. */
+void memranges_clone(struct memranges *newranges, struct memranges *oldranges)
+{
+ struct range_entry *r, *cur;
+ struct range_entry **prev_ptr;
+
+ memranges_init_empty(newranges, NULL, 0);
+
+ prev_ptr = &newranges->entries;
+ memranges_each_entry(r, oldranges) {
+ cur = range_list_add(newranges, prev_ptr, r->begin, r->end,
+ r->tag);
+ prev_ptr = &cur->next;
+ }
+}
+
void memranges_teardown(struct memranges *ranges)
{
while (ranges->entries != NULL) {