patch-2.1.37 linux/ipc/shm.c

Next file: linux/ipc/util.c
Previous file: linux/ipc/sem.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.36/linux/ipc/shm.c linux/ipc/shm.c
@@ -16,6 +16,7 @@
 #include <linux/swap.h>
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
+#include <linux/init.h>
 
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -44,7 +45,7 @@
 static ulong swap_successes = 0;
 static ulong used_segs = 0;
 
-void shm_init (void)
+__initfunc(void shm_init (void))
 {
 	int id;
 
@@ -402,42 +403,21 @@
 	shm_swap_in		/* swapin */
 };
 
-/* Insert shmd into the circular list shp->attaches */
+/* Insert shmd into the list shp->attaches */
 static inline void insert_attach (struct shmid_ds * shp, struct vm_area_struct * shmd)
 {
-	struct vm_area_struct * attaches;
-
-	if ((attaches = shp->attaches)) {
-		shmd->vm_next_share = attaches;
-		shmd->vm_prev_share = attaches->vm_prev_share;
-		shmd->vm_prev_share->vm_next_share = shmd;
-		attaches->vm_prev_share = shmd;
-	} else
-		shp->attaches = shmd->vm_next_share = shmd->vm_prev_share = shmd;
+	if((shmd->vm_next_share = shp->attaches) != NULL)
+		shp->attaches->vm_pprev_share = &shmd->vm_next_share;
+	shp->attaches = shmd;
+	shmd->vm_pprev_share = &shp->attaches;
 }
 
-/* Remove shmd from circular list shp->attaches */
+/* Remove shmd from list shp->attaches */
 static inline void remove_attach (struct shmid_ds * shp, struct vm_area_struct * shmd)
 {
-	if (shmd->vm_next_share == shmd) {
-		if (shp->attaches != shmd) {
-			printk("shm_close: shm segment (id=%ld) attach list inconsistent\n",
-			       SWP_OFFSET(shmd->vm_pte) & SHM_ID_MASK);
-			printk("shm_close: %08lx-%08lx %c%c%c%c %08lx %08lx\n",
-				shmd->vm_start, shmd->vm_end,
-				shmd->vm_flags & VM_READ ? 'r' : '-',
-				shmd->vm_flags & VM_WRITE ? 'w' : '-',
-				shmd->vm_flags & VM_EXEC ? 'x' : '-',
-				shmd->vm_flags & VM_MAYSHARE ? 's' : 'p',
-				shmd->vm_offset, shmd->vm_pte);
-		}
-		shp->attaches = NULL;
-	} else {
-		if (shp->attaches == shmd)
-			shp->attaches = shmd->vm_next_share;
-		shmd->vm_prev_share->vm_next_share = shmd->vm_next_share;
-		shmd->vm_next_share->vm_prev_share = shmd->vm_prev_share;
-	}
+	if(shmd->vm_next_share)
+		shmd->vm_next_share->vm_pprev_share = shmd->vm_pprev_share;
+	*shmd->vm_pprev_share = shmd->vm_next_share;
 }
 
 /*
@@ -575,7 +555,6 @@
 	shmd->vm_flags = VM_SHM | VM_MAYSHARE | VM_SHARED
 			 | VM_MAYREAD | VM_MAYEXEC | VM_READ | VM_EXEC
 			 | ((shmflg & SHM_RDONLY) ? 0 : VM_MAYWRITE | VM_WRITE);
-	shmd->vm_next_share = shmd->vm_prev_share = NULL;
 	shmd->vm_inode = NULL;
 	shmd->vm_offset = 0;
 	shmd->vm_ops = &shm_vm_ops;
@@ -825,9 +804,10 @@
 		if (shmd->vm_mm->rss > 0)
 			shmd->vm_mm->rss--;
 		flush_tlb_page(shmd, tmp);
-	    /* continue looping through circular list */
+	    /* continue looping through the linked list */
 	    } while (0);
-	    if ((shmd = shmd->vm_next_share) == shp->attaches)
+	    shmd = shmd->vm_next_share;
+	    if (!shmd)
 		break;
 	}
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov