From d3573f61aca67a398de7eaa7593d3973cb5fd154 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 27 Aug 2015 16:44:04 -0300 Subject: Fix wordsize-32 mmap offset for negative value (BZ#18877) This patch fixes the default wordsize-32 mmap implementation offset calculation for negative values. Current code uses signed shift operation to calculate the multiple size to use with syscall and it is implementation defined. Change it to use a division base on mmap page size (default being as before, 4096). Tested on armv7hf. [BZ #18877] * posix/Makefile (tests): Add tst-mmap-offset. * posix/tst-mmap.c: New file. * sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c (__mmap): Fix offset calculation for negative values. --- sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sysdeps') diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c index 24835ce9cc..75790f1996 100644 --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c +++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c @@ -21,20 +21,20 @@ #include #include -#ifndef MMAP_PAGE_SHIFT -#define MMAP_PAGE_SHIFT 12 +#ifndef MMAP_PAGE_UNIT +# define MMAP_PAGE_UNIT 4096UL #endif __ptr_t __mmap (__ptr_t addr, size_t len, int prot, int flags, int fd, off_t offset) { - if (offset & ((1 << MMAP_PAGE_SHIFT) - 1)) + if (offset & (MMAP_PAGE_UNIT - 1)) { __set_errno (EINVAL); return MAP_FAILED; } return (__ptr_t) INLINE_SYSCALL (mmap2, 6, addr, len, prot, flags, fd, - offset >> MMAP_PAGE_SHIFT); + offset / MMAP_PAGE_UNIT); } weak_alias (__mmap, mmap) -- cgit 1.4.1