/* * AdjustMods - adjust the demand info offsets in all the modules * - allocate module index table * - allocate demand load link table */ dip_status AdjustMods( section_info *inf, unsigned long adjust ) { info_block *blk; unsigned count; unsigned mod_off; mod_table *tbl; mod_info *mod; unsigned long num_links; unsigned long first_link; unsigned long last_link; unsigned d; unsigned num; dword *lnk; dword **lnk_tbl; unsigned long off; dip_status ok; last_link = 0; first_link = ~0; num_links = 1; for( blk = inf->mod_info; blk != NULL; blk = blk->next ) { count = 0; for( mod_off = 0; mod_off < blk->size; mod_off += sizeof( mod_info ) + mod->name[0] ) { ++count; mod = (mod_info *)((byte *)blk->info + mod_off); } tbl = DCAlloc( sizeof(mod_table) + (count-1)*sizeof(mod_info *) ); if( tbl == NULL ) { DCStatus( DS_ERR|DS_NO_MEM ); return( DS_ERR|DS_NO_MEM ); } tbl->count = count; blk->link = tbl; count = 0; for( mod_off = 0; mod_off < blk->size; mod_off += sizeof( mod_info ) + mod->name[0] ) { tbl->mod_off[count++] = mod_off; mod = (mod_info *)((byte *)blk->info + mod_off); for( d = DMND_FIRST; d < DMND_NUM; ++d ) { if( inf->ctl->v2 ) { if( mod->di[d].u.size != 0 ) ++num_links; } else { if( mod->di[d].u.entries != 0 ) { num_links = mod->di[d].info_off; if( num_links < first_link ) { first_link = num_links; } num_links += mod->di[d].u.entries * sizeof(dword); if( num_links > last_link ) { last_link = num_links; } } } } } } if( !inf->ctl->v2 ) { off = first_link + adjust; if( DCSeek( inf->ctl->sym_file, off, DIG_ORG) != off ) { DCStatus( DS_ERR|DS_FSEEK_FAILED ); return( DS_ERR|DS_FSEEK_FAILED ); } num_links = (last_link - first_link) / sizeof( dword ) + 2; } ok = AllocLinkTable( inf, num_links, first_link ); if( ok != DS_OK ) return( ok ); num = 0; lnk_tbl = inf->dmnd_link; lnk = *lnk_tbl; for( ;; ) { if( num_links == 0 ) break; if( num >= MAX_LINK_ENTRIES ) { lnk = *++lnk_tbl; num = 0; } /* * shift over one bit so as to leave the lower bit * clear for testing if it is allocated or not */ lnk[num] = (lnk[num] + adjust) << 1; ++num; --num_links; } return( DS_OK ); }
/* * AdjustMods - adjust the demand info offsets in all the modules * - allocate module index table * - allocate demand load link table */ dip_status AdjustMods( section_info *inf, unsigned long adjust ) { info_block *blk; unsigned count; unsigned mod_off; mod_table *tbl; mod_info *mod; dword num_links; dword first_link; dword last_link; demand_kind dk; unsigned num; pointer_int *lnk; pointer_int **lnk_tbl; unsigned long off; dip_status ok; last_link = 0; first_link = (dword)-1L; num_links = 1; for( blk = inf->mod_info; blk != NULL; blk = blk->next ) { mod = (mod_info *)blk->info; count = 0; for( mod_off = 0; mod_off < blk->size; mod_off += MODINFO_SIZE( (byte *)mod + mod_off ) ) { ++count; } tbl = DCAlloc( sizeof( mod_table ) + ( count - 1 ) * sizeof( mod_info * ) ); if( tbl == NULL ) { DCStatus( DS_ERR|DS_NO_MEM ); return( DS_ERR|DS_NO_MEM ); } tbl->count = count; blk->link = tbl; count = 0; for( mod_off = 0; mod_off < blk->size; mod_off += MODINFO_SIZE( mod ) ) { tbl->mod_off[count++] = mod_off; mod = (mod_info *)((byte *)blk->info + mod_off); for( dk = 0; dk < MAX_DMND; ++dk ) { if( inf->ctl->v2 ) { if( mod->di[dk].u.size != 0 ) { ++num_links; } } else { if( mod->di[dk].u.entries != 0 ) { num_links = mod->di[dk].info_off; if( first_link > num_links ) { first_link = num_links; } num_links += mod->di[dk].u.entries * sizeof( pointer_int ); if( last_link < num_links ) { last_link = num_links; } } } } } } if( !inf->ctl->v2 ) { off = first_link + adjust; if( DCSeek( inf->ctl->sym_fid, off, DIG_ORG) != off ) { DCStatus( DS_ERR|DS_FSEEK_FAILED ); return( DS_ERR|DS_FSEEK_FAILED ); } num_links = (last_link - first_link) / sizeof( pointer_int ) + 2; } ok = AllocLinkTable( inf, num_links, first_link ); if( ok != DS_OK ) return( ok ); num = 0; lnk_tbl = inf->dmnd_link; lnk = *lnk_tbl; for( ; num_links-- > 0; ) { if( num >= MAX_LINK_ENTRIES ) { lnk = *++lnk_tbl; num = 0; } /* * shift over one bit so as to leave the lower bit * clear for testing if it is allocated or not */ lnk[num] = (lnk[num] + adjust) << 1; ++num; } return( DS_OK ); }