From patchwork Sat Oct 16 16:04:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 68045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E7CD4B70EE for ; Sun, 17 Oct 2010 03:18:42 +1100 (EST) Received: from localhost ([127.0.0.1]:52004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P79Sw-0007Fs-2a for incoming@patchwork.ozlabs.org; Sat, 16 Oct 2010 12:18:38 -0400 Received: from [140.186.70.92] (port=59299 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P79Fm-0006Zn-BH for qemu-devel@nongnu.org; Sat, 16 Oct 2010 12:05:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P79Fj-0005Rw-Pp for qemu-devel@nongnu.org; Sat, 16 Oct 2010 12:05:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41923) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P79Fj-0005RZ-Iu for qemu-devel@nongnu.org; Sat, 16 Oct 2010 12:04:59 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9GG4w9V018223 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 16 Oct 2010 12:04:58 -0400 Received: from localhost6.localdomain6 ([10.3.113.13]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o9GG4jbB003612; Sat, 16 Oct 2010 12:04:57 -0400 From: Jes.Sorensen@redhat.com To: qemu-devel@nongnu.org Date: Sat, 16 Oct 2010 18:04:42 +0200 Message-Id: <1287245083-26110-9-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1287245083-26110-1-git-send-email-Jes.Sorensen@redhat.com> References: <1287245083-26110-1-git-send-email-Jes.Sorensen@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: blauwirbel@gmail.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 8/9] Consolidate oom_check() functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jes Sorensen This consolidates the duplicated oom_check() functions, as well as splitting them into OS dependant versions to avoid the #ifdef grossness that was present in the old osdep.c version. Signed-off-by: Jes Sorensen --- oslib-posix.c | 8 +++----- oslib-win32.c | 6 +++--- qemu-common.h | 1 + qemu-malloc.c | 14 +++----------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/oslib-posix.c b/oslib-posix.c index ad44b17..6e9b0c3 100644 --- a/oslib-posix.c +++ b/oslib-posix.c @@ -31,8 +31,7 @@ #include "trace.h" #include "qemu_socket.h" -#if !defined(_POSIX_C_SOURCE) || defined(__sun__) -static void *oom_check(void *ptr) +void *qemu_oom_check(void *ptr) { if (ptr == NULL) { fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno)); @@ -40,7 +39,6 @@ static void *oom_check(void *ptr) } return ptr; } -#endif void *qemu_memalign(size_t alignment, size_t size) { @@ -54,9 +52,9 @@ void *qemu_memalign(size_t alignment, size_t size) abort(); } #elif defined(CONFIG_BSD) - ptr = oom_check(valloc(size)); + ptr = qemu_oom_check(valloc(size)); #else - ptr = oom_check(memalign(alignment, size)); + ptr = qemu_oom_check(memalign(alignment, size)); #endif trace_qemu_memalign(alignment, size, ptr); return ptr; diff --git a/oslib-win32.c b/oslib-win32.c index e03c472..ab29eae 100644 --- a/oslib-win32.c +++ b/oslib-win32.c @@ -31,7 +31,7 @@ #include "trace.h" #include "qemu_socket.h" -static void *oom_check(void *ptr) +void *qemu_oom_check(void *ptr) { if (ptr == NULL) { fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError()); @@ -47,7 +47,7 @@ void *qemu_memalign(size_t alignment, size_t size) if (!size) { abort(); } - ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); + ptr = qemu_oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); trace_qemu_memalign(alignment, size, ptr); return ptr; } @@ -62,7 +62,7 @@ void *qemu_vmalloc(size_t size) if (!size) { abort(); } - ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); + ptr = qemu_oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); trace_qemu_vmalloc(size, ptr); return ptr; } diff --git a/qemu-common.h b/qemu-common.h index 81aafa0..ead1d83 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -174,6 +174,7 @@ const char *path(const char *pathname); #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); diff --git a/qemu-malloc.c b/qemu-malloc.c index ecffb67..28fb05a 100644 --- a/qemu-malloc.c +++ b/qemu-malloc.c @@ -25,14 +25,6 @@ #include "trace.h" #include -static void *oom_check(void *ptr) -{ - if (ptr == NULL) { - abort(); - } - return ptr; -} - void qemu_free(void *ptr) { trace_qemu_free(ptr); @@ -54,7 +46,7 @@ void *qemu_malloc(size_t size) if (!size && !allow_zero_malloc()) { abort(); } - ptr = oom_check(malloc(size ? size : 1)); + ptr = qemu_oom_check(malloc(size ? size : 1)); trace_qemu_malloc(size, ptr); return ptr; } @@ -65,7 +57,7 @@ void *qemu_realloc(void *ptr, size_t size) if (!size && !allow_zero_malloc()) { abort(); } - newptr = oom_check(realloc(ptr, size ? size : 1)); + newptr = qemu_oom_check(realloc(ptr, size ? size : 1)); trace_qemu_realloc(ptr, size, newptr); return newptr; } @@ -75,7 +67,7 @@ void *qemu_mallocz(size_t size) if (!size && !allow_zero_malloc()) { abort(); } - return oom_check(calloc(1, size ? size : 1)); + return qemu_oom_check(calloc(1, size ? size : 1)); } char *qemu_strdup(const char *str)