Subject: mmap(2) can't map /dev/kmem?
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: None <Mark_Weaver@brown.edu>
List: current-users
Date: 02/24/1994 09:37:48
About two months ago I wrote a similiar program, and it worked.  Have
I just forgotten how to do it right, or has something broken since
then?

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

die(char *s) { perror(s); exit(1); }

main()
{
    int fd;
    caddr_t base;

    if ((fd = open("/dev/kmem", O_RDWR)) < 0)
	die("open");
    base = mmap(0, 4096, PROT_READ | PROT_WRITE,
		MAP_SHARED | MAP_FILE, fd, 0);
    if (base == (caddr_t)-1)
	die("mmap");
    printf("successful\n");
    return 0;
}

--------------------------------------------------------------------
Email: Mark_Weaver@brown.edu           | Brown University
PGP Key: finger mhw@cs.brown.edu       | Dept of Computer Science

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