From c1b0b93b06ab026ef45ae02d0ee7557741910637 Mon Sep 17 00:00:00 2001 From: Jes Sorensen Date: Tue, 26 Oct 2010 10:39:19 +0200 Subject: Move QEMU OS dependant library functions to OS specific files This moves library functions used by both QEMU and the QEMU tools, such as qemu-img, qemu-nbd etc. from osdep.c to oslib-{posix,win32}.c In addition it introduces oslib-obj.y to the Makefile set to be included by the various targets, instead of relying on these library functions magically getting included via block-obj-y. Signed-off-by: Jes Sorensen Signed-off-by: Blue Swirl --- osdep.c | 85 ----------------------------------------------------------------- 1 file changed, 85 deletions(-) (limited to 'osdep.c') diff --git a/osdep.c b/osdep.c index 2e05b21ad9..581768a906 100644 --- a/osdep.c +++ b/osdep.c @@ -61,91 +61,6 @@ extern int madvise(caddr_t, size_t, int); #include "sysemu.h" #include "qemu_socket.h" -#if !defined(_POSIX_C_SOURCE) || defined(_WIN32) || defined(__sun__) -static void *oom_check(void *ptr) -{ - if (ptr == NULL) { -#if defined(_WIN32) - fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError()); -#else - fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno)); -#endif - abort(); - } - return ptr; -} -#endif - -#if defined(_WIN32) -void *qemu_memalign(size_t alignment, size_t size) -{ - void *ptr; - - if (!size) { - abort(); - } - ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); - trace_qemu_memalign(alignment, size, ptr); - return ptr; -} - -void *qemu_vmalloc(size_t size) -{ - void *ptr; - - /* FIXME: this is not exactly optimal solution since VirtualAlloc - has 64Kb granularity, but at least it guarantees us that the - memory is page aligned. */ - if (!size) { - abort(); - } - ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); - trace_qemu_vmalloc(size, ptr); - return ptr; -} - -void qemu_vfree(void *ptr) -{ - trace_qemu_vfree(ptr); - VirtualFree(ptr, 0, MEM_RELEASE); -} - -#else - -void *qemu_memalign(size_t alignment, size_t size) -{ - void *ptr; -#if defined(_POSIX_C_SOURCE) && !defined(__sun__) - int ret; - ret = posix_memalign(&ptr, alignment, size); - if (ret != 0) { - fprintf(stderr, "Failed to allocate %zu B: %s\n", - size, strerror(ret)); - abort(); - } -#elif defined(CONFIG_BSD) - ptr = oom_check(valloc(size)); -#else - ptr = oom_check(memalign(alignment, size)); -#endif - trace_qemu_memalign(alignment, size, ptr); - return ptr; -} - -/* alloc shared memory pages */ -void *qemu_vmalloc(size_t size) -{ - return qemu_memalign(getpagesize(), size); -} - -void qemu_vfree(void *ptr) -{ - trace_qemu_vfree(ptr); - free(ptr); -} - -#endif - int qemu_madvise(void *addr, size_t len, int advice) { if (advice == QEMU_MADV_INVALID) { -- cgit v1.2.3