Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mmap in Solaris

Posted on 1997-07-06
2
Medium Priority
?
357 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 600 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

963 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