-#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)
-{
- if (!size) {
- abort();
- }
- return oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
-}
-
-void *qemu_vmalloc(size_t size)
-{
- /* 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();
- }
- return oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
-}
-
-void qemu_vfree(void *ptr)
-{
- VirtualFree(ptr, 0, MEM_RELEASE);
-}
-
-#else
-
-void *qemu_memalign(size_t alignment, size_t size)
-{
-#if defined(_POSIX_C_SOURCE) && !defined(__sun__)
- int ret;
- void *ptr;
- ret = posix_memalign(&ptr, alignment, size);
- if (ret != 0) {
- fprintf(stderr, "Failed to allocate %zu B: %s\n",
- size, strerror(ret));
- abort();
- }
- return ptr;
-#elif defined(CONFIG_BSD)
- return oom_check(valloc(size));
-#else
- return oom_check(memalign(alignment, size));
-#endif
-}
-
-/* alloc shared memory pages */
-void *qemu_vmalloc(size_t size)