diff options
author | Kevin Wolf <kwolf@redhat.com> | 2014-05-20 12:24:05 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-08-15 15:07:15 +0200 |
commit | 7d2a35cc921ea4832083a7e8598461868bb538ce (patch) | |
tree | 0aabab68f9ae59485bba04d9fe374ed0e603af1e /util/oslib-posix.c | |
parent | 23d20b5b4fb7bde102e6779b7a13b88375e4db66 (diff) | |
download | qemu-7d2a35cc921ea4832083a7e8598461868bb538ce.tar.gz qemu-7d2a35cc921ea4832083a7e8598461868bb538ce.tar.bz2 qemu-7d2a35cc921ea4832083a7e8598461868bb538ce.zip |
block: Introduce qemu_try_blockalign()
This function returns NULL instead of aborting when an allocation fails.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Diffstat (limited to 'util/oslib-posix.c')
-rw-r--r-- | util/oslib-posix.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c index cdbfb2e270..016a047cfc 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -94,7 +94,7 @@ void *qemu_oom_check(void *ptr) return ptr; } -void *qemu_memalign(size_t alignment, size_t size) +void *qemu_try_memalign(size_t alignment, size_t size) { void *ptr; @@ -106,19 +106,23 @@ void *qemu_memalign(size_t alignment, size_t size) int ret; ret = posix_memalign(&ptr, alignment, size); if (ret != 0) { - fprintf(stderr, "Failed to allocate %zu B: %s\n", - size, strerror(ret)); - abort(); + errno = ret; + ptr = NULL; } #elif defined(CONFIG_BSD) - ptr = qemu_oom_check(valloc(size)); + ptr = valloc(size); #else - ptr = qemu_oom_check(memalign(alignment, size)); + ptr = memalign(alignment, size); #endif trace_qemu_memalign(alignment, size, ptr); return ptr; } +void *qemu_memalign(size_t alignment, size_t size) +{ + return qemu_oom_check(qemu_try_memalign(alignment, size)); +} + /* alloc shared memory pages */ void *qemu_anon_ram_alloc(size_t size) { |