提交 b152aa84 编写于 作者: J Jes Sorensen 提交者: Blue Swirl

Consolidate oom_check() functions

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: NJes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: NBlue Swirl <blauwirbel@gmail.com>
上级 bc4a957c
...@@ -88,7 +88,7 @@ $(call set-vpath, $(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR ...@@ -88,7 +88,7 @@ $(call set-vpath, $(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR
QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \ obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o \ elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o \
qemu-malloc.o qemu-malloc.o $(oslib-obj-y)
obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_HAS_BFLT) += flatload.o
......
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
#include "trace.h" #include "trace.h"
#include "qemu_socket.h" #include "qemu_socket.h"
#if !defined(_POSIX_C_SOURCE) || defined(__sun__) void *qemu_oom_check(void *ptr)
static void *oom_check(void *ptr)
{ {
if (ptr == NULL) { if (ptr == NULL) {
fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno)); fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno));
...@@ -40,7 +39,6 @@ static void *oom_check(void *ptr) ...@@ -40,7 +39,6 @@ static void *oom_check(void *ptr)
} }
return ptr; return ptr;
} }
#endif
void *qemu_memalign(size_t alignment, size_t size) void *qemu_memalign(size_t alignment, size_t size)
{ {
...@@ -54,9 +52,9 @@ void *qemu_memalign(size_t alignment, size_t size) ...@@ -54,9 +52,9 @@ void *qemu_memalign(size_t alignment, size_t size)
abort(); abort();
} }
#elif defined(CONFIG_BSD) #elif defined(CONFIG_BSD)
ptr = oom_check(valloc(size)); ptr = qemu_oom_check(valloc(size));
#else #else
ptr = oom_check(memalign(alignment, size)); ptr = qemu_oom_check(memalign(alignment, size));
#endif #endif
trace_qemu_memalign(alignment, size, ptr); trace_qemu_memalign(alignment, size, ptr);
return ptr; return ptr;
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "trace.h" #include "trace.h"
#include "qemu_socket.h" #include "qemu_socket.h"
static void *oom_check(void *ptr) void *qemu_oom_check(void *ptr)
{ {
if (ptr == NULL) { if (ptr == NULL) {
fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError()); fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
...@@ -47,7 +47,7 @@ void *qemu_memalign(size_t alignment, size_t size) ...@@ -47,7 +47,7 @@ void *qemu_memalign(size_t alignment, size_t size)
if (!size) { if (!size) {
abort(); 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); trace_qemu_memalign(alignment, size, ptr);
return ptr; return ptr;
} }
...@@ -62,7 +62,7 @@ void *qemu_vmalloc(size_t size) ...@@ -62,7 +62,7 @@ void *qemu_vmalloc(size_t size)
if (!size) { if (!size) {
abort(); 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); trace_qemu_vmalloc(size, ptr);
return ptr; return ptr;
} }
......
...@@ -175,6 +175,7 @@ const char *path(const char *pathname); ...@@ -175,6 +175,7 @@ const char *path(const char *pathname);
int ffs(int i); int ffs(int i);
#endif #endif
void *qemu_oom_check(void *ptr);
void *qemu_malloc(size_t size); void *qemu_malloc(size_t size);
void *qemu_realloc(void *ptr, size_t size); void *qemu_realloc(void *ptr, size_t size);
void *qemu_mallocz(size_t size); void *qemu_mallocz(size_t size);
......
...@@ -25,14 +25,6 @@ ...@@ -25,14 +25,6 @@
#include "trace.h" #include "trace.h"
#include <stdlib.h> #include <stdlib.h>
static void *oom_check(void *ptr)
{
if (ptr == NULL) {
abort();
}
return ptr;
}
void qemu_free(void *ptr) void qemu_free(void *ptr)
{ {
trace_qemu_free(ptr); trace_qemu_free(ptr);
...@@ -54,7 +46,7 @@ void *qemu_malloc(size_t size) ...@@ -54,7 +46,7 @@ void *qemu_malloc(size_t size)
if (!size && !allow_zero_malloc()) { if (!size && !allow_zero_malloc()) {
abort(); abort();
} }
ptr = oom_check(malloc(size ? size : 1)); ptr = qemu_oom_check(malloc(size ? size : 1));
trace_qemu_malloc(size, ptr); trace_qemu_malloc(size, ptr);
return ptr; return ptr;
} }
...@@ -65,7 +57,7 @@ void *qemu_realloc(void *ptr, size_t size) ...@@ -65,7 +57,7 @@ void *qemu_realloc(void *ptr, size_t size)
if (!size && !allow_zero_malloc()) { if (!size && !allow_zero_malloc()) {
abort(); abort();
} }
newptr = oom_check(realloc(ptr, size ? size : 1)); newptr = qemu_oom_check(realloc(ptr, size ? size : 1));
trace_qemu_realloc(ptr, size, newptr); trace_qemu_realloc(ptr, size, newptr);
return newptr; return newptr;
} }
...@@ -75,7 +67,7 @@ void *qemu_mallocz(size_t size) ...@@ -75,7 +67,7 @@ void *qemu_mallocz(size_t size)
if (!size && !allow_zero_malloc()) { if (!size && !allow_zero_malloc()) {
abort(); abort();
} }
return oom_check(calloc(1, size ? size : 1)); return qemu_oom_check(calloc(1, size ? size : 1));
} }
char *qemu_strdup(const char *str) char *qemu_strdup(const char *str)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册