Subject: Re: LWP'ifying compat_irix
To: Emmanuel Dreyfus <manu@netbsd.org>
From: Rafal Boni <rafal@attbi.com>
List: port-sgimips
Date: 01/22/2003 08:25:33
In message <1fp6iqa.1920sgm175hlktM@[10.0.12.137]>, you write: 

-> > Here's my 90% attempt at LPW'ifying compat_irix; it's not complete because
-> > I wasn't sure what to do with the share group/prctl stuff.  I'll look at
-> > that a bit more and will send anything I have on, but help would be very
-> > much appreciated.
-> 
-> I'm glad you looked after it. I was planning to find some time to work
-> on it, it's a good surprise to find it already started :o)
-> 
-> Go ahead and commit every fix you can, I'll do the testing. For the
-> share group stuff, we have to make a decision: do we keep it the way
-> it's working now, or do we use our new lwp for processes sharing memory
-> in a share group?

I've commited all but irix_prctl.c as I'm sure what I did there was not
correct.  

It seems to me that we would want to move to the model of using LWP's for
IRIX share groups as that would simplify a lot of the code (for example,
all the vm-syncing code, we already have a per-process LWP list, maybe
even LWP state handling to do the block/unblock goo).  On the other hand,
if we ever expect (and I don't know enough about the IRIX sproc() inter-
face to know if this is a reasonable expectation or not) to *not* share
vmspace, fd tables, doing this via LWP's will probably make that harder.  

Thoughts?
--rafal

BTW, here's my "at least make it compile" mangling of irix_prctl.c:

--- irix_prctl.c	Wed Jan 22 07:58:48 2003
+++ irix_prctl.c.rkb	Tue Jan 21 23:49:10 2003
@@ -68,18 +68,18 @@
 #include <compat/irix/irix_syscallargs.h>
 
 struct irix_sproc_child_args {
-	struct proc **isc_proc; 
+	struct lwp **isc_lwp; 
 	void *isc_entry;
 	void *isc_arg;
 	size_t isc_len;
 	int isc_inh;
-	struct proc *isc_parent;
+	struct lwp *isc_parent_lwp;
 	struct irix_share_group *isc_share_group;
 	int isc_child_done;
 }; 
 static void irix_sproc_child __P((struct irix_sproc_child_args *));
 static int irix_sproc __P((void *, unsigned int, void *, caddr_t, size_t, 
-    pid_t, struct proc *, register_t *));
+    pid_t, struct lwp *, register_t *));
 static struct irix_shared_regions_rec *irix_isrr_create __P((vaddr_t, 
     vsize_t, int));
 #ifdef DEBUG_IRIX
@@ -88,8 +88,8 @@
 static void irix_isrr_cleanup __P((struct proc *));
 
 int
-irix_sys_prctl(p, v, retval)
-	struct proc *p;
+irix_sys_prctl(l, v, retval)
+	struct lwp *l;
 	void *v;
 	register_t *retval;
 {
@@ -97,6 +97,7 @@
 		syscallarg(int) option;
 		syscallarg(void *) arg1;
 	} */ *uap = v;
+	struct proc *p = l->l_proc;
 	int option = SCARG(uap, option);
 
 #ifdef DEBUG_IRIX
@@ -207,8 +208,8 @@
 
 
 int
-irix_sys_pidsprocsp(p, v, retval)
-	struct proc *p;
+irix_sys_pidsprocsp(l, v, retval)
+	struct lwp *l;
 	void *v;
 	register_t *retval;
 {
@@ -225,12 +226,12 @@
 	printf("Warning: unsupported pid argument to IRIX sproc\n");
 
 	return irix_sproc(SCARG(uap, entry), SCARG(uap, inh), SCARG(uap, arg),
-	    SCARG(uap, sp), SCARG(uap, len), SCARG(uap, pid), p, retval);
+	    SCARG(uap, sp), SCARG(uap, len), SCARG(uap, pid), l, retval);
 }
 
 int
-irix_sys_sprocsp(p, v, retval)
-	struct proc *p;
+irix_sys_sprocsp(l, v, retval)
+	struct lwp *l;
 	void *v;
 	register_t *retval;
 {
@@ -243,12 +244,12 @@
 	} */ *uap = v;
 
 	return irix_sproc(SCARG(uap, entry), SCARG(uap, inh), SCARG(uap, arg),
-	    SCARG(uap, sp), SCARG(uap, len), 0, p, retval);
+	    SCARG(uap, sp), SCARG(uap, len), 0, l, retval);
 }
 
 int
-irix_sys_sproc(p, v, retval)
-	struct proc *p;
+irix_sys_sproc(l, v, retval)
+	struct lwp *l;
 	void *v;
 	register_t *retval;
 {
@@ -257,27 +258,30 @@
 		syscallarg(unsigned) inh;
 		syscallarg(void *) arg;
 	} */ *uap = v;
