Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

mmap in Solaris

Posted on 1997-07-06
2
319 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

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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

856 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