Skip to content

Commit

Permalink
oslib-posix: Print errors before aborting on qemu_alloc_stack()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Tested-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
ehabkost authored and stefanhaRH committed Aug 30, 2017
1 parent d942fee commit e916a6e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions util/oslib-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down

0 comments on commit e916a6e

Please sign in to comment.