Commit 39228250 authored by Markus Armbruster's avatar Markus Armbruster Committed by Anthony Liguori

exec: Don't abort when we can't allocate guest memory

We abort() on memory allocation failure.  abort() is appropriate for
programming errors.  Maybe most memory allocation failures are
programming errors, maybe not.  But guest memory allocation failure
isn't, and aborting when the user asks for more memory than we can
provide is not nice.  exit(1) instead, and do it in just one place, so
the error message is consistent.
Tested-by: default avatarChristian Borntraeger <>
Signed-off-by: default avatarMarkus Armbruster <>
Reviewed-by: default avatarAndreas Färber <>
Acked-by: default avatarLaszlo Ersek <>
Acked-by: default avatarStefano Stabellini <>
Acked-by: default avatarChristian Borntraeger <>
Signed-off-by: default avatarAnthony Liguori <>
parent e1e84ba0
......@@ -1150,6 +1150,11 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
if (!new_block->host) {
new_block->host = phys_mem_alloc(size);
if (!new_block->host) {
fprintf(stderr, "Cannot set up guest memory '%s': %s\n",
new_block->mr->name, strerror(errno));
memory_try_enable_merging(new_block->host, size);
......@@ -332,11 +332,7 @@ static void *legacy_s390_alloc(ram_addr_t size)
mem = mmap((void *) 0x800000000ULL, size,
if (mem == MAP_FAILED) {
fprintf(stderr, "Allocating RAM failed\n");
return mem;
return mem == MAP_FAILED ? NULL : mem;
int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
......@@ -112,9 +112,7 @@ void *qemu_anon_ram_alloc(size_t size)
size_t offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
if (ptr == MAP_FAILED) {
fprintf(stderr, "Failed to allocate %zu B: %s\n",
size, strerror(errno));
return NULL;
ptr += offset;
......@@ -65,10 +65,7 @@ void *qemu_anon_ram_alloc(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) {
ptr = qemu_oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
trace_qemu_anon_ram_alloc(size, ptr);
return ptr;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment