www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/01/16/10:11:18

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_23,J_CHICKENPOX_43,J_CHICKENPOX_44,SARE_MSGID_LONG40,SPF_PASS
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
Date: Fri, 16 Jan 2009 15:10:35 +0000
Message-ID: <ee2e06e90901160710v7b4dc070lf9dc323e301be97f@mail.gmail.com>
Subject: Re: how to get mmap page size?
From: Jay Foad <jay DOT foad AT gmail DOT com>
To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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

Corinna Vinschen wrote:

> mmap always allocates in 64K chunks.

That doesn't seem to be true in practice. In the test below I mmap a
1080K file (this is a multiple of 4K but not a multiple of 64K). The
first byte after the end of the file isn't readable.

$ cat mmaptest.c
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
        int fd;
        struct stat st;
        void *p;
        if (argc != 2) return 1;
        if ((fd = open(argv[1], O_RDONLY, 0)) < 0) return 1;
        if (fstat(fd, &st) != 0) return 1;
        if ((p = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd,
0)) == MAP_FAILED) return 1;
        printf("last byte 0x%02X\n", ((unsigned char *)p)[st.st_size - 1]);
        fflush(stdout);
        printf("next byte 0x%02X\n", ((unsigned char *)p)[st.st_size]);
        return 0;
}

$ gcc -o mmaptest mmaptest.c

$ dd bs=1080K count=1 if=/dev/random of=foo
1+0 records in
1+0 records out
1105920 bytes (1.1 MB) copied, 0.077 s, 14.4 MB/s

$ ./mmaptest foo
last byte 0x5F
      9 [main] mmaptest 3040 _cygtls::handle_exceptions: Error while dumping sta
te (probably corrupted stack)
Segmentation fault (core dumped)

This is a recent cygwin installation on XP Pro SP2.

Thanks,
Jay.

--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019