mirror of
https://github.com/qemu/qemu.git
synced 2025-08-09 01:50:43 +00:00
Tell users about out-of-memory errors
Aborting without an error message when memory is short is not helpful, so print the reason for the abort. Try qemu -m 1000000 or qemu -m 2000 (win32) to force an out-of-memory error. v2: * Fix error message for win32. * Fix error message for posix_memalign. Thanks to malc for the hints. Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
776e1bbb6c
commit
d2d5adcb58
10
osdep.c
10
osdep.c
@ -52,6 +52,11 @@
|
|||||||
static void *oom_check(void *ptr)
|
static void *oom_check(void *ptr)
|
||||||
{
|
{
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno));
|
||||||
|
#endif
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
@ -91,8 +96,11 @@ void *qemu_memalign(size_t alignment, size_t size)
|
|||||||
int ret;
|
int ret;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
ret = posix_memalign(&ptr, alignment, size);
|
ret = posix_memalign(&ptr, alignment, size);
|
||||||
if (ret != 0)
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "Failed to allocate %zu B: %s\n",
|
||||||
|
size, strerror(ret));
|
||||||
abort();
|
abort();
|
||||||
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
#elif defined(CONFIG_BSD)
|
#elif defined(CONFIG_BSD)
|
||||||
return oom_check(valloc(size));
|
return oom_check(valloc(size));
|
||||||
|
Loading…
Reference in New Issue
Block a user