This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Consolidate Linux mmap implementation



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     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]