Mercurial > sos > sos
changeset 154:0d0ce48aa55d
Heap storage keys are now unset when the program exits
author | Jonathan Pevarnek <pevarnj@gmail.com> |
---|---|
date | Fri, 04 Nov 2011 14:29:16 -0400 |
parents | b523bc9c9a74 |
children | 9ad854e6d994 |
files | src/os/heap.c |
diffstat | 1 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/os/heap.c Wed Nov 02 21:42:28 2011 -0400 +++ b/src/os/heap.c Fri Nov 04 14:29:16 2011 -0400 @@ -3,6 +3,8 @@ #include <os/storageKeys.h> #include <os/memLayout.h> +//TODO break if PageSize%BLOCKSIZE != 0 + static Header base; static Header *allocp = NULL; @@ -35,7 +37,7 @@ *ammt = cur->size*PageSize - sizeof(Header); allocp = prev; intptr_t ptr; - for(ptr = (intptr_t)cur; (ptr - (intptr_t)cur)/BLOCKSIZE < nUnits; ptr += PageSize) { + for(ptr = (intptr_t)cur; (ptr - (intptr_t)cur) < nUnits*PageSize; ptr += BLOCKSIZE) { setStorageKey(ptr, PROGSK, 1); //TODO only do this if being called by the program (how?) } return (void*)(cur + 1); @@ -48,6 +50,10 @@ void freeHeap(void *ptr) { Header *toFree = (Header *)ptr - 1; + intptr_t skLoc; + for(skLoc = (intptr_t)toFree; (skLoc - (intptr_t)toFree) < toFree->size*PageSize; skLoc += BLOCKSIZE) { + setStorageKey(skLoc, 0, 1); + } Header *scan; for(scan = allocp; !(toFree > scan && toFree < scan->next); scan = scan->next) if(scan->next <= scan && (toFree > scan || toFree < scan->next)) break;