*BSD News Article 16698


Return to BSD News archive

Newsgroups: comp.os.386bsd.development
Path: sserve!newshost.anu.edu.au!munnari.oz.au!uunet!portal!chris
From: chris@shell.portal.com (Chris - Ding)
Subject: MMAP() doesn't work for me ?
Message-ID: <C7xM5G.3sE@unix.portal.com>
Keywords: mmap, 386bsd
Sender: news@unix.portal.com
Nntp-Posting-Host: jobe
Organization: Portal Communications Company
Date: Tue, 1 Jun 1993 07:29:40 GMT
Lines: 53


The configuration is 386bsd 0.1 + 0.2.3.

The command sequence is:

#su
#ls -l /dev/mem
crw-r-----    1 root       2,   0 May 31 11:58 /dev/mem
#a.out
test ( mmap ) : Invalid argument


Can anyone tell me what's wrong with the code ? Or there is a bug in the kernal ?
Thanks.
C. Ding
chris@shell.portal.com

------ Source code for a.out --------
#include	<sys/file.h>
#include	<unistd.h>
#include	<stdio.h>
#include	<ctype.h>
#include	<sys/mman.h>

main()
{
	caddr_t addr;
	int prot = PROT_WRITE;
	static int	fd;

	int i;

	if ( ( fd = open ( "/dev/mem", O_RDWR ) ) == -1 )
	{
		perror ( "test" );
		exit( 1 );
	}
	addr = mmap ( (caddr_t) 0, len, prot, MAP_FILE, fd, (off_t)0x0 );
	if ( addr == ( caddr_t ) -1 )
	{
		perror ( "test (mmap) " );
		exit ( 1 );
	}

	:
	:
	:
	:
}

--
Chris Ding
chris@portal.shell.com