PERFORCE change 56811 for review

Robert Watson rwatson at FreeBSD.org
Thu Jul 8 21:46:55 GMT 2004


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

Change 56811 by rwatson at rwatson_tislabs on 2004/07/08 21:46:17

	Remove module refcount; maybe removed a little too much and will
	have to re-add it.

Affected files ...

.. //depot/projects/trustedbsd/mac/sys/kern/sysv_shm.c#20 edit

Differences ...

==== //depot/projects/trustedbsd/mac/sys/kern/sysv_shm.c#20 (text+ko) ====

@@ -94,8 +94,6 @@
 
 static int shm_last_free, shm_nused, shm_committed, shmalloced;
 static struct shmid_kernel	*shmsegs;
-static int refcount; /* to ensure consistency during and after shmunload */
-static struct mtx refcnt_mtx;	/* global mutex for refcount. */
 
 struct shm_handle {
 	/* vm_offset_t kva; */
@@ -283,18 +281,6 @@
 	if (!jail_sysvipc_allowed && jailed(td->td_ucred))
 		return (ENOSYS);
 
-	/*
-	 * Prevent thread from going any further if module is (being)
-	 * unloaded.
-	 */
-	mtx_lock(&refcnt_mtx);
-	if (refcount < 0 ) {
-		mtx_unlock(&refcnt_mtx);
-		return (ENOSYS);
-	}
-	refcount++; /* Indicate that thread is active in the code-path */
-	mtx_unlock(&refcnt_mtx);
-
 	mtx_lock(&Giant);
 	shmmap_s = p->p_vmspace->vm_shm;
  	if (shmmap_s == NULL) {
@@ -327,9 +313,6 @@
 	error = shm_delete_mapping(p->p_vmspace, shmmap_s);
 done2:
 	mtx_unlock(&Giant);
-	mtx_lock(&refcnt_mtx);
-	refcount--; /* Indicate that thread no longer active in the code-path */
-	mtx_unlock(&refcnt_mtx);
 	return (error);
 }
 
@@ -365,18 +348,6 @@
 	if (!jail_sysvipc_allowed && jailed(td->td_ucred))
 		return (ENOSYS);
 
-	/*
-	 * Prevent thread from going any further if module is (being)
-	 * unloaded.
-	 */
-	mtx_lock(&refcnt_mtx);
-	if (refcount < 0 ) {
-		mtx_unlock(&refcnt_mtx);
-		return (ENOSYS);
-	}
-	refcount++; /* Indicate that thread is active in the code-path */
-	mtx_unlock(&refcnt_mtx);
-
 	mtx_lock(&Giant);
 	shmmap_s = p->p_vmspace->vm_shm;
 	if (shmmap_s == NULL) {
@@ -459,9 +430,6 @@
 	td->td_retval[0] = attach_va;
 done2:
 	mtx_unlock(&Giant);
-	mtx_lock(&refcnt_mtx);
-	refcount--; /* Indicate that thread no longer active in the code-path */
-	mtx_unlock(&refcnt_mtx);
 	return (error);
 }
 
@@ -507,18 +475,6 @@
 	if (!jail_sysvipc_allowed && jailed(td->td_ucred))
 		return (ENOSYS);
 
-	/*
-	 * Prevent thread from going any further if module is (being)
-	 * unloaded.
-	 */
-	mtx_lock(&refcnt_mtx);
-	if (refcount < 0 ) {
-		mtx_unlock(&refcnt_mtx);
-		return (ENOSYS);
-	}
-	refcount++; /* Indicate that thread is active in the code-path */
-	mtx_unlock(&refcnt_mtx);
-
 	mtx_lock(&Giant);
 	shmseg = shm_find_segment_by_shmid(uap->shmid);
 	if (shmseg == NULL) {
@@ -557,9 +513,6 @@
 	}
 done2:
 	mtx_unlock(&Giant);
-	mtx_lock(&refcnt_mtx);
-	refcount--; /* Indicate that thread no longer active in the code-path */
-	mtx_unlock(&refcnt_mtx);
 	return (error);
 #else
 	return (EINVAL);
@@ -591,18 +544,6 @@
 	if (!jail_sysvipc_allowed && jailed(td->td_ucred))
 		return (ENOSYS);
 
-	/*
-	 * Prevent thread from going any further if module is (being)
-	 * unloaded
-	 */
-	mtx_lock(&refcnt_mtx);
-	if (refcount < 0 ) {
-		mtx_unlock(&refcnt_mtx);
-		return (ENOSYS);
-	}
-	refcount++; /* Indicate that thread is active in the code-path */
-	mtx_unlock(&refcnt_mtx);
-
 	mtx_lock(&Giant);
 	switch (cmd) {
 	case IPC_INFO:
@@ -689,9 +630,6 @@
 	}
 done2:
 	mtx_unlock(&Giant);
-	mtx_lock(&refcnt_mtx);
-	refcount--; /* Indicate that thread no longer active in the code-path */
-	mtx_unlock(&refcnt_mtx);
 	return (error);
 }
 
