qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>,
	Blue Swirl <blauwirbel@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Wire g_new() and friends to the qemu_malloc() family
Date: Thu, 18 Aug 2011 10:48:17 -0700	[thread overview]
Message-ID: <1313689697-23627-1-git-send-email-avi@redhat.com> (raw)

This makes the tracing infrastructure available to users of g_new().

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 qemu-common.h |    1 +
 qemu-malloc.c |   15 +++++++++++++++
 vl.c          |    1 +
 3 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/qemu-common.h b/qemu-common.h
index 74d5c4b..fbe2de0 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -180,6 +180,7 @@ const char *path(const char *pathname);
 #define qemu_isascii(c)		isascii((unsigned char)(c))
 #define qemu_toascii(c)		toascii((unsigned char)(c))
 
+void qemu_malloc_init(void);
 void *qemu_oom_check(void *ptr);
 void *qemu_malloc(size_t size);
 void *qemu_realloc(void *ptr, size_t size);
diff --git a/qemu-malloc.c b/qemu-malloc.c
index b9b3851..8b0c1ec 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -24,6 +24,21 @@
 #include "qemu-common.h"
 #include "trace.h"
 #include <stdlib.h>
+#include <glib.h>
+
+static GMemVTable gmemvtable = {
+    .malloc = qemu_malloc,
+    .realloc = qemu_realloc,
+    .free = qemu_free,
+};
+
+/**
+ * qemu_malloc_init: initialize memory management
+ */
+void qemu_malloc_init(void)
+{
+    g_mem_set_vtable(&gmemvtable);
+}
 
 void qemu_free(void *ptr)
 {
diff --git a/vl.c b/vl.c
index c714127..7c4f8da 100644
--- a/vl.c
+++ b/vl.c
@@ -2106,6 +2106,7 @@ int main(int argc, char **argv, char **envp)
 
     atexit(qemu_run_exit_notifiers);
     error_set_progname(argv[0]);
+    qemu_malloc_init();
 
     init_clocks();
 
-- 
1.7.6

             reply	other threads:[~2011-08-18 17:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-18 17:48 Avi Kivity [this message]
2011-08-19  4:25 ` [Qemu-devel] [PATCH] Wire g_new() and friends to the qemu_malloc() family Stefan Hajnoczi
2011-08-19  4:54 ` Peter Maydell
2011-08-19 15:22   ` Avi Kivity
2011-08-20  6:59     ` Blue Swirl
2011-08-21  3:11       ` Anthony Liguori
2011-08-21  7:17         ` Blue Swirl
2011-08-21 13:24           ` Anthony Liguori
2011-08-22  6:53             ` Paolo Bonzini
2011-08-21  3:40 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1313689697-23627-1-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=blauwirbel@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).