www.delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
X-SWARE-Spam-Status: | No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS |
X-Spam-Check-By: | sourceware.org |
MIME-Version: | 1.0 |
Subject: | RE: how to get mmap page size? |
Date: | Fri, 16 Jan 2009 13:51:24 -0000 |
Message-ID: | <5E25AF06EFB9EA4A87C19BC98F5C8753024EE59D@core-email.int.ascribe.com> |
In-Reply-To: | <ee2e06e90901160424j63c9a2b0u8d6e76bd8bb352c1@mail.gmail.com> |
References: | <ee2e06e90901160424j63c9a2b0u8d6e76bd8bb352c1 AT mail DOT gmail DOT com> |
From: | "Phil Betts" <Phil DOT Betts AT ascribe DOT com> |
To: | <cygwin AT cygwin DOT com> |
Reply-To: | <cygwin AT cygwin DOT com> |
X-IsSubscribed: | yes |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Unsubscribe: | <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id n0GDqAqu019416 |
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/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |