From e7a09b92b70786f9e8c5fbf787e0248c6ebbe707 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 13 May 2013 16:19:56 +0200 Subject: osdep: introduce qemu_anon_ram_free to free qemu_anon_ram_alloc-ed memory We switched from qemu_memalign to mmap() but then we don't modify qemu_vfree() to do a munmap() over free(). Which we cannot do because qemu_vfree() frees memory allocated by qemu_{mem,block}align. Introduce a new function that does the munmap(), luckily the size is available in the RAMBlock. Reported-by: Amos Kong Signed-off-by: Paolo Bonzini Reviewed-by: Amos Kong Message-id: 1368454796-14989-3-git-send-email-pbonzini@redhat.com Signed-off-by: Anthony Liguori --- util/oslib-posix.c | 8 ++++++++ util/oslib-win32.c | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'util') diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 6acbbef..631a1de 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -135,6 +135,14 @@ void qemu_vfree(void *ptr) free(ptr); } +void qemu_anon_ram_free(void *ptr, size_t size) +{ + trace_qemu_anon_ram_free(ptr, size); + if (ptr) { + munmap(ptr, size); + } +} + void qemu_set_block(int fd) { int f; diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 5b1fc20..df2ecbd 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -76,6 +76,14 @@ void qemu_vfree(void *ptr) } } +void qemu_anon_ram_free(void *ptr, size_t size) +{ + trace_qemu_anon_ram_free(ptr, size); + if (ptr) { + VirtualFree(ptr, 0, MEM_RELEASE); + } +} + /* FIXME: add proper locking */ struct tm *gmtime_r(const time_t *timep, struct tm *result) { -- cgit v1.1