Split do_brk in a stub and a function that does the real work, so that

the real work can be called from elsewhere too. Specifically, to allow PM
its own brk().
This commit is contained in:
Ben Gras 2006-06-30 14:35:38 +00:00
parent 0323892f71
commit b5179d7025
2 changed files with 19 additions and 7 deletions

View file

@ -28,31 +28,42 @@
*===========================================================================*/
PUBLIC int do_brk()
{
/* Entry point to brk(addr) system call. real_brk() does the real work,
* as that is called from elsewhere too.
*/
int r;
r = real_brk(mp, (vir_bytes) m_in.addr);
mp->mp_reply.reply_ptr = (r == OK ? m_in.addr : (char *) -1);
return r;
}
/*===========================================================================*
* do_brk *
*===========================================================================*/
PUBLIC int real_brk(struct mproc *rmp, vir_bytes v)
{
/* Perform the brk(addr) system call.
*
* The call is complicated by the fact that on some machines (e.g., 8088),
* the stack pointer can grow beyond the base of the stack segment without
* anybody noticing it.
* The parameter, 'addr' is the new virtual address in D space.
*
* This call can also be performed on PM itself from brk() in misc.c.
*/
register struct mproc *rmp;
int r;
vir_bytes v, new_sp;
vir_bytes new_sp;
vir_clicks new_clicks;
rmp = mp;
v = (vir_bytes) m_in.addr;
new_clicks = (vir_clicks) ( ((long) v + CLICK_SIZE - 1) >> CLICK_SHIFT);
if (new_clicks < rmp->mp_seg[D].mem_vir) {
rmp->mp_reply.reply_ptr = (char *) -1;
return(ENOMEM);
}
new_clicks -= rmp->mp_seg[D].mem_vir;
if ((r=get_stack_ptr(who_e, &new_sp)) != OK) /* ask kernel for sp value */
if ((r=get_stack_ptr(rmp->mp_endpoint, &new_sp)) != OK) /* get sp value */
panic(__FILE__,"couldn't get stack pointer", r);
r = adjust(rmp, new_clicks, new_sp);
rmp->mp_reply.reply_ptr = (r == OK ? m_in.addr : (char *) -1);
return(r); /* return new address or -1 */
}

View file

@ -26,6 +26,7 @@ _PROTOTYPE(int mem_holes_copy, (struct hole *, size_t *, u32_t *) );
_PROTOTYPE( int adjust, (struct mproc *rmp,
vir_clicks data_clicks, vir_bytes sp) );
_PROTOTYPE( int do_brk, (void) );
_PROTOTYPE( int real_brk, (struct mproc *pr, vir_bytes v) );
_PROTOTYPE( int size_ok, (int file_type, vir_clicks tc, vir_clicks dc,
vir_clicks sc, vir_clicks dvir, vir_clicks s_vir) );