PUBLIC int allocate_new_mem(rmp, old_mem_clicks)
register struct mproc* rmp;
phys_clicks old_mem_clicks;
register struct mem_map* mem_sp, * mem_dp;
phys_clicks new_mem_clicks, new_data_base, old_data_base, old_stack_base,
phys_bytes new_data_addr, old_data_addr, new_stack_addr, old_stack_addr;
phys_bytes databytes, stackbytes;
mem_dp = &rmp->mp_seg[D];
mem_sp = &rmp->mp_seg[S];
new_mem_clicks = old_mem_clicks * 2;
new_data_base = alloc_mem(new_mem_clicks);
if (new_data_base == NO_MEM)
old_data_base = mem_dp->mem_phys, old_stack_base = mem_sp->mem_phys;
new_stack_base = new_data_base + new_mem_clicks - mem_sp->mem_len;
new_data_addr = (phys_bytes)(new_data_base << CLICK_SHIFT);
old_data_addr = (phys_bytes)(old_data_base << CLICK_SHIFT);
new_stack_addr = (phys_bytes)(new_stack_base << CLICK_SHIFT);
old_stack_addr = (phys_bytes)(old_stack_base << CLICK_SHIFT);
databytes = (phys_bytes)(mem_dp->mem_len << CLICK_SHIFT);
stackbytes = (phys_bytes)(mem_sp->mem_len << CLICK_SHIFT);
if (sys_abscopy(old_data_addr, new_data_addr, databytes) < 0 ||
sys_abscopy(old_stack_addr, new_stack_addr, stackbytes) < 0)
panic(__FILE__, "do_fork can't copy", -1);
rmp->mp_seg[D].mem_phys = new_data_base;
rmp->mp_seg[S].mem_phys = new_stack_base;
rmp->mp_seg[S].mem_vir = mem_dp->mem_vir + new_mem_clicks - mem_sp -
free_mem(old_data_base, old_mem_clicks);