X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fposix%2FOSMem.c;h=bfe12964a23cea2f5f13dda3e4f7dad432e0f371;hb=05fd4e9ddd2fb1d76dc9b8733353105eeea3a3d4;hp=0a372560227027f4b79c6e0d1c4dde71a97f789d;hpb=a2a67cd520b9841114d69a87a423dabcb3b4368e;p=ghc-hetmet.git diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c index 0a37256..bfe1296 100644 --- a/rts/posix/OSMem.c +++ b/rts/posix/OSMem.c @@ -11,6 +11,7 @@ #include "Rts.h" +#include "RtsUtils.h" #include "sm/OSMem.h" #ifdef HAVE_UNISTD_H @@ -121,8 +122,8 @@ my_mmap (void *addr, lnat size) (errno == EINVAL && sizeof(void*)==4 && size >= 0xc0000000)) { // If we request more than 3Gig, then we get EINVAL // instead of ENOMEM (at least on Linux). - errorBelch("out of memory (requested %lu bytes)", size); - stg_exit(EXIT_FAILURE); + errorBelch("out of memory (requested %lu bytes)", size); + stg_exit(EXIT_FAILURE); } else { barf("getMBlock: mmap: %s", strerror(errno)); } @@ -148,10 +149,10 @@ gen_map_mblocks (lnat size) // unmap the slop bits around the chunk we allocated slop = (W_)ret & MBLOCK_MASK; - if (munmap(ret, MBLOCK_SIZE - slop) == -1) { + if (munmap((void*)ret, MBLOCK_SIZE - slop) == -1) { barf("gen_map_mblocks: munmap failed"); } - if (slop > 0 && munmap(ret+size-slop, slop) == -1) { + if (slop > 0 && munmap((void*)(ret+size-slop), slop) == -1) { barf("gen_map_mblocks: munmap failed"); } @@ -177,7 +178,7 @@ osGetMBlocks(nat n) { caddr_t ret; lnat size = MBLOCK_SIZE * (lnat)n; - + if (next_request == 0) { // use gen_map_mblocks the first time. ret = gen_map_mblocks(size); @@ -198,7 +199,6 @@ osGetMBlocks(nat n) ret = gen_map_mblocks(size); } } - // Next time, we'll try to allocate right after the block we just got. // ToDo: check that we haven't already grabbed the memory at next_request next_request = ret + size; @@ -206,9 +206,24 @@ osGetMBlocks(nat n) return ret; } +void osFreeMBlocks(char *addr, nat n) +{ + munmap(addr, n * MBLOCK_SIZE); +} + +void osReleaseFreeMemory(void) { + /* Nothing to do on POSIX */ +} + void osFreeAllMBlocks(void) { - /* XXX Do something here (bug #711) */ + void *mblock; + + for (mblock = getFirstMBlock(); + mblock != NULL; + mblock = getNextMBlock(mblock)) { + munmap(mblock, MBLOCK_SIZE); + } } lnat getPageSize (void)