@@ -882,18 +820,6 @@
 	if (!jail_sysvipc_allowed && jailed(td->td_ucred))
 		return (ENOSYS);
 
-	/*
-	 * Prevent thread from going any further if module is (being)
-	 * unloaded.
-	 */
-	mtx_lock(&refcnt_mtx);
-	if (refcount < 0 ) {
-		mtx_unlock(&refcnt_mtx);
-		return (ENOSYS);
-	}
-	refcount++; /* Indicate that thread is active in the code-path */
-	mtx_unlock(&refcnt_mtx);
-
 	mtx_lock(&Giant);
 	mode = uap->shmflg & ACCESSPERMS;
 	if (uap->key != IPC_PRIVATE) {
@@ -913,9 +839,6 @@
 	error = shmget_allocate_segment(td, uap, mode);
 done2:
 	mtx_unlock(&Giant);
-	mtx_lock(&refcnt_mtx);
-	refcount--; /* Indicate that thread no longer active in the code-path */
-	mtx_unlock(&refcnt_mtx);
 	return (error);
 }
 
@@ -1043,39 +966,14 @@
 	shm_committed = 0;
 	shmexit_hook = &shmexit_myhook;
 	shmfork_hook = &shmfork_myhook;
-	refcount = 0;
-	/*
-	 * It is not permissible to pass the same mutex to mtx_init()
-	 * multiple times without intervening calls to mtx_destroy().  Since
-	 * we cannot destroy the refcnt_mtx during shmunload, we check if
-	 * the mtx_init has ever been called. If so, we dont need to do
-	 * mtx_init as the mutex is already initialized.
-	 */
-	if (mtx_initialized(&refcnt_mtx) == 0)
-		mtx_init(&refcnt_mtx, "shmrefcnt", NULL, MTX_DEF);
 }
 
 static int
 shmunload()
 {
-
-	/*
-	 * Make sure that the shmunload maintains the consistency of the
-	 * shmsegs data structure.  This assures that the unload doesn't
-	 * take place if any thread is in any of the code-paths (tinkering
-	 * with the data structures), and also that no thread can enter
-	 * the code-paths once the module is unloaded.
-	 */
-	mtx_lock(&refcnt_mtx);
-	if ((refcount > 0) || (shm_nused > 0)) {
-		mtx_unlock(&refcnt_mtx);
-		return (EBUSY);
-	}
-	refcount= -1; /* Mark the module as being unloaded */
-	mtx_unlock(&refcnt_mtx);
-
 #ifdef MAC
 	int i;	
+
 	for (i = 0; i < shmalloced; i++)
   	mac_destroy_ipc_shm(&shmsegs[i]);
 #endif
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message



More information about the trustedbsd-cvs mailing list