diff mbox

[12/15] util: add a function to realloc mmapped memory

Message ID 1467104499-27517-13-git-send-email-pl@kamp.de (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Lieven June 28, 2016, 9:01 a.m. UTC
Signed-off-by: Peter Lieven <pl@kamp.de>
---
 include/qemu/mmap-alloc.h |  1 +
 util/mmap-alloc.c         | 10 ++++++++++
 2 files changed, 11 insertions(+)
diff mbox

Patch

diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h
index a457721..935a907 100644
--- a/include/qemu/mmap-alloc.h
+++ b/include/qemu/mmap-alloc.h
@@ -14,5 +14,6 @@  void qemu_ram_munmap(void *ptr, size_t size);
  * for g_malloc0 and friends. */
 void *qemu_anon_ram_mmap(size_t size);
 void qemu_anon_ram_munmap(void *ptr, size_t size);
+void *qemu_anon_ram_remap(void *old_ptr, size_t old_size, size_t new_size);
 
 #endif
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index c099858..5cbe1c5 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -124,3 +124,13 @@  void qemu_anon_ram_munmap(void *ptr, size_t size)
         munmap(ptr, size);
     }
 }
+
+void *qemu_anon_ram_remap(void *old_ptr, size_t old_size, size_t new_size)
+{
+    void *ptr = qemu_anon_ram_mmap(new_size);
+    if (old_ptr) {
+        memcpy(ptr, old_ptr, old_size);
+        qemu_anon_ram_munmap(old_ptr, old_size);
+    }
+    return ptr;
+}