From tegge@pat.idt.unit.no  Mon Aug 19 07:44:04 1996
Received: from pat.idt.unit.no (pat.idt.unit.no [129.241.103.5])
          by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id HAA20965
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 19 Aug 1996 07:44:02 -0700 (PDT)
Received: from ikke.idt.unit.no (ikke.idt.unit.no [129.241.111.65]) by pat.idt.unit.no (8.7.5/8.7.3) with ESMTP id QAA29630 for <FreeBSD-gnats-submit@freebsd.org>; Mon, 19 Aug 1996 16:43:58 +0200 (MET DST)
Received: (from tegge@localhost) by ikke.idt.unit.no (8.7.5/8.7.3) id QAA01466; Mon, 19 Aug 1996 16:43:58 +0200 (MET DST)
Message-Id: <199608191443.QAA01466@ikke.idt.unit.no>
Date: Mon, 19 Aug 1996 16:43:58 +0200 (MET DST)
From: Tor Egge <tegge@idt.ntnu.no>
Reply-To: tegge@idt.ntnu.no
To: FreeBSD-gnats-submit@freebsd.org
Subject: mlock fails on readonly regions
X-Send-Pr-Version: 3.2

>Number:         1514
>Category:       kern
>Synopsis:       mlock fails on readonly regions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dyson
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 19 07:50:02 PDT 1996
>Closed-Date:    Thu Jun 10 07:45:17 PDT 1999
>Last-Modified:  Thu Jun 10 07:47:02 PDT 1999
>Originator:     Tor Egge
>Release:        FreeBSD 2.2-CURRENT i386
>Organization:
Norwegian University of Science and Technology, Trondheim, Norway
>Environment:
FreeBSD ikke.idt.unit.no 2.2-CURRENT FreeBSD 2.2-CURRENT #5: Mon Aug 19 16:14:50 MET DST 1996     root@ikke.idt.unit.no:/usr/src/sys/compile/TEGGE  i386

>Description:

	When a memory region is readonly and mlock is called, vm_fault_wire
	tries to fault in the region with (VM_PROT_READ|VM_PROT_WRITE) as 
	flags to vm_fault. This fails, since the memory region is not
	writable.

>How-To-Repeat:

	mmap a region readonly, and try mlocking it.

Here is the pach I use to enable mlock for normal users (Added one line 
from /usr/src/sys/arch/pmax/include/pmap.h in NetBSD-current).
------
*** /usr/snapshot-src/sys/i386/include/pmap.h   Tue Jul 30 05:08:57 1996
--- ./pmap.h    Mon Aug 19 14:45:28 1996
***************
*** 212,217 ****
--- 212,218 ----
  struct pcb;
  
  void  pmap_bootstrap __P(( vm_offset_t, vm_offset_t));
+ #define pmap_wired_count(pmap)        ((pmap)->pm_stats.wired_count)
  pmap_t        pmap_kernel __P((void));
  void  *pmap_mapdev __P((vm_offset_t, vm_size_t));
  unsigned * __pure pmap_pte __P((pmap_t, vm_offset_t)) __pure2;
----
	
>Fix:
Here is a patch that solved the problem for me.
------ 
diff -c /usr/snapshot-src/sys/vm/vm_fault.c ./vm_fault.c
*** /usr/snapshot-src/sys/vm/vm_fault.c	Tue Jul 30 05:08:07 1996
--- ./vm_fault.c	Mon Aug 19 16:12:23 1996
***************
*** 840,846 ****
  	 */
  
  	for (va = start; va < end; va += PAGE_SIZE) {
! 		rv = vm_fault(map, va, VM_PROT_READ|VM_PROT_WRITE, TRUE);
  		if (rv) {
  			if (va != start)
  				vm_fault_unwire(map, start, va);
--- 840,846 ----
  	 */
  
  	for (va = start; va < end; va += PAGE_SIZE) {
! 		rv = vm_fault(map, va, VM_PROT_READ, TRUE);
  		if (rv) {
  			if (va != start)
  				vm_fault_unwire(map, start, va);
------------
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->dyson 
Responsible-Changed-By: wosch 
Responsible-Changed-When: Tue Aug 20 11:41:39 PDT 1996 
Responsible-Changed-Why:  
John's area 
Responsible-Changed-From-To: dyson->dg 
Responsible-Changed-By: wosch 
Responsible-Changed-When: Wed Jun 17 15:13:22 MEST 1998 
Responsible-Changed-Why:  
John Dyson has resigned from the FreeBSD project. 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Thu Jun 10 07:45:17 PDT 1999 
State-Changed-Why:  
Fixed in revision 1.59 of vm_fault.c 
Responsible-Changed-From-To: dg->dyson 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Thu Jun 10 07:46:27 PDT 1999 
Responsible-Changed-Why:  
John's fix. 
>Unformatted:
