oslib-posix: Print errors before aborting on qemu_alloc_stack()
authorEduardo Habkost <ehabkost@redhat.com>
Tue, 29 Aug 2017 21:20:53 +0000 (18:20 -0300)
committerStefan Hajnoczi <stefanha@redhat.com>
Wed, 30 Aug 2017 08:33:49 +0000 (09:33 +0100)
If QEMU is running on a system that's out of memory and mmap()
fails, QEMU aborts with no error message at all, making it hard
to debug the reason for the failure.

Add perror() calls that will print error information before
aborting.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20170829212053.6003-1-ehabkost@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
util/oslib-posix.c

index cacf0ef5e34acb5124598a9b6f77f1e913d4f0b3..80086c549ff13b0dbc585752a496cc585c9a76c8 100644 (file)
@@ -530,6 +530,7 @@ void *qemu_alloc_stack(size_t *sz)
     ptr = mmap(NULL, *sz, PROT_READ | PROT_WRITE,
                MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
     if (ptr == MAP_FAILED) {
+        perror("failed to allocate memory for stack");
         abort();
     }
 
@@ -544,6 +545,7 @@ void *qemu_alloc_stack(size_t *sz)
     guardpage = ptr;
 #endif
     if (mprotect(guardpage, pagesz, PROT_NONE) != 0) {
+        perror("failed to set up stack guard page");
         abort();
     }