Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Reply-To: From: "Shane Mann" To: Subject: RE: MMap offset parameter failing with ENOMEM error Date: Fri, 20 Sep 2002 09:38:06 +1000 Message-ID: <000801c26035$9af84410$8e90a8c0@citr.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 In-Reply-To: <20020919093239.H29920@cygbert.vinschen.de> Importance: Normal X-MailScanner: Found to be clean Corinna, I noticed this while I continued testing last night. Interestingly Linux and SunOS don't seem to be bothered by this, however, if you read the IEEE standard: http://www.opengroup.org/onlinepubs/007904975/functions/mmap.html there is the following quote: "The range of bytes starting at off and continuing for len bytes shall be legitimate for the possible (not necessarily current) offsets in the file, shared memory object, or [TYM] typed memory object represented by fildes." Linux and Sun seem to allow it and return '0' if you access memory beyond the EOF, go figure. Perhaps the wrong error is being returned for this case - I would have thought the following error code would be more appropriate: [ENXIO] Addresses in the range [off,off+len) are invalid for the object specified by fildes. I have since amended the code by replacing the following line: size = finfo.st_size; with size = finfo.st_size - foff; and I still get the same error. There is some example output below: Note: index.idx is a file with a size of 557592 bytes. In the output below it worked for an offset of 400000 and created a map of 157592 bytes - but failed for the same file with an offset of 300000 and a potential map of 257592 bytes. Run 1) ~/c>./a.exe 400000 index.idx Offset is 400000 File index.idx opened on descriptor 3. It is 157592 bytes long --- Syspagesize 4096, pagemask FFFFF000, offmask FFF foff is 400000 --- Syspagesize 4096, pagemask FFFFF000, offmask FFF pfoff is 397312 **** Vars just before mmap call **** psyz = 163840 prot = 1 fd = 3 pfoff = 397312 Mapping 163840 at 2A231000 <---> 397312 (mapping fh Result from femmap is 2A231A80 Byte is 127 Run 2) ~/c>./a.exe 300000 index.idx Offset is 300000 File index.idx opened on descriptor 3. It is 257592 bytes long --- Syspagesize 4096, pagemask FFFFF000, offmask FFF foff is 300000 --- Syspagesize 4096, pagemask FFFFF000, offmask FFF pfoff is 299008 **** Vars just before mmap call **** psyz = 262144 prot = 1 fd = 3 pfoff = 299008 perror reports errno of 12 Mapping 262144 at FFFFFFFF <---> 299008 (mapping fh Any ideas? Cheers, Shane Shane Mann Software Engineer Phone: +61-7-3259-2223 LeadUp Software Pty Ltd Fax: +61-7-3259-2259 339 Coronation Drive, Email: shane DOT mann AT leadup DOT com DOT au Milton, QLD, 4064 Web: http://www.leadup.com.au > -----Original Message----- > From: cygwin-owner AT cygwin DOT com [mailto:cygwin-owner AT cygwin DOT com]On Behalf > Of Corinna Vinschen > Sent: Thursday, 19 September 2002 17:33 > To: Cygwin AT Cygwin. Com > Subject: Re: MMap offset parameter failing with ENOMEM error > > > On Thu, Sep 19, 2002 at 12:19:06PM +1000, Shane Mann wrote: > > Hi, > > > > I am having trouble with mmap using the last 'offset' parameter. I have > > attached a small piece of code (and sample file) which demonstrates the > > problem. Basically if the offset parameter is passed as a > variable to mmap > > then the call fails with an ENOMEM error. But if you pass 0 as > the parameter > > and then access the return address from mmap + offset - it is fine. My > > question: is mmap handling the offset parameter correctly? > > > > Usage for the program: > > > > ./a.exe eg: ./a.exe 11200 index.idx > > > > To see the address + offset work, comment out the first mmap > call and return > > statement and uncomment the lines below each one. > > > > Any help appreciated. > > Your application tries to mmap over EOF. > > Corinna > > -- > Corinna Vinschen Please, send mails regarding Cygwin to > Cygwin Developer mailto:cygwin AT cygwin DOT com > Red Hat, Inc. > > -- > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > Bug reporting: http://cygwin.com/bugs.html > Documentation: http://cygwin.com/docs.html > FAQ: http://cygwin.com/faq/ > -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/