qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] [RESEND] oom_check qemu_memalign
@ 2009-03-31 22:47 Nolan
  0 siblings, 0 replies; only message in thread
From: Nolan @ 2009-03-31 22:47 UTC (permalink / raw)
  To: qemu-devel@nongnu.org

As suggested by Avi on the KVM list, this patch adds oom_check to
qemu_memalign, in the interests of symmetry with qemu_malloc*.

See also:
http://article.gmane.org/gmane.comp.emulators.kvm.devel/29510

This version also updates the win32 version, at malc's request.

Signed-off-by: Nolan Leake <nolan <at> sigbus.net>

Index: osdep.c
===================================================================
--- osdep.c	(revision 6963)
+++ osdep.c	(working copy)
@@ -51,7 +51,8 @@
 #if defined(_WIN32)
 void *qemu_memalign(size_t alignment, size_t size)
 {
-    return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
+    return qemu_oom_check(VirtualAlloc(NULL, size,
+                                       MEM_COMMIT, PAGE_READWRITE));
 }
 
 void *qemu_vmalloc(size_t size)
@@ -186,11 +187,11 @@
     ret = posix_memalign(&ptr, alignment, size);
     if (ret != 0)
         return NULL;
-    return ptr;
+    return qemu_oom_check(ptr);
 #elif defined(HOST_BSD)
-    return valloc(size);
+    return qemu_oom_check(valloc(size));
 #else
-    return memalign(alignment, size);
+    return qemu_oom_check(memalign(alignment, size));
 #endif
 }
 
Index: qemu-common.h
===================================================================
--- qemu-common.h	(revision 6963)
+++ qemu-common.h	(working copy)
@@ -126,6 +126,7 @@
 #define qemu_isascii(c)		isascii((unsigned char)(c))
 #define qemu_toascii(c)		toascii((unsigned char)(c))
 
+void *qemu_oom_check(void *ptr);
 void *qemu_malloc(size_t size);
 void *qemu_realloc(void *ptr, size_t size);
 void *qemu_mallocz(size_t size);
Index: qemu-malloc.c
===================================================================
--- qemu-malloc.c	(revision 6963)
+++ qemu-malloc.c	(working copy)
@@ -24,7 +24,7 @@
 #include "qemu-common.h"
 #include <stdlib.h>
 
-static void *oom_check(void *ptr)
+void *qemu_oom_check(void *ptr)
 {
     if (ptr == NULL)
         abort();
@@ -43,13 +43,13 @@
 
 void *qemu_malloc(size_t size)
 {
-    return oom_check(malloc(size));
+    return qemu_oom_check(malloc(size));
 }
 
 void *qemu_realloc(void *ptr, size_t size)
 {
     if (size)
-        return oom_check(realloc(ptr, size));
+        return qemu_oom_check(realloc(ptr, size));
     else
         return realloc(ptr, size);
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-03-31 22:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-31 22:47 [Qemu-devel] [PATCH] [RESEND] oom_check qemu_memalign Nolan

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).