From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [6526] Terminate emulation on memory allocation failure (Avi Kivity)
Date: Thu, 05 Feb 2009 22:05:50 +0000 [thread overview]
Message-ID: <E1LVCM2-0007gO-5p@cvs.savannah.gnu.org> (raw)
Revision: 6526
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6526
Author: aliguori
Date: 2009-02-05 22:05:49 +0000 (Thu, 05 Feb 2009)
Log Message:
-----------
Terminate emulation on memory allocation failure (Avi Kivity)
Memory allocation failures are a very rare condition on virtual-memory
hosts. They are also very difficult to handle correctly (especially in a
hardware emulation context). Because of this, it is better to gracefully
terminate emulation rather than executing untested or even unwritten recovery
code paths.
This patch changes the qemu memory allocation routines to terminate emulation
if an allocation failure is encountered.
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Modified Paths:
--------------
trunk/qemu-malloc.c
Modified: trunk/qemu-malloc.c
===================================================================
--- trunk/qemu-malloc.c 2009-02-05 21:24:02 UTC (rev 6525)
+++ trunk/qemu-malloc.c 2009-02-05 22:05:49 UTC (rev 6526)
@@ -22,7 +22,15 @@
* THE SOFTWARE.
*/
#include "qemu-common.h"
+#include <stdlib.h>
+static void *oom_check(void *ptr)
+{
+ if (ptr == NULL)
+ exit(13);
+ return ptr;
+}
+
void *get_mmap_addr(unsigned long size)
{
return NULL;
@@ -35,20 +43,18 @@
void *qemu_malloc(size_t size)
{
- return malloc(size);
+ return oom_check(malloc(size));
}
void *qemu_realloc(void *ptr, size_t size)
{
- return realloc(ptr, size);
+ return oom_check(realloc(ptr, size));
}
void *qemu_mallocz(size_t size)
{
void *ptr;
ptr = qemu_malloc(size);
- if (!ptr)
- return NULL;
memset(ptr, 0, size);
return ptr;
}
@@ -58,8 +64,6 @@
char *ptr;
size_t len = strlen(str);
ptr = qemu_malloc(len + 1);
- if (!ptr)
- return NULL;
memcpy(ptr, str, len + 1);
return ptr;
}
reply other threads:[~2009-02-05 22:05 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=E1LVCM2-0007gO-5p@cvs.savannah.gnu.org \
--to=anthony@codemonkey.ws \
--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).