diff options
author | Jes Sorensen <Jes.Sorensen@redhat.com> | 2010-10-26 10:39:19 +0200 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2010-10-30 08:02:36 +0000 |
commit | c1b0b93b06ab026ef45ae02d0ee7557741910637 (patch) | |
tree | 586402746c2e86fe219e409bbf55ef2211eb1f3d /osdep.c | |
parent | 9a78eead0c74333a394c0f7bbfc4423ac746fcd5 (diff) | |
download | qemu-c1b0b93b06ab026ef45ae02d0ee7557741910637.tar.gz qemu-c1b0b93b06ab026ef45ae02d0ee7557741910637.tar.bz2 qemu-c1b0b93b06ab026ef45ae02d0ee7557741910637.zip |
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 <Jes.Sorensen@redhat.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'osdep.c')
-rw-r--r-- | osdep.c | 85 |
1 files changed, 0 insertions, 85 deletions
@@ -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) { |