// // Z_Init // void (Z_Init)(__string file, int line) { register size_t size; // Allocate the memory // davidph 06/17/12: For DS, memory is a static allocation. zonebase = (memblock_t __near *)heap; zonebase_size = HEAPSIZE; // Align on cache boundary // davidph 08/03/12 FIXME: This causes invalid codegen. //zone = (memblock_t *)(((uintptr_t)zonebase + (CACHE_ALIGN - 1)) & ~(CACHE_ALIGN - 1)); zone = zonebase; size = zonebase_size - ((char __near *)zone - (char __near *)zonebase); rover = zone; // Rover points to base of zone mem zone->next = zone->prev = zone; // Single node zone->size = size - HEADER_SIZE; // All memory in one block zone->tag = PU_FREE; // A free block #ifdef ZONEIDCHECK zone->id = 0; #endif INSTRUMENT(free_memory = zone->size); INSTRUMENT(inactive_memory = zonebase_size - zone->size); INSTRUMENT(active_memory = purgable_memory = 0); Z_OpenLogFile(); Z_LogPrintf("Initialized zone heap with size of %u bytes (zonebase = %p)\n", zonebase_size, (void *)zonebase); }
static void Z_LogPuts(const char *msg) { #ifdef ZONEFILE if(!zonelog) Z_OpenLogFile(); if(zonelog) fputs(msg, zonelog); #endif }
void Z_Init(void) { dmemset(allocated_blocks, 0, sizeof(allocated_blocks)); #ifdef ZONEFILE atexit(Z_CloseLogFile); // exit handler Z_OpenLogFile(); Z_LogPrintf("* Z_Init\n"); #endif }
static void Z_LogPrintf(const char *msg, ...) { #ifdef ZONEFILE if(!zonelog) Z_OpenLogFile(); if(zonelog) { va_list ap; va_start(ap, msg); vfprintf(zonelog, msg, ap); va_end(ap); // flush after every message fflush(zonelog); } #endif }