simple mmap() call failed with EINVAL on Redhat EL 3 update 9
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
- build with gcc
gcc test.c
- create a test.txt file with lengh 100 or you like for testing
- run testing
a.out 10
I specify 10 bytes length from the beginning of test.txt file to be mapped into memory. mmap failed with EINVAL error. If I changed the length to 0, it returns successfully. It also failed with 4096 which is pagesize.
The invalid argument is the 'len', which you have set to zero. Perhaps it should be set to the size of the file? Or perhaps you should guess the size of the file with the command-line arg?
Last edited by dwhitney67; 03-13-2009 at 11:54 AM.
sorry about the compiling errors as I am using a smart configured(might be stupid) gcc...
By the way, len=any# works fine on another box which has "Linux 2.4.21-9.ELsmp #1 SMP" and "Red Hat Enterprise Linux AS release 3 (Taroon Update 1)"
I don't want to clean or reinstall the system to fix this problem, I really want to figure out the problem first and know what is the real cause, such as system configuration caused the problem or a system file caused the problem etc...
On my system, the code runs fine as long as 'len' is not zero.
You may want to refer to the man-page for mmap() on your system to see if there is any information given concerning the 'addr' and/or 'len' being zero (or null).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.