]> Git Repo - qemu.git/commitdiff
exec: Don't abort when we can't allocate guest memory
authorMarkus Armbruster <[email protected]>
Wed, 31 Jul 2013 13:11:11 +0000 (15:11 +0200)
committerAnthony Liguori <[email protected]>
Thu, 12 Sep 2013 16:45:32 +0000 (11:45 -0500)
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: Christian Borntraeger <[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Andreas Färber <[email protected]>
Acked-by: Laszlo Ersek <[email protected]>
Acked-by: Stefano Stabellini <[email protected]>
Acked-by: Christian Borntraeger <[email protected]>
Message-id: 1375276272[email protected]
Signed-off-by: Anthony Liguori <[email protected]>
exec.c
target-s390x/kvm.c
util/oslib-posix.c
util/oslib-win32.c

diff --git a/exec.c b/exec.c
index 59debc9cd8218b9527f0d1b304d12f70f31c1379..26469120d949e68473f07cdd9185b02d78594fd0 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -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));
+                exit(1);
+            }
             memory_try_enable_merging(new_block->host, size);
         }
     }
index 0b75164ddbb7ad7818b103476f8341c291674c7a..4923e0a71752e306321408d38f8cbb5d02ff13a1 100644 (file)
@@ -332,11 +332,7 @@ static void *legacy_s390_alloc(ram_addr_t size)
     mem = mmap((void *) 0x800000000ULL, size,
                PROT_EXEC|PROT_READ|PROT_WRITE,
                MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
-    if (mem == MAP_FAILED) {
-        fprintf(stderr, "Allocating RAM failed\n");
-        abort();
-    }
-    return mem;
+    return mem == MAP_FAILED ? NULL : mem;
 }
 
 int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
index 3dc8b1b0743192aa929af70e85746b5b2106041d..253bc3df2e899ccf9e4a7e1cde9c5886b86dd877 100644 (file)
@@ -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));
-        abort();
+        return NULL;
     }
 
     ptr += offset;
index 961fbf5e3de5d35d77c97814adf6f97762bd357c..983b7a2375808608c6dc16a604b33fffafa2c942 100644 (file)
@@ -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) {
-        abort();
-    }
-    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;
 }
This page took 0.034438 seconds and 4 git commands to generate.