Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

=========Problem using mmap on DECstations========

0 views
Skip to first unread message

Prabal Kumar Roy

unread,
Jan 27, 1993, 7:26:10 PM1/27/93
to
Greetings:

I am trying to use the mmap command on DECStation 5000. In the following test
program I am trying to reserve 1000 bytes of memory and trying to write some stuff
in that area.

However, at the statement *intptr = 1; I am getting the following error.
pid 10810 (a.out) was killed on kernel access, at pc 0x400284. Bus error (core
dumped).

So the statement result = (caddr_t) mmap(0,..............) has got me some
memory which is in the kernel area, so when I am trying to access it later I am
getting a core dump. Any help will be greatly appreciated.

Prabal K. Roy
AI Lab
U. of New South Wales
Sydney 2033
AUSTRALIA
----------

#include <sys/types.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <string.h>
#include <limits.h>
#define PERMS 0666
#define TRUE 1
#define FALSE 0

main ()
{
int fd;
caddr_t result;
int *intptr;
char *charptr;

fd = creat("myfile", PERMS);

result = (caddr_t) mmap(0, 1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
close(fd);

intptr = (int *) result;
*intptr = 1;
result = result + sizeof(int);
charptr = (char *) result;
strcpy(charptr, "hello world");

}

Frank Wortner

unread,
Jan 28, 1993, 10:08:09 AM1/28/93
to

ULTRIX mmap() supports only the mapping of the memory associated with
a character device special file into the address space of a process. It
is not possible to map an arbitrary file.

DEC OSF/1 does allow mapping of files into memory space.

Frank

Roland Besserer

unread,
Feb 1, 1993, 2:34:51 AM2/1/93
to
r...@spectrum.cs.unsw.oz.au (Prabal Kumar Roy) writes:
: Greetings:

:
: I am trying to use the mmap command on DECStation 5000. In the following test
: program I am trying to reserve 1000 bytes of memory and trying to write some stuff
: in that area.
:

Unfortunately, for your type of usage, the mmap() call is inappropriate as
it is used to map memory associated with a device, not a regular file.
The mmap() system call is simply an interface to the mmap() routine in
a character device driver.

For what you want to do you should use one of the availabel shared memory
allocation schemes.


--

--------------------------------------------------------------------------------
Roland Besserer QUAD Systems, Santa Cruz rol...@quadsys.com

Oliver Laumann

unread,
Feb 2, 1993, 8:10:04 AM2/2/93
to
rol...@quadsys.com (Roland Besserer) writes:
> > I am trying to use the mmap command on DECStation 5000. In the
> > following test program I am trying to reserve 1000 bytes of memory
> > and trying to write some stuff in that area.
> >
> > [program that creates an empty file by calling creat(), mmaps the
> > file, and attempts to store something into the first few bytes of
> > the returned memory segment]

>
> Unfortunately, for your type of usage, the mmap() call is inappropriate as
> it is used to map memory associated with a device, not a regular file.
> The mmap() system call is simply an interface to the mmap() routine in
> a character device driver.

Even on systems that allows to mmap() regular files (such as SunOS), the
program wouldn't work, because 1) creat() opens the file for writing
only (which conflicts with the PROT_READ|PROT_WRITE argument to mmap()),
and 2) it is not allowed to reference memory locations beyond the end
of the mapped file (i.e. any location in case of a newly created file,
or `memory object' in the manual page jargon).

Checking the return value of mmap() before using it (and calling perror()
if the return value is -1) would have uncovered the first of these two
errors.

--
Oliver Laumann n...@cs.tu-berlin.de n...@tub.UUCP n...@tub.BITNET

0 new messages