PERFORCE change 99963 for review

John Baldwin jhb at FreeBSD.org
Sun Jun 25 02:29:08 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=99963

Change 99963 by jhb at jhb_mutex on 2006/06/25 02:28:11

	Sync svr4_sys_break() with obreak() some and mark MPSAFE:
	- Just read the process limits once up front and cache them.
	- Use vm_map_max() rather than VM_MAXUSER_ADDRESS.
	- Add vm_map locking.

Affected files ...

.. //depot/projects/smpng/sys/compat/svr4/svr4_misc.c#45 edit
.. //depot/projects/smpng/sys/compat/svr4/syscalls.master#11 edit

Differences ...

==== //depot/projects/smpng/sys/compat/svr4/svr4_misc.c#45 (text+ko) ====

@@ -795,27 +795,36 @@
 	struct proc *p = td->td_proc;
 	struct vmspace *vm = p->p_vmspace;
 	vm_offset_t new, old, base, ns;
-	int rv;
+	rlim_t datalim, vmemlim;
+	int error, rv;
+
+	PROC_LOCK(p);
+	datalim = lim_cur(p, RLIMIT_DATA);
+	vmemlim = lim_cur(p, RLIMIT_VMEM);
+	PROC_UNLOCK(p);
 
 	base = round_page((vm_offset_t) vm->vm_daddr);
 	ns = (vm_offset_t)uap->nsize;
 	new = round_page(ns);
+	error = 0;
+	vm_map_lock(&vm->vm_map);
 	if (new > base) {
-		PROC_LOCK(p);
-		if ((new - base) > (unsigned)lim_cur(p, RLIMIT_DATA)) {
-			PROC_UNLOCK(p);
-			return ENOMEM;
+		if ((new - base) > (unsigned)datalim) {
+			error = ENOMEM;
+			goto done;
+		}
+		if (new > vm_map_max(&vm->vm_map)) {
+			error = ENOMEM;
+			goto done;
 		}
-		PROC_UNLOCK(p);
-		if (new >= VM_MAXUSER_ADDRESS)
-			return (ENOMEM);
 	} else if (new < base) {
 		/*
 		 * This is simply an invalid value.  If someone wants to
 		 * do fancy address space manipulations, mmap and munmap
 		 * can do most of what the user would want.
 		 */
-		return EINVAL;
+		error = EINVAL;
+		goto done;
 	}
 
 	old = base + ctob(vm->vm_dsize);
@@ -823,27 +832,29 @@
 	if (new > old) {
 		vm_size_t diff;
 		diff = new - old;
-		PROC_LOCK(p);
-		if (vm->vm_map.size + diff > lim_cur(p, RLIMIT_VMEM)) {
-			PROC_UNLOCK(p);
-			return(ENOMEM);
+		if (vm->vm_map.size + diff > vmemlim) {
+			error = ENOMEM;
+			goto done;
 		}
-		PROC_UNLOCK(p);
 		rv = vm_map_find(&vm->vm_map, NULL, 0, &old, diff, FALSE,
 			VM_PROT_ALL, VM_PROT_ALL, 0);
 		if (rv != KERN_SUCCESS) {
-			return (ENOMEM);
+			error = ENOMEM;
+			goto done;
 		}
 		vm->vm_dsize += btoc(diff);
 	} else if (new < old) {
 		rv = vm_map_remove(&vm->vm_map, new, old);
 		if (rv != KERN_SUCCESS) {
-			return (ENOMEM);
+			error = ENOMEM;
+			goto done;
 		}
 		vm->vm_dsize -= btoc(old - new);
 	}
+done:
+	vm_map_unlock(&vm->vm_map);
 
-	return (0);
+	return (error);
 }
 
 static __inline clock_t

==== //depot/projects/smpng/sys/compat/svr4/syscalls.master#11 (text+ko) ====

@@ -57,7 +57,7 @@
 14	AUE_NULL	MSTD	{ int svr4_sys_mknod(char* path, int mode, int dev); }
 15	AUE_NULL	MNOPROTO	{ int chmod(char *path, int mode); }
 16	AUE_NULL	MNOPROTO	{ int chown(char *path, uid_t uid, gid_t gid); }
-17	AUE_NULL	STD	{ int svr4_sys_break(caddr_t nsize); }
+17	AUE_NULL	MSTD	{ int svr4_sys_break(caddr_t nsize); }
 18	AUE_NULL	MSTD	{ int svr4_sys_stat(char* path, \
 				    struct svr4_stat* ub); }
 19	AUE_NULL	MNOPROTO	{ int lseek(int filedes, off_t *offset, \


More information about the p4-projects mailing list