Subject: Re: fork1 and new stack
To: Emmanuel Dreyfus <manu@netbsd.org>
From: Andrey Petrov <petrov@netbsd.org>
List: tech-kern
Date: 04/25/2002 23:11:58
On Fri, Apr 26, 2002 at 07:30:28AM +0200, Emmanuel Dreyfus wrote:
> > Uh, did you by any chance forget to allocate VM in that range?
>
> Here is the code. Is there something wrong in VM allocation?
>
> bsd_flags = FORK_SHAREVM;
> tf = (struct frame *)p->p_md.md_regs;
>
> child_stack_addr = (u_long)(tf->f_regs[SP] - IRIX_SPROC_STACK_OFFSET);
> child_stack_size = (u_long)p->p_vmspace->vm_minsaddr
> - (u_long)p->p_vmspace->vm_maxsaddr;
Aren't they reversed?
>
> error = fork1(p, bsd_flags, SIGCHLD, (void *)child_stack_addr,
> child_stack_size, NULL, NULL, retval, &p2);
> if (error)
> return error;
>
> tf = (struct frame *)p2->p_md.md_regs;
>
> tf->f_regs[PC] = (unsigned long)SCARG(uap, entry);
>
> tf->f_regs[A0] = (unsigned long)SCARG(uap, arg);
> tf->f_regs[A1] = tf->f_regs[S3]; /* XXX ? */
>
> bzero(&vmc, sizeof(vmc));
> vmc.ev_addr = trunc_page(child_stack_addr - child_stack_size);
> vmc.ev_len = round_page(child_stack_size);
> vmc.ev_prot = UVM_PROT_RWX;
> vmc.ev_flags = UVM_FLAG_COPYONW|UVM_FLAG_FIXED|UVM_FLAG_OVERLAY;
> vmc.ev_proc = vmcmd_map_zero;
> error = (*vmc.ev_proc)(p, &vmc);
>
> retval[0] = (register_t)p2->p_pid;
> retval[1] = 0;
>
> return error;
>
> --
> Emmanuel Dreyfus.
> "Le 80x86 n'est pas si complexe - il n'a simplement pas de sens"
> (Mike Johnson, responsable de la conception x86 chez AMD)
> manu@netbsd.org