This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Consolidate Linux mmap implementation
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: Florian Weimer <fweimer at redhat dot com>, libc-alpha at sourceware dot org
- Date: Wed, 12 Apr 2017 11:15:06 -0300
- Subject: Re: [PATCH] Consolidate Linux mmap implementation
- Authentication-results: sourceware.org; auth=none
- References: <1490369962-29989-1-git-send-email-adhemerval.zanella@linaro.org> <757b1881-bd83-ac34-c299-c3fc9c9731d7@redhat.com>
On 12/04/2017 11:03, Florian Weimer wrote:
> On 03/24/2017 04:39 PM, Adhemerval Zanella wrote:
>> + /* For architectures with sizeof (off_t) < sizeof (off64_t) mmap is
>> + implemented with __SYS_mmap2 syscall and the offset is represented in
>> + multiples of page size. For offset larger than
>> + '1 << (page_shift + 8 * sizeof (off_t))' (that is, 1<<44 on system with
>> + page size of 4096 bytes) the system call silently truncates the offset.
>> + For this case glibc mmap implementation returns EINVAL. */
>> + const int prot = PROT_READ | PROT_WRITE;
>> + const int flags = MAP_SHARED;
>> + const int64_t offset = 1ULL << (page_shift + 8 * sizeof (uint32_t));
>
> Is there a test already which checks that an offset which is not a multiple of the page size is not silently rounded down?
>
> Thanks,
> Florian
posix/tst-mmap.c already check this up for both mmap/mmap64:
42 /* First try something which is not allowed: map at an offset which is
43 not modulo the pagesize. */
44 ptr = mmap (NULL, 1000, PROT_READ, MAP_SHARED, fd, ps - 1);
45 if (ptr != MAP_FAILED)
46 {
47 puts ("mapping at offset with mod pagesize != 0 succeeded!");
48 result = 1;
49 }
50 else if (errno != EINVAL && errno != ENOSYS)
51 {
52 puts ("wrong error value for mapping at offset with mod pagesize != 0: %m (should be EINVAL)");
53 result = 1;
54 }