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 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" 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: References: From: "Phil Betts" To: Reply-To: X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: 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 Content-Transfer-Encoding: 8bit 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/