public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Phil Betts" <Phil.Betts@ascribe.com>
To: <cygwin@cygwin.com>
Subject: RE: how to get mmap page size?
Date: Fri, 16 Jan 2009 15:34:00 -0000	[thread overview]
Message-ID: <5E25AF06EFB9EA4A87C19BC98F5C8753024EE59D@core-email.int.ascribe.com> (raw)
In-Reply-To: <ee2e06e90901160424j63c9a2b0u8d6e76bd8bb352c1@mail.gmail.com>

Jay Foad wrote on Friday, January 16, 2009 12:24 PM::

> I have an application that wants to use mmap() to read a file, but
> only if it can guarantee that this will leave one or more zero bytes
> after the end of the contents of the file in memory:
> 
>   if ((filesize & (pagesize - 1) != 0)
>     use_mmap();
>   else
>     use_read();
> 

FYI, this is not good practice (although I fully understand why you
might want to do it).  From the mmap man page on an OSF1 UNIX box at 
work:

| If the len parameter is not a multiple of the page size returned by
| the sysconf(_SC_PAGE_SIZE) call, then the result of any reference to
| an address between the end of the region and the end of the page 
| containing the end of the region is undefined.

and:

|  +  If the end of the mapped file region is beyond the end of the 
|     file, the result of any reference to an address in the mapped 
|     file region corresponding to an offset beyond the end of the 
|     file is unspecified.

In other words, you're relying on system dependent behaviour if you
reference memory beyond the end of the file.  Your requirement
"only if it can guarantee that this will leave one or more zero bytes
after the end of the contents" cannot be satisfied if system
independence is required (or may be in future).  If you ever build 
your code on other systems, any bugs due to this would probably be 
really tough to track down, may be quite subtle, and may pose a
security risk.


Phil
-- 


This email has been scanned by Ascribe PLC using Microsoft Antigen for Exchange.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

  parent reply	other threads:[~2009-01-16 13:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-16 15:11 Jay Foad
2009-01-16 15:25 ` Corinna Vinschen
2009-01-16 15:34 ` Phil Betts [this message]
2009-01-16 16:11 Jay Foad
2009-01-16 17:21 ` Corinna Vinschen
2009-01-16 17:28 Jay Foad
2009-01-18  1:04 ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5E25AF06EFB9EA4A87C19BC98F5C8753024EE59D@core-email.int.ascribe.com \
    --to=phil.betts@ascribe.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).