Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Aug 2007 21:30:26 GMT
From:      Jesper Brix Rosenkilde <jbr@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 125453 for review
Message-ID:  <200708202130.l7KLUQiJ000418@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=125453

Change 125453 by jbr@jbr_bob on 2007/08/20 21:29:29

	fork and exec, sort of working

Affected files ...

.. //depot/projects/soc2007/jbr-syscall/src/sys/kern/kern_exec.c#18 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/kern/kern_fork.c#5 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/sys/proc.h#6 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/sys/types.h#3 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_glue.c#4 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.c#12 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.h#8 edit
.. //depot/projects/soc2007/jbr-syscall/tests/fork.c#3 edit
.. //depot/projects/soc2007/jbr-syscall/tests/mlibc/mlibc.c#2 edit

Differences ...

==== //depot/projects/soc2007/jbr-syscall/src/sys/kern/kern_exec.c#18 (text+ko) ====

@@ -910,17 +910,13 @@
 {
 	int error = 0;
 	struct proc *p = imgp->proc; 
-	//vm_offset_t *addr = &imgp->proc->p_usrsysshm;
 	struct sysshm outsysshm;
 
-	//if (addr) {
-		//vm_unmap_sysshm(p);
-		error = vm_map_sysshm(p);
-	//}
-	
+	error = vm_map_sysshm(p);
+
 	PROC_LOCK(p);
 	outsysshm.pid = p->p_pid;
-	copyout(&outsysshm, (vm_offset_t *)  p->p_usrsysshm, 
+	copyout(&outsysshm, (vm_offset_t *) p->p_usrsysshm, 
 			sizeof(struct sysshm));
 	PROC_UNLOCK(p);
 

==== //depot/projects/soc2007/jbr-syscall/src/sys/kern/kern_fork.c#5 (text+ko) ====

@@ -90,24 +90,12 @@
 {
 	int error;
 	struct proc *p2;
+	error = fork1(td, RFFDG | RFPROC, 0, &p2);
 
-	error = fork1(td, RFFDG | RFPROC, 0, &p2);
 	if (error == 0) {
 		td->td_retval[0] = p2->p_pid;
 		td->td_retval[1] = 0;
 	}
-
-	vm_map_sysshm(p2);
-
-	struct sysshm outsysshm;
-
-	PROC_LOCK(p2);
-	outsysshm.pid = p2->p_pid;
-	printf("%d\n", outsysshm.pid);
-	copyout(&outsysshm, (vm_offset_t *)  p2->p_usrsysshm, 
-			sizeof(struct sysshm));
-	PROC_UNLOCK(p2);
-
 	return (error);
 }
 
@@ -742,7 +730,6 @@
 		thread_single_end();
 		PROC_UNLOCK(p1);
 	}
-
 	/*
 	 * Return child proc pointer to parent.
 	 */

==== //depot/projects/soc2007/jbr-syscall/src/sys/sys/proc.h#6 (text+ko) ====

@@ -824,6 +824,7 @@
 void	faultin(struct proc *p);
 void	fixjobc(struct proc *p, struct pgrp *pgrp, int entering);
 int	fork1(struct thread *, int, int, struct proc **);
+void	fork_map_sysshm(struct proc *, struct proc *, int);	
 void	fork_exit(void (*)(void *, struct trapframe *), void *,
 	    struct trapframe *);
 void	fork_return(struct thread *, struct trapframe *);

==== //depot/projects/soc2007/jbr-syscall/src/sys/sys/types.h#3 (text+ko) ====


==== //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_glue.c#4 (text+ko) ====

@@ -523,6 +523,7 @@
 				vmspace_unshare(p1);
 			}
 		}
+		fork_map_sysshm(p1, p2, flags);
 		cpu_fork(td, p2, td2, flags);
 		return;
 	}
@@ -541,17 +542,31 @@
 		if (p1->p_vmspace->vm_shm)
 			shmfork(p1, p2);
 	}
-
-	p2->p_usrsysshm = (vm_offset_t) p1->p_vmspace->vm_taddr - 
-		p1->p_usrsysshm + (vm_offset_t) p2->p_vmspace->vm_taddr;
-
 	/*
 	 * cpu_fork will copy and update the pcb, set up the kernel stack,
 	 * and make the child ready to run.
 	 */
