Solved

mmap in Solaris

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSH commands for Nas4free 21 374
Correct syntax to upload file in a script using sftp 2 73
matchUp  challenge 9 91
Excel file not created as expected 7 46
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

929 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now