Subject: kern/169: mmap'ing devices no longer work
To: None <gnats-admin>
From: Jarle Greipsland <jarle@darling.idt.unit.no>
List: netbsd-bugs
Date: 03/16/1994 14:05:03
>Number:         169
>Category:       kern
>Synopsis:       mmap'ing /dev/* fails.
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    gnats-admin (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 16 14:05:02 1994
>Originator:     Jarle Greipsland
>Organization:
Norwegian Institute of Technology
>Release:        NetBSD-current
>Environment:
Intel Professional Workstation/GX, NetBSD-current, do. std.
System: NetBSD darling.idt.unit.no 0.9a AICTEST#184 i386


>Description:
mmap'ing device files seems to fail no matter what type of devices involved.
Encountered the bug while configuring XFree86-2.1 and trying to make it mmap
in the framebuffer from /dev/mem.  Have since tried to mmap several other
files and devices, giving the consistent results that mmap'ing files work ok,
but mmap'ing devices fails.  (Maybe this also explains why xload doesn't work
anymore).

>How-To-Repeat:
Run the following program (with appropriate filenames compiled in).

#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/mman.h>

#define FILENAME "/dev/mem"  
#define FOFFSET ((off_t)0x0000)
int main()
{
        int fd;
        caddr_t ptr;

        fd = open(FILENAME, O_RDWR);
        if (fd < 0) {
                fprintf(stderr,"Couldn't open \"%s\"\n", FILENAME);
                exit(-1);
        }
        ptr = mmap((caddr_t)0, 4096, PROT_READ|PROT_WRITE,
                   MAP_FILE, fd, FOFFSET);
        if (ptr == (caddr_t)-1) {
                fprintf(stderr, "mmap failed\n");
                exit(-1);
        }
        fprintf(stderr, "Success!\n");
        exit(0);
}

>Fix:
	"how to correct or work around the problem, if known (multiple lines)"
Oh come on! I've filled out the two previous blanks.  Now you fill out
this one. :-)  Seriously, I'm not that experienced in kernel exploration,
but maybe the dev_pager is in error?

					-jarle
----
"Don't get suckered in by the comments -- they can be terribly
 misleading. Debug only code."
				-- Dave Storer

>Audit-Trail:
>Unformatted:


------------------------------------------------------------------------------