Skip to contentSkip to conversation

oslib-posix: Print errors before aborting on qemu_alloc_stack()

PATCH Applied Eduardo Habkost 3 participants 4 messages Aug 29, 2017 – Aug 30, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 oslib-posix: Print errors before aborting on qemu_alloc_stack()

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.

---
 util/oslib-posix.c | 2 ++
 1 file changed, 2 insertions(+)
util/oslib-posix.c +2 -0
index cacf0ef..80086c5 100644
@@ -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();
     }
 
Signature · 1 line
2.9.4
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eduardo Habkost

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.

Quoted 25 lines
---
  util/oslib-posix.c | 2 ++
  1 file changed, 2 insertions(+)
util/oslib-posix.c +2 -0
index cacf0ef..80086c5 100644
@@ -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();
      }
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Eduardo Habkost
Quoted 11 lines · Eduardo Habkost

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.

---
 util/oslib-posix.c | 2 ++
 1 file changed, 2 insertions(+)
#3 lore raw
In reply to Eduardo Habkost
Quoted 11 lines · Eduardo Habkost

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.

---
 util/oslib-posix.c | 2 ++
 1 file changed, 2 insertions(+)

Thanks, applied to my block-next tree:
https://github.com/stefanha/qemu/commits/block-next

Stefan