From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LVCM5-0005mb-F3 for qemu-devel@nongnu.org; Thu, 05 Feb 2009 17:05:53 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LVCM4-0005mH-Ia for qemu-devel@nongnu.org; Thu, 05 Feb 2009 17:05:52 -0500 Received: from [199.232.76.173] (port=44899 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LVCM4-0005mE-CP for qemu-devel@nongnu.org; Thu, 05 Feb 2009 17:05:52 -0500 Received: from savannah.gnu.org ([199.232.41.3]:35478 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LVCM3-0002Oz-M4 for qemu-devel@nongnu.org; Thu, 05 Feb 2009 17:05:51 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LVCM2-0007gS-Bh for qemu-devel@nongnu.org; Thu, 05 Feb 2009 22:05:50 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LVCM2-0007gO-5p for qemu-devel@nongnu.org; Thu, 05 Feb 2009 22:05:50 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 05 Feb 2009 22:05:50 +0000 Subject: [Qemu-devel] [6526] Terminate emulation on memory allocation failure (Avi Kivity) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 Signed-off-by: Anthony Liguori 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 +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; }