Subject: Re: cpu_fork(), it bends my brain
To: Anders Magnusson <ragge@ludd.luth.se>
From: Jason R Thorpe <thorpej@zembu.com>
List: port-vax
Date: 05/25/2000 07:53:37
On Thu, May 25, 2000 at 01:18:19PM +0200, Anders Magnusson wrote:

 > This only shows that you don't have enough knowledge about real computers. :-)
 > You should get a VAX, Jason :-)

Hey!  Actually, I have *two* VAXes, but just don't have them set up
right now :-)

 > Ok, simple principle:
 > cpu_fork() is called to duplicate another process. Switching between
 > processes is done with two instructions; svpctx and ldpctx (compare with
 > the Alpha PAL call swpctx). The PCB is stored/loaded at the bottom of
 > the u. area. A fork is a result of a system call. With all this knowledge
 > a new PCB (for the new process) is created based on the information in
 > the trap frame from the parent's system call, so when swtch() is called
 > the next time the new process PCB is loaded that has the state the parent
 > process will have after the system call returns. Simple, eh? Was it 
 > understandable? More code description: (nyproc is the new process' PCB).

Yah, I understand the basic principle :-)  I was mostly just confused about
the VAX's details.  You have clarified them.  And I think I've even found
a bug! :-)

 >         nyproc->PC = tf->pc;	<- user space program counter after trap
 >         nyproc->PSL = tf->psl & ~PSL_C; <- PSL have privileges of process
 > 					   (kernel/user privileges)
 >         nyproc->R[0] = p1->p_pid; /* parent pid. (shouldn't be needed) */
 >         nyproc->R[1] = 1;	<- R0/R1 have return values

Right, ok, so this is effectively what child_return() does on most
platforms.  I'll reference the hp300's trap.c for simplicity.

The problem here is that the VAX is failing to do a few things upon
child return in a fork():

	- Not delivering any signals that may have been sent to
	  the process before it gets a chance to run.  (done in
	  userret()).

	- Missing the child's KTRACE point for fork return (done
	  in child_return()).

The VAX's return-to-userspace-from-trap should probably be made to
look more like the hp300's, if nothing else, to reduce the duplication
of code (VAX has 2 copies of what is effectively userret()), and to
get the KTRACE point.

 > I assume that you don't provide a PC if it's a normal fork :-)

Actually, I was thinking of just providing "child_return" as the
kernel trampoline function, since every port has one .. well, except
for VAX :-)  But I'm hoping you'll change that.  Or I could.  Now that
I understand what's going on there... :-)

-- 
        -- Jason R. Thorpe <thorpej@zembu.com>