+	fork_map_sysshm(p1, p2, flags);
 	cpu_fork(td, p2, td2, flags);
 }
 
+void 
+fork_map_sysshm(struct proc *old, struct proc *new, int flags)
+{
+	struct sysshm outsysshm;
+
+	new->p_usrsysshm = (vm_offset_t) old->p_vmspace->vm_taddr -
+		old->p_usrsysshm + (vm_offset_t) new->p_vmspace->vm_taddr;
+
+	vm_map_sysshm(new);
+
+	PROC_LOCK(new);
+	outsysshm.pid = new->p_pid;
+	PROC_UNLOCK(new);
+	copyout(&outsysshm, (vm_offset_t *)  new->p_usrsysshm, 
+			sizeof(struct sysshm));
+}
+
 /*
  * Called after process has been wait(2)'ed apon and is being reaped.
  * The idea is to reclaim resources that we could not reclaim while

==== //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.c#12 (text+ko) ====

@@ -2990,24 +2990,24 @@
 int
 vm_map_sysshm(struct proc *p)
 {
-	vm_offset_t *addr = &p->p_usrsysshm;
+	vm_offset_t addr;
 	vm_map_t map = &p->p_vmspace->vm_map;
 	size_t size = round_page(sizeof(struct sysshm));
 
 	PROC_LOCK(p);
-	*addr = round_page((vm_offset_t) p->p_vmspace->vm_daddr) +
+	addr = round_page((vm_offset_t) p->p_vmspace->vm_daddr) +
 		lim_cur(p, RLIMIT_DATA);
 	PROC_UNLOCK(p);
 	
-	if (vm_map_find(map, NULL, *addr, addr, size, TRUE, VM_PROT_RW,
+	if (vm_map_find(map, NULL, addr, &addr, size, TRUE, VM_PROT_RW,
 				VM_PROT_RW, 0))
 		panic("vm_map_sysshm: cannot allocated sysshm.");
 
-	if (vm_map_wire(map, *addr, *addr + size, VM_MAP_WIRE_USER)
+	if (vm_map_wire(map, addr, addr + size, VM_MAP_WIRE_USER)
 			!= KERN_SUCCESS)
 		panic("vm_map_sysshm: cannot wire page.");
 
-	vm_map_t *tmap = &map;
+	vm_map_t tmap = map;
 	vm_map_entry_t entry;
 	vm_object_t object;
 	vm_pindex_t pindex;
@@ -3015,19 +3015,22 @@
 	boolean_t wired;
 	vm_page_t page;
 
-	if (vm_map_lookup(tmap, *addr, VM_PROT_READ|VM_PROT_WRITE, &entry,
+	if (vm_map_lookup(&tmap, addr, VM_PROT_READ|VM_PROT_WRITE, &entry,
 			&object, &pindex, &prot, &wired))
 		panic("vm_map_sysshm: cannot lookup vm_object.");
 
 	VM_OBJECT_LOCK(object);	
-	page = vm_page_lookup(object, pindex);
+	if(!(page = vm_page_lookup(object, pindex)))
+		panic("vm_map_sysshm: cannot wire page.");
 	vm_page_lock_queues();
 	vm_page_wire(page);
 	vm_page_unlock_queues();
 	VM_OBJECT_UNLOCK(object);
-	vm_map_lookup_done(*tmap, entry);
+	vm_map_lookup_done(tmap, entry);
+
+	p->p_usrsysshm = addr;
 
-	return (0);
+	return (addr);
 }
 
 /*

==== //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.h#8 (text+ko) ====


==== //depot/projects/soc2007/jbr-syscall/tests/fork.c#3 (text+ko) ====


==== //depot/projects/soc2007/jbr-syscall/tests/mlibc/mlibc.c#2 (text+ko) ====

@@ -1,4 +1,5 @@
 #include "mlibc.h"
+#include <stdio.h>
 
 struct sysshm * sysshm = NULL;
 
@@ -11,9 +12,11 @@
 	sysctlbyname("kern.usrsysshm", &addr, &size, NULL, 0);
 
 	sysshm = (struct sysshm * ) addr;
+	printf("%d\n", addr);
 }
 
 pid_t getpid2(void)
 {
+	__mlibc_init();
 	return(sysshm->pid);	
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708202130.l7KLUQiJ000418>