Subject: Re: VI is crazy !!!
To: Joao Carlos Mendes Luis <jonny@gaia.coppe.ufrj.br>
From: Greg Hudson <ghudson@mit.edu>
List: netbsd-help
Date: 03/02/1996 11:45:52
This is a followup to a previous message I sent about your vi problem.
Due to a second bug I didn't know about, the patch I sent you won't
help you any.  (It won't hurt, either, but don't bother applying it if
you haven't already.)  Following is a patch to be applied in
/usr/src/sys/vm to fix the problem in the kernel.  I've tested this
patch, and plan to check it into the mainline sources shortly, but do
make sure to keep an old kernel around in case there's a bug here.

*** vm_mmap.c	1996/03/01 06:11:19	1.4
--- vm_mmap.c	1996/03/02 16:12:29
***************
*** 879,884 ****
--- 879,887 ----
  			printf("vm_mmap(%d): FILE *addr %x size %x pager %p\n",
  			       curproc->p_pid, *addr, size, pager);
  #endif
+ 
+ 		/* Make sure new mapping is in sync with filesystem */
+ 		vm_map_clean(map, *addr, *addr+size, TRUE, TRUE);
  	}
  	/*
  	 * Correct protection (default is VM_PROT_ALL).
*** vm_map.c	1996/03/02 08:51:37	1.1
--- vm_map.c	1996/03/02 08:51:21
***************
*** 1381,1387 ****
  	register vm_map_entry_t current;
  	vm_map_entry_t entry;
  	vm_size_t size;
! 	vm_object_t object;
  	vm_offset_t offset;
  
  	vm_map_lock_read(map);
--- 1381,1387 ----
  	register vm_map_entry_t current;
  	vm_map_entry_t entry;
  	vm_size_t size;
! 	vm_object_t object, shadow;
  	vm_offset_t offset;
  
  	vm_map_lock_read(map);
***************
*** 1433,1452 ****
  			object = current->object.vm_object;
  			vm_object_lock(object);
  		}
! 		/*
! 		 * Flush pages if writing is allowed.
! 		 * XXX should we continue on an error?
! 		 */
! 		if ((current->protection & VM_PROT_WRITE) &&
! 		    !vm_object_page_clean(object, offset, offset+size,
! 					  syncio, FALSE)) {
  			vm_object_unlock(object);
  			vm_map_unlock_read(map);
  			return(KERN_FAILURE);
! 		}
! 		if (invalidate)
  			vm_object_page_remove(object, offset, offset+size);
! 		vm_object_unlock(object);
  		start += size;
  	}
  
--- 1433,1459 ----
  			object = current->object.vm_object;
  			vm_object_lock(object);
  		}
! 		while (object) {
! 		    /*
! 		     * Flush pages if writing is allowed.
! 		     * XXX should we continue on an error?
! 		     */
! 		    if ((current->protection & VM_PROT_WRITE) &&
! 			!vm_object_page_clean(object, offset, offset+size,
! 					      syncio, FALSE)) {
  			vm_object_unlock(object);
  			vm_map_unlock_read(map);
  			return(KERN_FAILURE);
! 		    }
! 		    if (invalidate)
  			vm_object_page_remove(object, offset, offset+size);
! 
! 		    shadow = object->shadow;
! 		    if (shadow)
! 			vm_object_lock(shadow);
! 		    vm_object_unlock(object);
! 		    object = shadow;
! 		}
  		start += size;
  	}