Solved

mmap in Solaris

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.

705 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

20 Experts available now in Live!

Get 1:1 Help Now