From: Nolan <nolan@sigbus.net>
To: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH] [RESEND] oom_check qemu_memalign
Date: Tue, 31 Mar 2009 15:47:03 -0700 [thread overview]
Message-ID: <1238539623.15350.556.camel@voxel> (raw)
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);
}
reply other threads:[~2009-03-31 22:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1238539623.15350.556.camel@voxel \
--to=nolan@sigbus.net \
--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).