X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fposix%2FOSMem.c;h=5d46e68d23004e7603fa815a6d02be8045e7722a;hb=b8766c9aa00be4bfb0dd5ba7236e43027244dcdc;hp=bdae2739f1191d9856bdeb79aa9b68295094b7a6;hpb=eb90092dad2a0b614d0aba5ed56d7d4eaf14b2ea;p=ghc-hetmet.git diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c index bdae273..5d46e68 100644 --- a/rts/posix/OSMem.c +++ b/rts/posix/OSMem.c @@ -6,12 +6,13 @@ * * ---------------------------------------------------------------------------*/ -/* This is non-posix compliant. */ -/* #include "PosixSource.h" */ +// This is non-posix compliant. +// #include "PosixSource.h" #include "Rts.h" -#include "OSMem.h" -#include "RtsFlags.h" + +#include "RtsUtils.h" +#include "sm/OSMem.h" #ifdef HAVE_UNISTD_H #include @@ -36,7 +37,16 @@ #include #endif +/* keep track of maps returned by my_mmap */ +typedef struct _map_rec { + char* base; /* base addr */ + int size; /* map size */ + struct _map_rec* next; /* next pointer */ +} map_rec; + + static caddr_t next_request = 0; +static map_rec* mmap_rec = NULL; void osMemInit(void) { @@ -138,7 +148,7 @@ static void * gen_map_mblocks (lnat size) { int slop; - void *ret; + StgWord8 *ret; // Try to map a larger block, and take the aligned portion from // it (unmap the rest). @@ -177,7 +187,8 @@ osGetMBlocks(nat n) { caddr_t ret; lnat size = MBLOCK_SIZE * (lnat)n; - + map_rec* rec; + if (next_request == 0) { // use gen_map_mblocks the first time. ret = gen_map_mblocks(size); @@ -198,7 +209,11 @@ osGetMBlocks(nat n) ret = gen_map_mblocks(size); } } - + rec = (map_rec*)stgMallocBytes(sizeof(map_rec),"OSMem: osGetMBlocks"); + rec->size = size; + rec->base = ret; + rec->next = mmap_rec; + mmap_rec = rec; // 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; @@ -208,7 +223,17 @@ osGetMBlocks(nat n) void osFreeAllMBlocks(void) { - /* XXX Do something here (bug #711) */ + map_rec* tmp = mmap_rec; + map_rec* next = NULL; + + for(; tmp!=NULL;) { + if(munmap(tmp->base,tmp->size)) + barf("osFreeAllMBlocks: munmap failed!"); + + next = tmp->next; + stgFree(tmp); + tmp = next; + } } lnat getPageSize (void) @@ -237,6 +262,6 @@ void setExecutable (void *p, lnat len, rtsBool exec) StgWord size = startOfLastPage - startOfFirstPage + pageSize; if (mprotect((void*)startOfFirstPage, (size_t)size, (exec ? PROT_EXEC : 0) | PROT_READ | PROT_WRITE) != 0) { - barf("makeExecutable: failed to protect 0x%p\n", p); + barf("setExecutable: failed to protect 0x%p\n", p); } }