Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 88

kvm-83-270.el5_11.src.rpm

From dba4f2c5855721ab6bc003b6029584ed3b1f1470 Mon Sep 17 00:00:00 2001
From: Eduardo Habkost <ehabkost@redhat.com>
Date: Fri, 15 May 2009 14:12:18 -0300
Subject: [PATCH 13/16] Backport oom_check() from upstream

This includes the following upstream commits:

commit 8a1d02aba9f986ca03d854184cd432ee98bcd179
Author: aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>
Date:   Thu Feb 5 22:05:49 2009 +0000

    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>

    git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6526 c046a42c-6fe2-441c-8c8c-71466251a162

commit 62a3fe29aa33651ca9b0af78dc5e1cf72ecd66be
Author: aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>
Date:   Fri Feb 6 00:19:42 2009 +0000

    Replace exit() in oom_check with abort()

    So that we can get a core dump with a stack trace.

    Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

    git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6542 c046a42c-6fe2-441c-8c8c-71466251a162

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
RH-Upstream-status: applied(qemu/master)
Message-ID: <20090515171218.GC2079@blackpad>
Bugzilla: 501729
Acked-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Glauber Costa <glommer@redhat.com>
Acked-by: Gleb Natapov <gleb@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: john cooper <john.cooper@redhat.com>
---
 qemu/qemu-malloc.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/qemu/qemu-malloc.c b/qemu/qemu-malloc.c
index dc74efe..e9e49cb 100644
--- a/qemu/qemu-malloc.c
+++ b/qemu/qemu-malloc.c
@@ -22,6 +22,14 @@
  * THE SOFTWARE.
  */
 #include "qemu-common.h"
+#include <stdlib.h>
+
+static void *oom_check(void *ptr)
+{
+    if (ptr == NULL)
+        abort();
+    return ptr;
+}
 
 void *get_mmap_addr(unsigned long size)
 {
@@ -35,20 +43,18 @@ void qemu_free(void *ptr)
 
 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 *qemu_strdup(const char *str)
     char *ptr;
     size_t len = strlen(str);
     ptr = qemu_malloc(len + 1);
-    if (!ptr)
-        return NULL;
     memcpy(ptr, str, len + 1);
     return ptr;
 }
-- 
1.6.3.rc4.29.g8146