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");
}
DEC OSF/1 does allow mapping of files into memory space.
Frank
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
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