extern void DWRVMInit( void ) /***************************/ // Allocate space for the branch pointers. { PageTab = DWRALLOC( NumBranches * sizeof( page_entry * ) ); memset( PageTab, 0, NumBranches * sizeof( page_entry * ) ); PageTab[1] = DWRALLOC( sizeof( page_entry ) * MAX_LEAFS ); memset( PageTab[1], 0, sizeof( page_entry ) * MAX_LEAFS ); DontSwap = false; PageCount = 0; }
static virt_struct GetPage( dr_section sect ) /*******************************************/ { page_entry *entry; unsigned alloc_size; virt_struct vmem; if( NextLeaf >= MAX_LEAFS ) { DontSwap = true; NextLeaf = 0; CurrBranch++; if( CurrBranch >= NumBranches ) { GetMoreBranches(); } alloc_size = sizeof( page_entry ) * MAX_LEAFS; entry = DWRALLOC( alloc_size ); PageTab[ CurrBranch ] = entry; memset( entry, 0, alloc_size ); //set all flags false. DontSwap = false; } else { entry = &PageTab[ CurrBranch ][ NextLeaf ]; } entry->sect = sect; vmem.w.high = CurrBranch; vmem.w.low = NextLeaf << OFFSET_SHIFT; NextLeaf++; return( vmem ); }
void DWRStackCreate( // INITIALIZE A STACK dr_stack *stk, // -- stack to initialize uint start_size ) // -- initial size guess /*************************/ { stk->stack = DWRALLOC( start_size * sizeof( uint_32 ) ); stk->free = 0; stk->size = start_size; }
extern dr_search_context * DRDuplicateSearchContext( dr_search_context *cxt ) /***************************************************************************/ { int i; dr_search_context *newCtxt; newCtxt = DWRALLOC( sizeof( dr_search_context ) ); *newCtxt = *cxt; /* structure copy */ /* but allocate and copy own stack */ newCtxt->stack.stack = DWRALLOC( newCtxt->stack.size * sizeof( uint_32 ) ); for( i = 0; i < cxt->stack.free; i += 1 ) { newCtxt->stack.stack[i] = cxt->stack.stack[i]; } return( newCtxt ); }
void DWRStackCopy( // COPY A STACK FROM ANOTHER dr_stack *dest, // -- destination of copy const dr_stack *src ) // -- source of copy /************************/ { dest->free = src->free; dest->size = src->size; dest->stack = DWRALLOC( dest->size * sizeof( uint_32 ) ); memcpy( dest->stack, src->stack, dest->size * sizeof( uint_32 ) ); }
char *DWRVMCopyString( drmem_hdl *info ) /**************************************/ { size_t count; char *str; count = DWRVMStrLen( *info ); str = DWRALLOC( count + 1 ); DWRVMGetString( str, info ); return( str ); }
char *DWRVMCopyString( dr_handle *info ) /**************************************/ { size_t len; char *dst; dr_handle src; src = *info; len = strlen( src ) + 1; *info += len; dst = DWRALLOC( len ); return( memcpy( dst, src, len ) ); }
static void ScopePush( dr_scope_stack *stack, dr_handle entry ) /*************************************************************/ { if( stack->stack == NULL ) { stack->stack = DWRALLOC( SCOPE_GUESS * sizeof( dr_handle ) ); } if( stack->free >= stack->size ) { stack->size += SCOPE_GUESS; stack->stack = DWRREALLOC( stack->stack, stack->size * sizeof( dr_handle ) ); } stack->stack[stack->free] = entry; stack->free += 1; }
static void GetMoreBranches( void ) /*********************************/ // make a larger array to hold branch pointers in. { page_entry **branches; unsigned alloc_size; alloc_size = NumBranches * sizeof( page_entry * ); NumBranches = NumBranches * 2; // double the # of pointers. if( NumBranches > SEG_LIMIT ) { DWREXCEPT( DREXCEP_OUT_OF_VM ); } branches = DWRALLOC( alloc_size * 2 ); memcpy( branches, PageTab, alloc_size ); memset( (char *)branches + alloc_size, 0, alloc_size ); // null pointers DWRFREE( PageTab ); PageTab = branches; }
extern dr_handle DWRVMAlloc( unsigned long len, int sect ) /********************************************************/ { alloc_struct *nChunk; if( len == 0 ) { return( 0 ); } nChunk = (alloc_struct *)DWRALLOC( len - 1 + sizeof( alloc_struct ) ); if( nChunk == NULL ) { DWREXCEPT( DREXCEP_OUT_OF_MMEM ); return( 0 ); } nChunk->next = AllocHead; AllocHead = nChunk; DWRSEEK( DWRCurrNode->file, sect, 0 ); DWRREAD( DWRCurrNode->file, sect, nChunk->data, len ); return( (dr_handle)nChunk->data ); }
static void ReadPage( page_entry * node, virt_struct vm ) /*******************************************************/ /* read a page in from the dwarf file */ { unsigned long size; drmem_hdl base; unsigned long offset; dr_section sect; sect = node->sect; size = DWRCurrNode->sections[sect].size; base = DWRCurrNode->sections[sect].base; offset = (vm.l - base) & ~((unsigned long)OFFSET_MASK); size -= offset; if( size > MAX_NODE_SIZE ) { size = MAX_NODE_SIZE; } node->mem = DWRALLOC( size ); node->inmem = true; ++PageCount; DWRSEEK( DWRCurrNode->file, sect, offset ); DWRREAD( DWRCurrNode->file, sect, node->mem, size ); }
extern void DWRInitFileTable( file_table *tab ) /*********************************************/ { tab->len = 0; tab->tab = DWRALLOC( VBL_ARRAY_DELTA * sizeof( filetab_entry ) ); }