Subject: port-i386/1834: panic caused by mlock system call on i386
To: None <>
From: R.Gopalakrishnan <>
List: netbsd-bugs
Date: 12/13/1995 10:30:07
>Number:         1834
>Category:       port-i386
>Synopsis:       The mlock system call panics in pmap_enter()
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 13 12:20:03 1995
>Originator:     gopal
Washington University, St.Louis
>Release:        NetBSD 1.1_ALPHA
Pentium 133 Mhz PC, NetBSD 1.1_ALPHA, 
system: NetBSD 1.1_ALPHA NetBSD 1.1_ALPHA (FARS) #22: Tue Dec 12 17:46:54 CST 1995 i386

	I tried to mlock an address obtained using shmat. The machine panics
	in pmap_enter(). I am running as root. If I try to mlock an address
	obtained using malloc, it succeeds.
	#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#define N 200
        int sid ;
        char *ptr ;
	/* Create a segment with key 0x5555 */
        if ((sid = shmget(0x5555, N*4096, (IPC_CREAT|SHM_RND)|(0666))) < 0) {
                perror("shmget") ;
                exit(1) ;
        printf("sid=0x%x\n",sid) ; /* succeeds;gives sid of 0x30000 */
	/* Attach it to my process */
        if ((ptr = (char *)shmat(sid, 0, 0600)) < (char *)0) {
                perror("shmat") ;
                exit(1) ;

        printf("addr=0x%x\n",ptr) ;/* succeeds; returns 0x10801000 */
/* THIS CALL PANICS in pmap_enter() saying "ptdi 0xXXXXX" */
        if (mlock(ptr, 4096)) perror("mlock") ;

	Before calling mlock, read or write the first byte in each page that
	you want to lock. Then the mlock call succeeds without panic.