+	struct proc *p = l->l_proc;
 
 	return irix_sproc(SCARG(uap, entry), SCARG(uap, inh), SCARG(uap, arg),
-	    NULL, p->p_rlimit[RLIMIT_STACK].rlim_cur, 0, p, retval);
+	    NULL, p->p_rlimit[RLIMIT_STACK].rlim_cur, 0, l, retval);
 }
 
 
 static int 
-irix_sproc(entry, inh, arg, sp, len, pid, p, retval)
+irix_sproc(entry, inh, arg, sp, len, pid, l, retval)
 	void *entry;
 	unsigned int inh;
 	void *arg;
 	caddr_t sp;
 	size_t len;
 	pid_t pid;
-	struct proc *p;
+	struct lwp *l;
 	register_t *retval;
 {
+	struct proc *p = l->l_proc;
 	int bsd_flags = 0;
 	struct exec_vmcmd vmc;
 	int error;
 	struct proc *p2;
+	struct lwp *l2;
 	struct irix_sproc_child_args *isc;	
 	struct irix_emuldata *ied;
 	struct irix_emuldata *iedp;
@@ -376,12 +380,12 @@
 	 * This will be freed by the child.
 	 */
 	isc = malloc(sizeof(*isc), M_TEMP, M_WAITOK);
-	isc->isc_proc = &p2;
+	isc->isc_lwp = &l2;
 	isc->isc_entry = entry;
 	isc->isc_arg = arg;
 	isc->isc_len = len;
 	isc->isc_inh = inh;
-	isc->isc_parent = p;
+	isc->isc_parent_lwp = l;
 	isc->isc_share_group = isg;
 	isc->isc_child_done = 0;
 
@@ -389,7 +393,7 @@
 		ied->ied_shareaddr = 1;
 	}
 
-	if ((error = fork1(p, bsd_flags, SIGCHLD, (void *)sp, len, 
+	if ((error = fork1(l, bsd_flags, SIGCHLD, (void *)sp, len, 
 	    (void *)irix_sproc_child, (void *)isc, retval, &p2)) != 0)
 		return error;
 
@@ -412,11 +416,13 @@
 irix_sproc_child(isc)
 	struct irix_sproc_child_args *isc;
 {
-	struct proc *p2 = *isc->isc_proc;
+	struct lwp *l2 = *isc->isc_lwp;
+	struct proc *p2 = l2->l_proc;
 	int inh = isc->isc_inh;
-	struct proc *parent = isc->isc_parent;
-	struct frame *tf = (struct frame *)p2->p_md.md_regs;
-	struct frame *ptf = (struct frame *)parent->p_md.md_regs;
+	struct lwp *lparent = isc->isc_parent_lwp;
+	struct proc *parent = lparent->l_proc;
+	struct frame *tf = (struct frame *)l2->l_md.md_regs;
+	struct frame *ptf = (struct frame *)lparent->l_md.md_regs;
 	struct pcred *pc;
 	struct plimit *pl;
 	struct irix_emuldata *ied;
@@ -550,8 +556,8 @@
 }
 
 int
-irix_sys_procblk(p, v, retval)
-	struct proc *p;
+irix_sys_procblk(l, v, retval)
+	struct lwp *l;
 	void *v;
 	register_t *retval;
 {
@@ -560,6 +566,8 @@
 		syscallarg(pid_t) pid;
 		syscallarg(int) count;
 	} */ *uap = v;
+	struct proc *p = l->l_proc;
+
 	int cmd = SCARG(uap, cmd);
 	struct irix_emuldata *ied;
 	struct irix_emuldata *iedp;
@@ -567,6 +575,7 @@
 	struct proc *target;
 	struct pcred *pc;
 	int oldcount;
+	struct lwp *ied_lwp;
 	int error, last_error;
 	struct irix_sys_procblk_args cup;
 
@@ -619,14 +628,15 @@
 		 */
 		if ((isg = ied->ied_share_group) == NULL) {
 			SCARG(&cup, pid) = SCARG(uap, pid);
-			return irix_sys_procblk(p, &cup, retval);
+			return irix_sys_procblk(l, &cup, retval);
 		}
 
 		(void)lockmgr(&isg->isg_lock, LK_SHARED, NULL);
 		LIST_FOREACH(iedp, &isg->isg_head, ied_sglist) {
 			/* Recall procblk for this process */
 			SCARG(&cup, pid) = iedp->ied_p->p_pid;
-			error = irix_sys_procblk(iedp->ied_p, &cup, retval);
+			ied_lwp = proc_representative_lwp(iedp->ied_p);
+			error = irix_sys_procblk(ied_lwp, &cup, retval);
 			if (error != 0) 
 				last_error = error;
 		}
----
Rafal Boni                                                     rafal@attbi.com
  We are all worms.  But I do believe I am a glowworm.  -- Winston Churchill