public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Jay Foad <jay.foad@gmail.com>
To: cygwin@cygwin.com
Subject: Re: how to get mmap page size?
Date: Fri, 16 Jan 2009 16:11:00 -0000	[thread overview]
Message-ID: <ee2e06e90901160710v7b4dc070lf9dc323e301be97f@mail.gmail.com> (raw)

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/

             reply	other threads:[~2009-01-16 15:11 UTC|newest]

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

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=ee2e06e90901160710v7b4dc070lf9dc323e301be97f@mail.gmail.com \
    --to=jay.foad@gmail.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).