From b25423e5c288b45f1f1878fe16b6c1e124035ae3 Mon Sep 17 00:00:00 2001 From: ivmai Date: Wed, 16 Sep 2009 08:55:33 +0000 Subject: [PATCH] 2009-09-16 Ivan Maidanski (ivmai125.diff) * os_dep.c (GC_wince_get_mem): If VirtualAlloc() returns NULL (due to out of memory) then don't increment GC_n_heap_bases and don't call VirtualAlloc() again (with MEM_COMMIT). * os_dep.c (GC_remap): Abort with a more informatory message if VirtualAlloc() fails due to out of memory; update FIXME. --- ChangeLog | 9 +++++++++ os_dep.c | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 23e0c1e..eb375f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,13 @@ 2009-09-16 Ivan Maidanski + (ivmai125.diff) + + * os_dep.c (GC_wince_get_mem): If VirtualAlloc() returns NULL (due + to out of memory) then don't increment GC_n_heap_bases and don't + call VirtualAlloc() again (with MEM_COMMIT). + * os_dep.c (GC_remap): Abort with a more informatory message if + VirtualAlloc() fails due to out of memory; update FIXME. + +2009-09-16 Ivan Maidanski (ivmai132.diff - superseding diff41a, diff64, diff84 partly) * Makefile: Fix typo for msvc_dbg.c. diff --git a/os_dep.c b/os_dep.c index 6aaaa10..63436a8 100644 --- a/os_dep.c +++ b/os_dep.c @@ -1962,6 +1962,7 @@ ptr_t GC_wince_get_mem(word bytes) /* If I read the documentation correctly, this can */ /* only happen if HBLKSIZE > 64k or not a power of 2. */ if (GC_n_heap_bases >= MAX_HEAP_SECTS) ABORT("Too many heap sections"); + if (result == NULL) return NULL; GC_heap_bases[GC_n_heap_bases] = result; GC_heap_lengths[GC_n_heap_bases] = 0; GC_n_heap_bases++; @@ -2066,7 +2067,7 @@ void GC_remap(ptr_t start, size_t bytes) ptr_t end_addr = GC_unmap_end(start, bytes); word len = end_addr - start_addr; - /* FIXME: Should we handle out-of-memory here? */ + /* FIXME: Handle out-of-memory correctly (at least for Win32) */ # if defined(MSWIN32) || defined(MSWINCE) ptr_t result; @@ -2082,7 +2083,12 @@ void GC_remap(ptr_t start, size_t bytes) MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (result != start_addr) { - ABORT("VirtualAlloc remapping failed"); + if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY || + GetLastError() == ERROR_OUTOFMEMORY) { + ABORT("Not enough memory to process remapping"); + } else { + ABORT("VirtualAlloc remapping failed"); + } } GC_unmapped_bytes -= alloc_len; start_addr += alloc_len; -- 2.7.4