Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Aug 2007 02:01:38 GMT
From:      Jesper Brix Rosenkilde <jbr@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 125372 for review
Message-ID:  <200708200201.l7K21c3v034586@repoman.freebsd.org>

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

Change 125372 by jbr@jbr_bob on 2007/08/20 02:01:34

	backup

Affected files ...

.. //depot/projects/soc2007/jbr-syscall/src/sys/kern/kern_exec.c#17 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/kern/kern_fork.c#2 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_glue.c#3 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.c#11 edit
.. //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.h#7 edit
.. //depot/projects/soc2007/jbr-syscall/tests/fork.c#2 edit

Differences ...

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

@@ -445,8 +445,7 @@
 		goto exec_fail_dealloc;
 	}
 
-	if (exec_map_sysshm(imgp))
-	    goto exec_fail_dealloc;
+	exec_map_sysshm(imgp);
 
 	/*
 	 * Special interpreter operation, cleanup and loop up to try to
@@ -909,18 +908,21 @@
 exec_map_sysshm(imgp)
      struct image_params *imgp;
 {
-	int error;
+	int error = 0;
 	struct proc *p = imgp->proc; 
-	vm_map_t map = &imgp->proc->p_vmspace->vm_map;
-	vm_offset_t *addr = &imgp->proc->p_usrsysshm;
+	//vm_offset_t *addr = &imgp->proc->p_usrsysshm;
 	struct sysshm outsysshm;
 
-	error = vm_map_sysshm(map, addr, 42);
-
+	//if (addr) {
+		//vm_unmap_sysshm(p);
+		error = vm_map_sysshm(p);
+	//}
+	
+	PROC_LOCK(p);
 	outsysshm.pid = p->p_pid;
-	strncpy(outsysshm.progtitle, p->p_comm, MAXCOMLEN);
-	strncpy(outsysshm.proctitle, "\0", 1);
-	copyout((caddr_t) &outsysshm, (caddr_t) *addr, sizeof(struct sysshm)); 
+	copyout(&outsysshm, (vm_offset_t *)  p->p_usrsysshm, 
+			sizeof(struct sysshm));
+	PROC_UNLOCK(p);
 
 	return(error);
 }

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

@@ -96,6 +96,18 @@
 		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);
 }
 
@@ -217,7 +229,7 @@
 			}
 			PROC_UNLOCK(p1);
 		}
-
+		
 		vm_forkproc(td, NULL, NULL, flags);
 
 		/*
@@ -405,6 +417,7 @@
 	td2 = FIRST_THREAD_IN_PROC(newproc);
 	p2->p_state = PRS_NEW;		/* protect against others */
 	p2->p_pid = trypid;
+
 	/*
 	 * Allow the scheduler to initialize the child.
 	 */
@@ -735,6 +748,7 @@
 	 * Return child proc pointer to parent.
 	 */
 	*procp = p2;
+
 	return (0);
 fail:
 	sx_sunlock(&proctree_lock);

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

@@ -511,7 +511,6 @@
 	int flags;
 {
 	struct proc *p1 = td->td_proc;
-	struct sysshm sysshm;
 
 	if ((flags & RFPROC) == 0) {
 		/*
@@ -543,16 +542,9 @@
 			shmfork(p1, p2);
 	}
 
-
-	p2->p_usrsysshm = p1->p_usrsysshm - 
-			(vm_offset_t) p1->p_vmspace->vm_daddr +
-			(vm_offset_t) p2->p_vmspace->vm_daddr;
+	p2->p_usrsysshm = (vm_offset_t) p1->p_vmspace->vm_taddr - 
+		p1->p_usrsysshm + (vm_offset_t) p2->p_vmspace->vm_taddr;
 
-	copyin((caddr_t) p1->p_usrsysshm, (caddr_t)  &sysshm, 
-			sizeof(struct sysshm));
-	sysshm.pid = p2->p_pid;
-	copyout((caddr_t) &sysshm, (caddr_t) p2->p_usrsysshm, 
-			sizeof(struct sysshm));
 	/*
 	 * cpu_fork will copy and update the pcb, set up the kernel stack,
 	 * and make the child ready to run.

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

@@ -2988,21 +2988,64 @@
  * process.
  */
 int
-vm_map_sysshm(vm_map_t map, vm_offset_t *usr_addr, vm_size_t size)
+vm_map_sysshm(struct proc *p)
 {
-	size = round_page(size);
+	vm_offset_t *addr = &p->p_usrsysshm;
+	vm_map_t map = &p->p_vmspace->vm_map;
+	size_t size = round_page(sizeof(struct sysshm));
 
-	PROC_LOCK(curthread->td_proc);
-
-	*usr_addr = round_page((vm_offset_t)
-	    curthread->td_proc->p_vmspace->vm_daddr) +
-	    lim_cur(curthread->td_proc, RLIMIT_DATA);
-	PROC_UNLOCK(curthread->td_proc);
+	PROC_LOCK(p);
+	*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, *usr_addr, usr_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)
+			!= KERN_SUCCESS)
+		panic("vm_map_sysshm: cannot wire page.");
+
+	vm_map_t *tmap = &map;
+	vm_map_entry_t entry;
+	vm_object_t object;
+	vm_pindex_t pindex;
+	vm_prot_t prot;
+	boolean_t wired;
+	vm_page_t page;
+
+	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);
+	vm_page_lock_queues();
+	vm_page_wire(page);
+	vm_page_unlock_queues();
+	VM_OBJECT_UNLOCK(object);
+	vm_map_lookup_done(*tmap, entry);
+
+	return (0);
+}
+
+/*
+ * Deallocate a page which holds data shared between the kernel and user
+ * process.
+ */
+int
+vm_unmap_sysshm(struct proc *p)
+{
+	size_t size = round_page(sizeof(struct sysshm));
+	vm_offset_t *addr = &p->p_usrsysshm;
+	vm_map_t map = &p->p_vmspace->vm_map;
+
+	if (vm_map_remove(map, *addr, *addr + size))
+		panic("vm_map_sysshm: cannot deallocated sysshm.");
+
+	addr = NULL;
+
 	return (0);
 }
 

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

@@ -354,7 +354,8 @@
 void vm_map_simplify_entry (vm_map_t, vm_map_entry_t);
 void vm_init2 (void);
 int vm_map_stack (vm_map_t, vm_offset_t, vm_size_t, vm_prot_t, vm_prot_t, int);
-int vm_map_sysshm(vm_map_t, vm_offset_t *, vm_size_t);
+int vm_map_sysshm(struct proc *);
+int vm_unmap_sysshm(struct proc *);
 int vm_map_growstack (struct proc *p, vm_offset_t addr);
 int vm_map_unwire(vm_map_t map, vm_offset_t start, vm_offset_t end,
     int flags);

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

@@ -1,12 +1,22 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include "mlibc/mlibc.h"
 
 int main(void)
 {
-	fork();
-	printf("pid: %d\n", getpid2());
+	pid_t child;
+
+	printf("Parent -- getpid(): %d\tgetpid2(): %d\n", getpid(), getpid2());
+	if(!(child = fork())) {
+		printf("Child -- getpid(): %d\tgetpid2(): %d\n", 
+				getpid(), getpid2());
+	} else {
+		waitpid(child, NULL, 0);
+		printf("Parent-- getpid(): %d\tgetpid2(): %d\n", getpid(),
+				getpid2());
+	}
 
 	return(0);
 }



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