void osFreeMBlocks(void *addr, uint32_t n) { W_ nBytes = (W_)n * MBLOCK_SIZE; insertFree(addr, nBytes); decommitBlocks(addr, nBytes); }
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 * osGetMBlocks(uint32_t n) { void* ret; ret = findFreeBlocks(n); if(ret==0) { alloc_rec* alloc; alloc = allocNew(n); /* We already belch in allocNew if it fails */ if (alloc == 0) { stg_exit(EXIT_FAILURE); } else { insertFree(alloc->base, alloc->size); ret = findFreeBlocks(n); } } if(ret!=0) { /* (In)sanity tests */ if (((W_)ret & MBLOCK_MASK) != 0) { barf("getMBlocks: misaligned block returned"); } commitBlocks(ret, (W_)MBLOCK_SIZE*n); } return ret; }
void osFreeMBlocks(char *addr, nat n) { W_ nBytes = (W_)n * MBLOCK_SIZE; insertFree(addr, nBytes); decommitBlocks(addr, nBytes); }