To allow other code to intercept buffer freeing and do customized unmapping operations.
Signed-off-by: Fam Zheng <f...@redhat.com> --- include/qemu/notify.h | 1 + util/oslib-posix.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/qemu/notify.h b/include/qemu/notify.h index a3d73e4..24c4f5f 100644 --- a/include/qemu/notify.h +++ b/include/qemu/notify.h @@ -69,4 +69,5 @@ void notifier_with_return_remove(NotifierWithReturn *notifier); int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data); +void qemu_vfree_add_notifier(Notifier *n); #endif diff --git a/util/oslib-posix.c b/util/oslib-posix.c index f631464..b0dd207 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -125,9 +125,18 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment) return ptr; } +static NotifierList qemu_vfree_notifiers = + NOTIFIER_LIST_INITIALIZER(qemu_vfree_notifiers); + +void qemu_vfree_add_notifier(Notifier *n) +{ + notifier_list_add(&qemu_vfree_notifiers, n); +} + void qemu_vfree(void *ptr) { trace_qemu_vfree(ptr); + notifier_list_notify(&qemu_vfree_notifiers, ptr); free(ptr); } -- 2.9.3