Solved

mmap in Solaris

Posted on 1997-07-06
2
321 Views
Last Modified: 2013-12-26
I would like to map two devices into contiguous memory in my process space, and I am using mmap to do this. I don't have the hardware or device drivers yet, but to test this out I tried to map two files into contiguous memory. I have run across some strange behaviors in mmap in doing this. First I tried to map a 32k and a 64k file together. So I did the
following:

    map1 = mmap(NULL, 0x8000, PROT_READ | PROT_WRITE,
                MAP_SHARED, fd1, 0);
    map2 = mmap(&map1[0x8000], 0x10000,
                PROT_READ | PROT_WRITE,
                MAP_FIXED | MAP_SHARED, fd2, 0);

This returns an error from the second mmap call saying one of the arguments to the call is invalid. I thought that this made sense because the address passed into the routine was probably invalid. Anyway, to double check I tried to map two 64k files together with the following:

    map1 = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE,
                MAP_SHARED, fd1, 0);
    map2 = mmap(&map1[0x10000], 0x10000,
                PROT_READ | PROT_WRITE,
                MAP_FIXED | MAP_SHARED, fd2, 0);

This actually works, which makes me somewhat happy, but also very suspicious of mmap (I check the mapping by loading the file with known data and compare the mapped memory with the known contents). I tried the same thing with two 32k files and that also works. I do not understand why the second set of calls work and the first set won't. If anyone out there can give some insight I would be very grateful. I am running Solaris on a SPARC 20 (SunOS 5.1.3).

thanks in advance,
conrad mukai
0
Comment
Question by:cmukai
2 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 200 total points
ID: 1293870
mmap(2) may return EINVAL, which may meen:

1. The arguments _addr_ (if MAX_FIXED was specified) or _offset_ are not multiples of the page size as returned by sysconf().

2. The field in _flags_ is invalid (neither MAP_PRIVATE or MAP_SHARED).

3. Teh argument _len_ has a value less than or equal to 0.

So, the problem should be your page size is 64K and you cannot allocate at &map1[0x8000].
Probably, in your first example, the system allocates map1 into an address space 64K aligned, and you're trying to allocate map2 not only unaligned to the page size (64K), but between the space allocated to map1.

Check your page size with sysconf(), to be completly sure.

HTH, julio
0
 

Author Comment

by:cmukai
ID: 1293871
In light of your answer, can you explain why I can map two 32k files together successfully?

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question