X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FMBlock.c;h=85fe02da6e12a411b255e9194a8ce8e440f0a8b4;hb=9cef40bd4dd2536c7a370a1a9b78461c152805cc;hp=f317690d4c50640cbddec33e118430d5d7c9cc4f;hpb=a922de3d97e026290b3db7e82350dc881e3bb933;p=ghc-hetmet.git diff --git a/rts/MBlock.c b/rts/MBlock.c index f317690..85fe02d 100644 --- a/rts/MBlock.c +++ b/rts/MBlock.c @@ -337,20 +337,19 @@ allocNew(nat n) { if(rec->base==0) { stgFree((void*)rec); rec=0; - errorBelch( - "getMBlocks: VirtualAlloc MEM_RESERVE %d blocks failed with: %ld\n" - , n, GetLastError()); + sysErrorBelch( + "getMBlocks: VirtualAlloc MEM_RESERVE %d blocks failed", n); } else { - if(allocs==0) { - allocs=rec; - rec->next=0; - } else { - alloc_rec* it; - it=allocs; - for(; it->next!=0 && it->next->basebase; it=it->next) ; - rec->next=it->next; - it->next=rec; - } + alloc_rec temp; + temp.base=0; temp.size=0; temp.next=allocs; + + alloc_rec* it; + it=&temp; + for(; it->next!=0 && it->next->basebase; it=it->next) ; + rec->next=it->next; + it->next=rec; + + allocs=temp.next; debugTrace(DEBUG_gc, "allocated %d megablock(s) at 0x%x",n,(nat)rec->base); } return rec; @@ -409,7 +408,7 @@ findFreeBlocks(nat n) { if( (((unsigned long)it->base) & MBLOCK_MASK) == 0) { /* MBlock aligned */ ret = (void*)it->base; if(it->size==required_size) { - prev->next=0; + prev->next=it->next; stgFree(it); } else { it->base += required_size; @@ -443,15 +442,17 @@ static void commitBlocks(char* base, int size) { alloc_rec* it; it=allocs; - for( ; it!=0 && (it->base+it->size)next ) {} + for( ; it!=0 && (it->base+it->size)<=base; it=it->next ) {} for( ; it!=0 && size>0; it=it->next ) { int size_delta; void* temp; size_delta = it->size - (base-it->base); if(size_delta>size) size_delta=size; temp = VirtualAlloc(base, size_delta, MEM_COMMIT, PAGE_READWRITE); - if(temp==0) - debugBelch("getMBlocks: VirtualAlloc MEM_COMMIT failed: %ld", GetLastError()); + if(temp==0) { + sysErrorBelch("getMBlocks: VirtualAlloc MEM_COMMIT failed"); + stg_exit(EXIT_FAILURE); + } size-=size_delta; base+=size_delta; } @@ -465,10 +466,12 @@ getMBlocks(nat n) { alloc_rec* alloc; alloc = allocNew(n); /* We already belch in allocNew if it fails */ - if(alloc!=0) { + if (alloc == 0) { + stg_exit(EXIT_FAILURE); + } else { insertFree(alloc->base, alloc->size); ret = findFreeBlocks(n); - } + } } if(ret!=0) { @@ -511,7 +514,8 @@ freeAllMBlocks(void) it=allocs; for(; it!=0; ) { if(!VirtualFree((void*)it->base, 0, MEM_RELEASE)) { - debugBelch("freeAllMBlocks: VirtualFree MEM_RELEASE failed with %ld", GetLastError()); + sysErrorBelch("freeAllMBlocks: VirtualFree MEM_RELEASE failed"); + stg_exit(EXIT_FAILURE); } next = it->next; stgFree(it);