X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fwin32%2FOSMem.c;h=44286d25622a83adb1c05821f1afc833c60bd899;hb=07c01d0911e8b706cb83254f7d3ed86a98e3e3ad;hp=f4c126403abfa852fd8d4e80880509e9f6d84fe5;hpb=016bac72c041e8589ece82fe86906fc9cf8f950c;p=ghc-hetmet.git diff --git a/rts/win32/OSMem.c b/rts/win32/OSMem.c index f4c1264..44286d2 100644 --- a/rts/win32/OSMem.c +++ b/rts/win32/OSMem.c @@ -7,9 +7,8 @@ * ---------------------------------------------------------------------------*/ #include "Rts.h" -#include "OSMem.h" +#include "sm/OSMem.h" #include "RtsUtils.h" -#include "RtsMessages.h" #if HAVE_WINDOWS_H #include @@ -204,6 +203,42 @@ osGetMBlocks(nat n) { return ret; } +void osFreeMBlocks(char *addr, nat n) +{ + alloc_rec *p; + lnat nBytes = (lnat)n * MBLOCK_SIZE; + + insertFree(addr, nBytes); + + p = allocs; + while ((p != NULL) && (addr >= (p->base + p->size))) { + p = p->next; + } + while (nBytes > 0) { + if ((p == NULL) || (p->base > addr)) { + errorBelch("Memory to be freed isn't allocated\n"); + stg_exit(EXIT_FAILURE); + } + if (p->base + p->size >= addr + nBytes) { + if (!VirtualFree(addr, nBytes, MEM_DECOMMIT)) { + sysErrorBelch("osFreeMBlocks: VirtualFree MEM_DECOMMIT failed"); + stg_exit(EXIT_FAILURE); + } + nBytes = 0; + } + else { + lnat bytesToFree = p->base + p->size - addr; + if (!VirtualFree(addr, bytesToFree, MEM_DECOMMIT)) { + sysErrorBelch("osFreeMBlocks: VirtualFree MEM_DECOMMIT failed"); + stg_exit(EXIT_FAILURE); + } + addr += bytesToFree; + nBytes -= bytesToFree; + p = p->next; + } + } +} + void osFreeAllMBlocks(void) { @@ -255,7 +290,7 @@ void setExecutable (void *p, lnat len, rtsBool exec) exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &dwOldProtect) == 0) { - sysErrorBelch("makeExecutable: failed to protect 0x%p; old protection: %lu\n", + sysErrorBelch("setExecutable: failed to protect 0x%p; old protection: %lu\n", p, (unsigned long)dwOldProtect); stg_exit(EXIT_FAILURE); }