Consolidate Linux mmap implementation (BZ#21270)
This patch consolidates all Linux mmap implementations on default
sysdeps/unix/sysv/linux/mmap{64}.c one. To accomodate all required
architecture specific requeriments a new internal header is created
(mmap_internal.h) where each architecture add its specific code
requirements. Currently only x86_64 (to define MMAP_PREPARE to add
MAP_32BITS), s390 (which have a different kernel ABI for mmap), m68k
(which have variable minimum page sizes), and MIPS n32 (which zero
extend the offset to handle negative one correctly) redefine the new
header.
The patch also fixes BZ#21270 where default mmap64 on architectures
which uses mmap2 silent truncates large offsets value (larger than
1 << (page shift + 8 * sizeof (off_t)) or 1<<44 on architectures with
4096 bytes page size). The new consolidate implementation returns
EINVAL as allowed by POSIX.
It also adds a tests for on current tst-mmap-offset one. I have run
a full make check on x86_64, x86_64-32, i686, aarch64, armhf, powerpc,
powerpc64le, sparc64, and sparcv9 without any regressions. I also ran
some basic tests (tst-mmap-offset) on sh4, m68k, and on qemu simulated
MIPS32 and MIPS64.
[BZ #21270]
* posix/tst-mmap-offset.c (do_prepare): New function.
(do_test): Rename to do_test_bz18877 and use FAIL_RET.
(do_test_bz21270): New function.
* sysdeps/unix/sysv/linux/aarch64/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/arm/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/hppa/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/microblaze/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mmap_internal.h: New file.
* sysdeps/unix/sysv/linux/m68k/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/s390/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list: Remove mmap
from auto-generation list.
* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/mmap.c: New file.
* sysdeps/unix/sysv/linux/mmap64.c (__mmap64): Add check for invalid
offsets and support for mmap2 syscall.
2017-04-06 20:01:56 +00:00
|
|
|
/* mmap - map files or devices into memory. Linux version.
|
2018-01-01 00:32:25 +00:00
|
|
|
Copyright (C) 2017-2018 Free Software Foundation, Inc.
|
i386: Remove syscall assembly codes with 6 arguments
This patch removes i386 assembly implementation for mmap, mmap64,
semtimeop now that i386 have 6 argument syscall support from C code
and GCC 5 can inline syscalls with 6 arguments. We also compile mmap.c,
mmap64.c and semtimedop.c with -fomit-frame-pointer since %ebp may be
used to pass the 6th argument to syscall.
Fo sysdeps/unix/sysv/linux/i386/mmap.c, with -O2 -march=i686
-mtune=generic, GCC 5.2 now generates:
<__mmap>:
0: sub $0x10,%esp
3: mov 0x28(%esp),%eax
7: mov %ebx,(%esp)
a: mov 0x18(%esp),%ecx
e: mov %esi,0x4(%esp)
12: mov 0x14(%esp),%ebx
16: mov %edi,0x8(%esp)
1a: mov 0x1c(%esp),%edx
1e: test $0xfff,%eax
23: mov 0x20(%esp),%esi
27: mov %ebp,0xc(%esp)
2b: mov 0x24(%esp),%edi
2f: jne 60 <__mmap+0x60>
31: shr $0xc,%eax
34: mov %eax,%ebp
36: mov $0xc0,%eax
3b: call *%gs:0x10
42: cmp $0xfffff000,%eax
47: ja 65 <__mmap+0x65>
49: mov (%esp),%ebx
4c: mov 0x4(%esp),%esi
50: mov 0x8(%esp),%edi
54: mov 0xc(%esp),%ebp
58: add $0x10,%esp
5b: ret
5c: lea 0x0(%esi,%eiz,1),%esi
60: mov $0xffffffea,%eax
65: mov (%esp),%ebx
68: mov 0x4(%esp),%esi
6c: mov 0x8(%esp),%edi
70: mov 0xc(%esp),%ebp
74: add $0x10,%esp
77: jmp 78 <__mmap+0x78>
vs sysdeps/unix/sysv/linux/i386/mmap.S:
<__mmap>:
0: push %ebp
1: push %ebx
2: push %esi
3: push %edi
4: mov 0x14(%esp),%ebx
8: mov 0x18(%esp),%ecx
c: mov 0x1c(%esp),%edx
10: mov 0x20(%esp),%esi
14: mov 0x24(%esp),%edi
18: mov 0x28(%esp),%ebp
1c: test $0xfff,%ebp
22: mov $0xffffffea,%eax
27: jne 38 <__mmap+0x38>
29: shr $0xc,%ebp
2c: mov $0xc0,%eax
31: call *%gs:0x10
38: pop %edi
39: pop %esi
3a: pop %ebx
3b: pop %ebp
3c: cmp $0xfffff000,%eax
41: ja 44 <__mmap+0x44>
43: ret
44: call 45 <__mmap+0x45> 45: R_386_PC32 __x86.get_pc_thunk.cx
49: add $0x2,%ecx 4b: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
4f: mov 0x0(%ecx),%ecx 51: R_386_TLS_GOTIE __libc_errno
55: neg %eax
57: mov %eax,%gs:(%ecx)
5a: or $0xffffffff,%eax
5d: ret
The C version has:
3: mov 0x28(%esp),%eax
...
1e: test $0xfff,%eax
...
31: sar $0xc,%eax
34: mov %eax,%ebp
is due to missing $ebx register constraint for inline asm. We have
to use "r" constraint with
register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6);
and compiler chose %eax for offset (arg6) in
if (offset & (MMAP_PAGE_UNIT - 1))
* sysdeps/unix/sysv/linux/i386/Makefile (CFLAGS-epoll_pwait.c):
Add -fomit-frame-pointer.
(CFLAGS-mmap.c): Likewise.
(CFLAGS-mmap64.c): Likewise.
(CFLAGS-semtimedop.c): Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: New file.
* sysdeps/unix/sysv/linux/i386/mmap.S: Remove file.
* sysdeps/unix/sysv/linux/i386/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/i386/semtimedop.S: Likewise.
2015-10-15 11:33:15 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include <errno.h>
|
Consolidate Linux mmap implementation (BZ#21270)
This patch consolidates all Linux mmap implementations on default
sysdeps/unix/sysv/linux/mmap{64}.c one. To accomodate all required
architecture specific requeriments a new internal header is created
(mmap_internal.h) where each architecture add its specific code
requirements. Currently only x86_64 (to define MMAP_PREPARE to add
MAP_32BITS), s390 (which have a different kernel ABI for mmap), m68k
(which have variable minimum page sizes), and MIPS n32 (which zero
extend the offset to handle negative one correctly) redefine the new
header.
The patch also fixes BZ#21270 where default mmap64 on architectures
which uses mmap2 silent truncates large offsets value (larger than
1 << (page shift + 8 * sizeof (off_t)) or 1<<44 on architectures with
4096 bytes page size). The new consolidate implementation returns
EINVAL as allowed by POSIX.
It also adds a tests for on current tst-mmap-offset one. I have run
a full make check on x86_64, x86_64-32, i686, aarch64, armhf, powerpc,
powerpc64le, sparc64, and sparcv9 without any regressions. I also ran
some basic tests (tst-mmap-offset) on sh4, m68k, and on qemu simulated
MIPS32 and MIPS64.
[BZ #21270]
* posix/tst-mmap-offset.c (do_prepare): New function.
(do_test): Rename to do_test_bz18877 and use FAIL_RET.
(do_test_bz21270): New function.
* sysdeps/unix/sysv/linux/aarch64/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/arm/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/hppa/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/microblaze/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mmap_internal.h: New file.
* sysdeps/unix/sysv/linux/m68k/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/s390/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list: Remove mmap
from auto-generation list.
* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/mmap.c: New file.
* sysdeps/unix/sysv/linux/mmap64.c (__mmap64): Add check for invalid
offsets and support for mmap2 syscall.
2017-04-06 20:01:56 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mman.h>
|
i386: Remove syscall assembly codes with 6 arguments
This patch removes i386 assembly implementation for mmap, mmap64,
semtimeop now that i386 have 6 argument syscall support from C code
and GCC 5 can inline syscalls with 6 arguments. We also compile mmap.c,
mmap64.c and semtimedop.c with -fomit-frame-pointer since %ebp may be
used to pass the 6th argument to syscall.
Fo sysdeps/unix/sysv/linux/i386/mmap.c, with -O2 -march=i686
-mtune=generic, GCC 5.2 now generates:
<__mmap>:
0: sub $0x10,%esp
3: mov 0x28(%esp),%eax
7: mov %ebx,(%esp)
a: mov 0x18(%esp),%ecx
e: mov %esi,0x4(%esp)
12: mov 0x14(%esp),%ebx
16: mov %edi,0x8(%esp)
1a: mov 0x1c(%esp),%edx
1e: test $0xfff,%eax
23: mov 0x20(%esp),%esi
27: mov %ebp,0xc(%esp)
2b: mov 0x24(%esp),%edi
2f: jne 60 <__mmap+0x60>
31: shr $0xc,%eax
34: mov %eax,%ebp
36: mov $0xc0,%eax
3b: call *%gs:0x10
42: cmp $0xfffff000,%eax
47: ja 65 <__mmap+0x65>
49: mov (%esp),%ebx
4c: mov 0x4(%esp),%esi
50: mov 0x8(%esp),%edi
54: mov 0xc(%esp),%ebp
58: add $0x10,%esp
5b: ret
5c: lea 0x0(%esi,%eiz,1),%esi
60: mov $0xffffffea,%eax
65: mov (%esp),%ebx
68: mov 0x4(%esp),%esi
6c: mov 0x8(%esp),%edi
70: mov 0xc(%esp),%ebp
74: add $0x10,%esp
77: jmp 78 <__mmap+0x78>
vs sysdeps/unix/sysv/linux/i386/mmap.S:
<__mmap>:
0: push %ebp
1: push %ebx
2: push %esi
3: push %edi
4: mov 0x14(%esp),%ebx
8: mov 0x18(%esp),%ecx
c: mov 0x1c(%esp),%edx
10: mov 0x20(%esp),%esi
14: mov 0x24(%esp),%edi
18: mov 0x28(%esp),%ebp
1c: test $0xfff,%ebp
22: mov $0xffffffea,%eax
27: jne 38 <__mmap+0x38>
29: shr $0xc,%ebp
2c: mov $0xc0,%eax
31: call *%gs:0x10
38: pop %edi
39: pop %esi
3a: pop %ebx
3b: pop %ebp
3c: cmp $0xfffff000,%eax
41: ja 44 <__mmap+0x44>
43: ret
44: call 45 <__mmap+0x45> 45: R_386_PC32 __x86.get_pc_thunk.cx
49: add $0x2,%ecx 4b: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
4f: mov 0x0(%ecx),%ecx 51: R_386_TLS_GOTIE __libc_errno
55: neg %eax
57: mov %eax,%gs:(%ecx)
5a: or $0xffffffff,%eax
5d: ret
The C version has:
3: mov 0x28(%esp),%eax
...
1e: test $0xfff,%eax
...
31: sar $0xc,%eax
34: mov %eax,%ebp
is due to missing $ebx register constraint for inline asm. We have
to use "r" constraint with
register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6);
and compiler chose %eax for offset (arg6) in
if (offset & (MMAP_PAGE_UNIT - 1))
* sysdeps/unix/sysv/linux/i386/Makefile (CFLAGS-epoll_pwait.c):
Add -fomit-frame-pointer.
(CFLAGS-mmap.c): Likewise.
(CFLAGS-mmap64.c): Likewise.
(CFLAGS-semtimedop.c): Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: New file.
* sysdeps/unix/sysv/linux/i386/mmap.S: Remove file.
* sysdeps/unix/sysv/linux/i386/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/i386/semtimedop.S: Likewise.
2015-10-15 11:33:15 +00:00
|
|
|
#include <sysdep.h>
|
Consolidate Linux mmap implementation (BZ#21270)
This patch consolidates all Linux mmap implementations on default
sysdeps/unix/sysv/linux/mmap{64}.c one. To accomodate all required
architecture specific requeriments a new internal header is created
(mmap_internal.h) where each architecture add its specific code
requirements. Currently only x86_64 (to define MMAP_PREPARE to add
MAP_32BITS), s390 (which have a different kernel ABI for mmap), m68k
(which have variable minimum page sizes), and MIPS n32 (which zero
extend the offset to handle negative one correctly) redefine the new
header.
The patch also fixes BZ#21270 where default mmap64 on architectures
which uses mmap2 silent truncates large offsets value (larger than
1 << (page shift + 8 * sizeof (off_t)) or 1<<44 on architectures with
4096 bytes page size). The new consolidate implementation returns
EINVAL as allowed by POSIX.
It also adds a tests for on current tst-mmap-offset one. I have run
a full make check on x86_64, x86_64-32, i686, aarch64, armhf, powerpc,
powerpc64le, sparc64, and sparcv9 without any regressions. I also ran
some basic tests (tst-mmap-offset) on sh4, m68k, and on qemu simulated
MIPS32 and MIPS64.
[BZ #21270]
* posix/tst-mmap-offset.c (do_prepare): New function.
(do_test): Rename to do_test_bz18877 and use FAIL_RET.
(do_test_bz21270): New function.
* sysdeps/unix/sysv/linux/aarch64/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/arm/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/hppa/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/microblaze/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mmap_internal.h: New file.
* sysdeps/unix/sysv/linux/m68k/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/s390/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list: Remove mmap
from auto-generation list.
* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/mmap.c: New file.
* sysdeps/unix/sysv/linux/mmap64.c (__mmap64): Add check for invalid
offsets and support for mmap2 syscall.
2017-04-06 20:01:56 +00:00
|
|
|
#include <stdint.h>
|
i386: Remove syscall assembly codes with 6 arguments
This patch removes i386 assembly implementation for mmap, mmap64,
semtimeop now that i386 have 6 argument syscall support from C code
and GCC 5 can inline syscalls with 6 arguments. We also compile mmap.c,
mmap64.c and semtimedop.c with -fomit-frame-pointer since %ebp may be
used to pass the 6th argument to syscall.
Fo sysdeps/unix/sysv/linux/i386/mmap.c, with -O2 -march=i686
-mtune=generic, GCC 5.2 now generates:
<__mmap>:
0: sub $0x10,%esp
3: mov 0x28(%esp),%eax
7: mov %ebx,(%esp)
a: mov 0x18(%esp),%ecx
e: mov %esi,0x4(%esp)
12: mov 0x14(%esp),%ebx
16: mov %edi,0x8(%esp)
1a: mov 0x1c(%esp),%edx
1e: test $0xfff,%eax
23: mov 0x20(%esp),%esi
27: mov %ebp,0xc(%esp)
2b: mov 0x24(%esp),%edi
2f: jne 60 <__mmap+0x60>
31: shr $0xc,%eax
34: mov %eax,%ebp
36: mov $0xc0,%eax
3b: call *%gs:0x10
42: cmp $0xfffff000,%eax
47: ja 65 <__mmap+0x65>
49: mov (%esp),%ebx
4c: mov 0x4(%esp),%esi
50: mov 0x8(%esp),%edi
54: mov 0xc(%esp),%ebp
58: add $0x10,%esp
5b: ret
5c: lea 0x0(%esi,%eiz,1),%esi
60: mov $0xffffffea,%eax
65: mov (%esp),%ebx
68: mov 0x4(%esp),%esi
6c: mov 0x8(%esp),%edi
70: mov 0xc(%esp),%ebp
74: add $0x10,%esp
77: jmp 78 <__mmap+0x78>
vs sysdeps/unix/sysv/linux/i386/mmap.S:
<__mmap>:
0: push %ebp
1: push %ebx
2: push %esi
3: push %edi
4: mov 0x14(%esp),%ebx
8: mov 0x18(%esp),%ecx
c: mov 0x1c(%esp),%edx
10: mov 0x20(%esp),%esi
14: mov 0x24(%esp),%edi
18: mov 0x28(%esp),%ebp
1c: test $0xfff,%ebp
22: mov $0xffffffea,%eax
27: jne 38 <__mmap+0x38>
29: shr $0xc,%ebp
2c: mov $0xc0,%eax
31: call *%gs:0x10
38: pop %edi
39: pop %esi
3a: pop %ebx
3b: pop %ebp
3c: cmp $0xfffff000,%eax
41: ja 44 <__mmap+0x44>
43: ret
44: call 45 <__mmap+0x45> 45: R_386_PC32 __x86.get_pc_thunk.cx
49: add $0x2,%ecx 4b: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
4f: mov 0x0(%ecx),%ecx 51: R_386_TLS_GOTIE __libc_errno
55: neg %eax
57: mov %eax,%gs:(%ecx)
5a: or $0xffffffff,%eax
5d: ret
The C version has:
3: mov 0x28(%esp),%eax
...
1e: test $0xfff,%eax
...
31: sar $0xc,%eax
34: mov %eax,%ebp
is due to missing $ebx register constraint for inline asm. We have
to use "r" constraint with
register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6);
and compiler chose %eax for offset (arg6) in
if (offset & (MMAP_PAGE_UNIT - 1))
* sysdeps/unix/sysv/linux/i386/Makefile (CFLAGS-epoll_pwait.c):
Add -fomit-frame-pointer.
(CFLAGS-mmap.c): Likewise.
(CFLAGS-mmap64.c): Likewise.
(CFLAGS-semtimedop.c): Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: New file.
* sysdeps/unix/sysv/linux/i386/mmap.S: Remove file.
* sysdeps/unix/sysv/linux/i386/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/i386/semtimedop.S: Likewise.
2015-10-15 11:33:15 +00:00
|
|
|
|
Consolidate Linux mmap implementation (BZ#21270)
This patch consolidates all Linux mmap implementations on default
sysdeps/unix/sysv/linux/mmap{64}.c one. To accomodate all required
architecture specific requeriments a new internal header is created
(mmap_internal.h) where each architecture add its specific code
requirements. Currently only x86_64 (to define MMAP_PREPARE to add
MAP_32BITS), s390 (which have a different kernel ABI for mmap), m68k
(which have variable minimum page sizes), and MIPS n32 (which zero
extend the offset to handle negative one correctly) redefine the new
header.
The patch also fixes BZ#21270 where default mmap64 on architectures
which uses mmap2 silent truncates large offsets value (larger than
1 << (page shift + 8 * sizeof (off_t)) or 1<<44 on architectures with
4096 bytes page size). The new consolidate implementation returns
EINVAL as allowed by POSIX.
It also adds a tests for on current tst-mmap-offset one. I have run
a full make check on x86_64, x86_64-32, i686, aarch64, armhf, powerpc,
powerpc64le, sparc64, and sparcv9 without any regressions. I also ran
some basic tests (tst-mmap-offset) on sh4, m68k, and on qemu simulated
MIPS32 and MIPS64.
[BZ #21270]
* posix/tst-mmap-offset.c (do_prepare): New function.
(do_test): Rename to do_test_bz18877 and use FAIL_RET.
(do_test_bz21270): New function.
* sysdeps/unix/sysv/linux/aarch64/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/arm/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/hppa/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/microblaze/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mmap_internal.h: New file.
* sysdeps/unix/sysv/linux/m68k/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/s390/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list: Remove mmap
from auto-generation list.
* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/mmap.c: New file.
* sysdeps/unix/sysv/linux/mmap64.c (__mmap64): Add check for invalid
offsets and support for mmap2 syscall.
2017-04-06 20:01:56 +00:00
|
|
|
#ifndef __OFF_T_MATCHES_OFF64_T
|
2017-08-06 14:14:32 +00:00
|
|
|
# include <mmap_internal.h>
|
i386: Remove syscall assembly codes with 6 arguments
This patch removes i386 assembly implementation for mmap, mmap64,
semtimeop now that i386 have 6 argument syscall support from C code
and GCC 5 can inline syscalls with 6 arguments. We also compile mmap.c,
mmap64.c and semtimedop.c with -fomit-frame-pointer since %ebp may be
used to pass the 6th argument to syscall.
Fo sysdeps/unix/sysv/linux/i386/mmap.c, with -O2 -march=i686
-mtune=generic, GCC 5.2 now generates:
<__mmap>:
0: sub $0x10,%esp
3: mov 0x28(%esp),%eax
7: mov %ebx,(%esp)
a: mov 0x18(%esp),%ecx
e: mov %esi,0x4(%esp)
12: mov 0x14(%esp),%ebx
16: mov %edi,0x8(%esp)
1a: mov 0x1c(%esp),%edx
1e: test $0xfff,%eax
23: mov 0x20(%esp),%esi
27: mov %ebp,0xc(%esp)
2b: mov 0x24(%esp),%edi
2f: jne 60 <__mmap+0x60>
31: shr $0xc,%eax
34: mov %eax,%ebp
36: mov $0xc0,%eax
3b: call *%gs:0x10
42: cmp $0xfffff000,%eax
47: ja 65 <__mmap+0x65>
49: mov (%esp),%ebx
4c: mov 0x4(%esp),%esi
50: mov 0x8(%esp),%edi
54: mov 0xc(%esp),%ebp
58: add $0x10,%esp
5b: ret
5c: lea 0x0(%esi,%eiz,1),%esi
60: mov $0xffffffea,%eax
65: mov (%esp),%ebx
68: mov 0x4(%esp),%esi
6c: mov 0x8(%esp),%edi
70: mov 0xc(%esp),%ebp
74: add $0x10,%esp
77: jmp 78 <__mmap+0x78>
vs sysdeps/unix/sysv/linux/i386/mmap.S:
<__mmap>:
0: push %ebp
1: push %ebx
2: push %esi
3: push %edi
4: mov 0x14(%esp),%ebx
8: mov 0x18(%esp),%ecx
c: mov 0x1c(%esp),%edx
10: mov 0x20(%esp),%esi
14: mov 0x24(%esp),%edi
18: mov 0x28(%esp),%ebp
1c: test $0xfff,%ebp
22: mov $0xffffffea,%eax
27: jne 38 <__mmap+0x38>
29: shr $0xc,%ebp
2c: mov $0xc0,%eax
31: call *%gs:0x10
38: pop %edi
39: pop %esi
3a: pop %ebx
3b: pop %ebp
3c: cmp $0xfffff000,%eax
41: ja 44 <__mmap+0x44>
43: ret
44: call 45 <__mmap+0x45> 45: R_386_PC32 __x86.get_pc_thunk.cx
49: add $0x2,%ecx 4b: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
4f: mov 0x0(%ecx),%ecx 51: R_386_TLS_GOTIE __libc_errno
55: neg %eax
57: mov %eax,%gs:(%ecx)
5a: or $0xffffffff,%eax
5d: ret
The C version has:
3: mov 0x28(%esp),%eax
...
1e: test $0xfff,%eax
...
31: sar $0xc,%eax
34: mov %eax,%ebp
is due to missing $ebx register constraint for inline asm. We have
to use "r" constraint with
register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6);
and compiler chose %eax for offset (arg6) in
if (offset & (MMAP_PAGE_UNIT - 1))
* sysdeps/unix/sysv/linux/i386/Makefile (CFLAGS-epoll_pwait.c):
Add -fomit-frame-pointer.
(CFLAGS-mmap.c): Likewise.
(CFLAGS-mmap64.c): Likewise.
(CFLAGS-semtimedop.c): Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: New file.
* sysdeps/unix/sysv/linux/i386/mmap.S: Remove file.
* sysdeps/unix/sysv/linux/i386/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/i386/semtimedop.S: Likewise.
2015-10-15 11:33:15 +00:00
|
|
|
|
Consolidate Linux mmap implementation (BZ#21270)
This patch consolidates all Linux mmap implementations on default
sysdeps/unix/sysv/linux/mmap{64}.c one. To accomodate all required
architecture specific requeriments a new internal header is created
(mmap_internal.h) where each architecture add its specific code
requirements. Currently only x86_64 (to define MMAP_PREPARE to add
MAP_32BITS), s390 (which have a different kernel ABI for mmap), m68k
(which have variable minimum page sizes), and MIPS n32 (which zero
extend the offset to handle negative one correctly) redefine the new
header.
The patch also fixes BZ#21270 where default mmap64 on architectures
which uses mmap2 silent truncates large offsets value (larger than
1 << (page shift + 8 * sizeof (off_t)) or 1<<44 on architectures with
4096 bytes page size). The new consolidate implementation returns
EINVAL as allowed by POSIX.
It also adds a tests for on current tst-mmap-offset one. I have run
a full make check on x86_64, x86_64-32, i686, aarch64, armhf, powerpc,
powerpc64le, sparc64, and sparcv9 without any regressions. I also ran
some basic tests (tst-mmap-offset) on sh4, m68k, and on qemu simulated
MIPS32 and MIPS64.
[BZ #21270]
* posix/tst-mmap-offset.c (do_prepare): New function.
(do_test): Rename to do_test_bz18877 and use FAIL_RET.
(do_test_bz21270): New function.
* sysdeps/unix/sysv/linux/aarch64/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/arm/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/hppa/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/microblaze/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mmap_internal.h: New file.
* sysdeps/unix/sysv/linux/m68k/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/s390/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list: Remove mmap
from auto-generation list.
* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/mmap.c: New file.
* sysdeps/unix/sysv/linux/mmap64.c (__mmap64): Add check for invalid
offsets and support for mmap2 syscall.
2017-04-06 20:01:56 +00:00
|
|
|
/* An architecture may override this. */
|
|
|
|
# ifndef MMAP_ADJUST_OFFSET
|
|
|
|
# define MMAP_ADJUST_OFFSET(offset) offset
|
|
|
|
# endif
|
|
|
|
|
|
|
|
void *
|
|
|
|
__mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
|
i386: Remove syscall assembly codes with 6 arguments
This patch removes i386 assembly implementation for mmap, mmap64,
semtimeop now that i386 have 6 argument syscall support from C code
and GCC 5 can inline syscalls with 6 arguments. We also compile mmap.c,
mmap64.c and semtimedop.c with -fomit-frame-pointer since %ebp may be
used to pass the 6th argument to syscall.
Fo sysdeps/unix/sysv/linux/i386/mmap.c, with -O2 -march=i686
-mtune=generic, GCC 5.2 now generates:
<__mmap>:
0: sub $0x10,%esp
3: mov 0x28(%esp),%eax
7: mov %ebx,(%esp)
a: mov 0x18(%esp),%ecx
e: mov %esi,0x4(%esp)
12: mov 0x14(%esp),%ebx
16: mov %edi,0x8(%esp)
1a: mov 0x1c(%esp),%edx
1e: test $0xfff,%eax
23: mov 0x20(%esp),%esi
27: mov %ebp,0xc(%esp)
2b: mov 0x24(%esp),%edi
2f: jne 60 <__mmap+0x60>
31: shr $0xc,%eax
34: mov %eax,%ebp
36: mov $0xc0,%eax
3b: call *%gs:0x10
42: cmp $0xfffff000,%eax
47: ja 65 <__mmap+0x65>
49: mov (%esp),%ebx
4c: mov 0x4(%esp),%esi
50: mov 0x8(%esp),%edi
54: mov 0xc(%esp),%ebp
58: add $0x10,%esp
5b: ret
5c: lea 0x0(%esi,%eiz,1),%esi
60: mov $0xffffffea,%eax
65: mov (%esp),%ebx
68: mov 0x4(%esp),%esi
6c: mov 0x8(%esp),%edi
70: mov 0xc(%esp),%ebp
74: add $0x10,%esp
77: jmp 78 <__mmap+0x78>
vs sysdeps/unix/sysv/linux/i386/mmap.S:
<__mmap>:
0: push %ebp
1: push %ebx
2: push %esi
3: push %edi
4: mov 0x14(%esp),%ebx
8: mov 0x18(%esp),%ecx
c: mov 0x1c(%esp),%edx
10: mov 0x20(%esp),%esi
14: mov 0x24(%esp),%edi
18: mov 0x28(%esp),%ebp
1c: test $0xfff,%ebp
22: mov $0xffffffea,%eax
27: jne 38 <__mmap+0x38>
29: shr $0xc,%ebp
2c: mov $0xc0,%eax
31: call *%gs:0x10
38: pop %edi
39: pop %esi
3a: pop %ebx
3b: pop %ebp
3c: cmp $0xfffff000,%eax
41: ja 44 <__mmap+0x44>
43: ret
44: call 45 <__mmap+0x45> 45: R_386_PC32 __x86.get_pc_thunk.cx
49: add $0x2,%ecx 4b: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
4f: mov 0x0(%ecx),%ecx 51: R_386_TLS_GOTIE __libc_errno
55: neg %eax
57: mov %eax,%gs:(%ecx)
5a: or $0xffffffff,%eax
5d: ret
The C version has:
3: mov 0x28(%esp),%eax
...
1e: test $0xfff,%eax
...
31: sar $0xc,%eax
34: mov %eax,%ebp
is due to missing $ebx register constraint for inline asm. We have
to use "r" constraint with
register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6);
and compiler chose %eax for offset (arg6) in
if (offset & (MMAP_PAGE_UNIT - 1))
* sysdeps/unix/sysv/linux/i386/Makefile (CFLAGS-epoll_pwait.c):
Add -fomit-frame-pointer.
(CFLAGS-mmap.c): Likewise.
(CFLAGS-mmap64.c): Likewise.
(CFLAGS-semtimedop.c): Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: New file.
* sysdeps/unix/sysv/linux/i386/mmap.S: Remove file.
* sysdeps/unix/sysv/linux/i386/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/i386/semtimedop.S: Likewise.
2015-10-15 11:33:15 +00:00
|
|
|
{
|
Consolidate Linux mmap implementation (BZ#21270)
This patch consolidates all Linux mmap implementations on default
sysdeps/unix/sysv/linux/mmap{64}.c one. To accomodate all required
architecture specific requeriments a new internal header is created
(mmap_internal.h) where each architecture add its specific code
requirements. Currently only x86_64 (to define MMAP_PREPARE to add
MAP_32BITS), s390 (which have a different kernel ABI for mmap), m68k
(which have variable minimum page sizes), and MIPS n32 (which zero
extend the offset to handle negative one correctly) redefine the new
header.
The patch also fixes BZ#21270 where default mmap64 on architectures
which uses mmap2 silent truncates large offsets value (larger than
1 << (page shift + 8 * sizeof (off_t)) or 1<<44 on architectures with
4096 bytes page size). The new consolidate implementation returns
EINVAL as allowed by POSIX.
It also adds a tests for on current tst-mmap-offset one. I have run
a full make check on x86_64, x86_64-32, i686, aarch64, armhf, powerpc,
powerpc64le, sparc64, and sparcv9 without any regressions. I also ran
some basic tests (tst-mmap-offset) on sh4, m68k, and on qemu simulated
MIPS32 and MIPS64.
[BZ #21270]
* posix/tst-mmap-offset.c (do_prepare): New function.
(do_test): Rename to do_test_bz18877 and use FAIL_RET.
(do_test_bz21270): New function.
* sysdeps/unix/sysv/linux/aarch64/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/arm/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/hppa/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/microblaze/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mmap_internal.h: New file.
* sysdeps/unix/sysv/linux/m68k/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/s390/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list: Remove mmap
from auto-generation list.
* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/mmap.c: New file.
* sysdeps/unix/sysv/linux/mmap64.c (__mmap64): Add check for invalid
offsets and support for mmap2 syscall.
2017-04-06 20:01:56 +00:00
|
|
|
MMAP_CHECK_PAGE_UNIT ();
|
|
|
|
|
|
|
|
if (offset & MMAP_OFF_LOW_MASK)
|
2017-08-08 17:14:49 +00:00
|
|
|
return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
|
i386: Remove syscall assembly codes with 6 arguments
This patch removes i386 assembly implementation for mmap, mmap64,
semtimeop now that i386 have 6 argument syscall support from C code
and GCC 5 can inline syscalls with 6 arguments. We also compile mmap.c,
mmap64.c and semtimedop.c with -fomit-frame-pointer since %ebp may be
used to pass the 6th argument to syscall.
Fo sysdeps/unix/sysv/linux/i386/mmap.c, with -O2 -march=i686
-mtune=generic, GCC 5.2 now generates:
<__mmap>:
0: sub $0x10,%esp
3: mov 0x28(%esp),%eax
7: mov %ebx,(%esp)
a: mov 0x18(%esp),%ecx
e: mov %esi,0x4(%esp)
12: mov 0x14(%esp),%ebx
16: mov %edi,0x8(%esp)
1a: mov 0x1c(%esp),%edx
1e: test $0xfff,%eax
23: mov 0x20(%esp),%esi
27: mov %ebp,0xc(%esp)
2b: mov 0x24(%esp),%edi
2f: jne 60 <__mmap+0x60>
31: shr $0xc,%eax
34: mov %eax,%ebp
36: mov $0xc0,%eax
3b: call *%gs:0x10
42: cmp $0xfffff000,%eax
47: ja 65 <__mmap+0x65>
49: mov (%esp),%ebx
4c: mov 0x4(%esp),%esi
50: mov 0x8(%esp),%edi
54: mov 0xc(%esp),%ebp
58: add $0x10,%esp
5b: ret
5c: lea 0x0(%esi,%eiz,1),%esi
60: mov $0xffffffea,%eax
65: mov (%esp),%ebx
68: mov 0x4(%esp),%esi
6c: mov 0x8(%esp),%edi
70: mov 0xc(%esp),%ebp
74: add $0x10,%esp
77: jmp 78 <__mmap+0x78>
vs sysdeps/unix/sysv/linux/i386/mmap.S:
<__mmap>:
0: push %ebp
1: push %ebx
2: push %esi
3: push %edi
4: mov 0x14(%esp),%ebx
8: mov 0x18(%esp),%ecx
c: mov 0x1c(%esp),%edx
10: mov 0x20(%esp),%esi
14: mov 0x24(%esp),%edi
18: mov 0x28(%esp),%ebp
1c: test $0xfff,%ebp
22: mov $0xffffffea,%eax
27: jne 38 <__mmap+0x38>
29: shr $0xc,%ebp
2c: mov $0xc0,%eax
31: call *%gs:0x10
38: pop %edi
39: pop %esi
3a: pop %ebx
3b: pop %ebp
3c: cmp $0xfffff000,%eax
41: ja 44 <__mmap+0x44>
43: ret
44: call 45 <__mmap+0x45> 45: R_386_PC32 __x86.get_pc_thunk.cx
49: add $0x2,%ecx 4b: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
4f: mov 0x0(%ecx),%ecx 51: R_386_TLS_GOTIE __libc_errno
55: neg %eax
57: mov %eax,%gs:(%ecx)
5a: or $0xffffffff,%eax
5d: ret
The C version has:
3: mov 0x28(%esp),%eax
...
1e: test $0xfff,%eax
...
31: sar $0xc,%eax
34: mov %eax,%ebp
is due to missing $ebx register constraint for inline asm. We have
to use "r" constraint with
register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6);
and compiler chose %eax for offset (arg6) in
if (offset & (MMAP_PAGE_UNIT - 1))
* sysdeps/unix/sysv/linux/i386/Makefile (CFLAGS-epoll_pwait.c):
Add -fomit-frame-pointer.
(CFLAGS-mmap.c): Likewise.
(CFLAGS-mmap64.c): Likewise.
(CFLAGS-semtimedop.c): Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: New file.
* sysdeps/unix/sysv/linux/i386/mmap.S: Remove file.
* sysdeps/unix/sysv/linux/i386/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/i386/semtimedop.S: Likewise.
2015-10-15 11:33:15 +00:00
|
|
|
|
Consolidate Linux mmap implementation (BZ#21270)
This patch consolidates all Linux mmap implementations on default
sysdeps/unix/sysv/linux/mmap{64}.c one. To accomodate all required
architecture specific requeriments a new internal header is created
(mmap_internal.h) where each architecture add its specific code
requirements. Currently only x86_64 (to define MMAP_PREPARE to add
MAP_32BITS), s390 (which have a different kernel ABI for mmap), m68k
(which have variable minimum page sizes), and MIPS n32 (which zero
extend the offset to handle negative one correctly) redefine the new
header.
The patch also fixes BZ#21270 where default mmap64 on architectures
which uses mmap2 silent truncates large offsets value (larger than
1 << (page shift + 8 * sizeof (off_t)) or 1<<44 on architectures with
4096 bytes page size). The new consolidate implementation returns
EINVAL as allowed by POSIX.
It also adds a tests for on current tst-mmap-offset one. I have run
a full make check on x86_64, x86_64-32, i686, aarch64, armhf, powerpc,
powerpc64le, sparc64, and sparcv9 without any regressions. I also ran
some basic tests (tst-mmap-offset) on sh4, m68k, and on qemu simulated
MIPS32 and MIPS64.
[BZ #21270]
* posix/tst-mmap-offset.c (do_prepare): New function.
(do_test): Rename to do_test_bz18877 and use FAIL_RET.
(do_test_bz21270): New function.
* sysdeps/unix/sysv/linux/aarch64/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/arm/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/hppa/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/microblaze/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mmap_internal.h: New file.
* sysdeps/unix/sysv/linux/m68k/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/s390/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list: Remove mmap
from auto-generation list.
* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/mmap.c: New file.
* sysdeps/unix/sysv/linux/mmap64.c (__mmap64): Add check for invalid
offsets and support for mmap2 syscall.
2017-04-06 20:01:56 +00:00
|
|
|
#ifdef __NR_mmap2
|
|
|
|
return (void *) MMAP_CALL (mmap2, addr, len, prot, flags, fd,
|
|
|
|
offset / (uint32_t) MMAP2_PAGE_UNIT);
|
|
|
|
#else
|
|
|
|
return (void *) MMAP_CALL (mmap, addr, len, prot, flags, fd,
|
|
|
|
MMAP_ADJUST_OFFSET (offset));
|
|
|
|
#endif
|
|
|
|
}
|
i386: Remove syscall assembly codes with 6 arguments
This patch removes i386 assembly implementation for mmap, mmap64,
semtimeop now that i386 have 6 argument syscall support from C code
and GCC 5 can inline syscalls with 6 arguments. We also compile mmap.c,
mmap64.c and semtimedop.c with -fomit-frame-pointer since %ebp may be
used to pass the 6th argument to syscall.
Fo sysdeps/unix/sysv/linux/i386/mmap.c, with -O2 -march=i686
-mtune=generic, GCC 5.2 now generates:
<__mmap>:
0: sub $0x10,%esp
3: mov 0x28(%esp),%eax
7: mov %ebx,(%esp)
a: mov 0x18(%esp),%ecx
e: mov %esi,0x4(%esp)
12: mov 0x14(%esp),%ebx
16: mov %edi,0x8(%esp)
1a: mov 0x1c(%esp),%edx
1e: test $0xfff,%eax
23: mov 0x20(%esp),%esi
27: mov %ebp,0xc(%esp)
2b: mov 0x24(%esp),%edi
2f: jne 60 <__mmap+0x60>
31: shr $0xc,%eax
34: mov %eax,%ebp
36: mov $0xc0,%eax
3b: call *%gs:0x10
42: cmp $0xfffff000,%eax
47: ja 65 <__mmap+0x65>
49: mov (%esp),%ebx
4c: mov 0x4(%esp),%esi
50: mov 0x8(%esp),%edi
54: mov 0xc(%esp),%ebp
58: add $0x10,%esp
5b: ret
5c: lea 0x0(%esi,%eiz,1),%esi
60: mov $0xffffffea,%eax
65: mov (%esp),%ebx
68: mov 0x4(%esp),%esi
6c: mov 0x8(%esp),%edi
70: mov 0xc(%esp),%ebp
74: add $0x10,%esp
77: jmp 78 <__mmap+0x78>
vs sysdeps/unix/sysv/linux/i386/mmap.S:
<__mmap>:
0: push %ebp
1: push %ebx
2: push %esi
3: push %edi
4: mov 0x14(%esp),%ebx
8: mov 0x18(%esp),%ecx
c: mov 0x1c(%esp),%edx
10: mov 0x20(%esp),%esi
14: mov 0x24(%esp),%edi
18: mov 0x28(%esp),%ebp
1c: test $0xfff,%ebp
22: mov $0xffffffea,%eax
27: jne 38 <__mmap+0x38>
29: shr $0xc,%ebp
2c: mov $0xc0,%eax
31: call *%gs:0x10
38: pop %edi
39: pop %esi
3a: pop %ebx
3b: pop %ebp
3c: cmp $0xfffff000,%eax
41: ja 44 <__mmap+0x44>
43: ret
44: call 45 <__mmap+0x45> 45: R_386_PC32 __x86.get_pc_thunk.cx
49: add $0x2,%ecx 4b: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
4f: mov 0x0(%ecx),%ecx 51: R_386_TLS_GOTIE __libc_errno
55: neg %eax
57: mov %eax,%gs:(%ecx)
5a: or $0xffffffff,%eax
5d: ret
The C version has:
3: mov 0x28(%esp),%eax
...
1e: test $0xfff,%eax
...
31: sar $0xc,%eax
34: mov %eax,%ebp
is due to missing $ebx register constraint for inline asm. We have
to use "r" constraint with
register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6);
and compiler chose %eax for offset (arg6) in
if (offset & (MMAP_PAGE_UNIT - 1))
* sysdeps/unix/sysv/linux/i386/Makefile (CFLAGS-epoll_pwait.c):
Add -fomit-frame-pointer.
(CFLAGS-mmap.c): Likewise.
(CFLAGS-mmap64.c): Likewise.
(CFLAGS-semtimedop.c): Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: New file.
* sysdeps/unix/sysv/linux/i386/mmap.S: Remove file.
* sysdeps/unix/sysv/linux/i386/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/i386/semtimedop.S: Likewise.
2015-10-15 11:33:15 +00:00
|
|
|
weak_alias (__mmap, mmap)
|
Clean pthread functions namespaces for C11 threads
This patch adds internal definition (through {libc_}hidden_{proto,def}) and
also change some strong to weak alias for symbols that might be used by C11
threads implementations.
The patchset should not change libc/libpthread functional, although object
changes are expected (since now internal symbols are used instead) and final
exported symbols through GLIBC_PRIVATE is also expanded (to cover libpthread
usage of __mmap{64}, __munmap, __mprotect).
Checked with a build for all major ABI (aarch64-linux-gnu, alpha-linux-gnu,
arm-linux-gnueabi, i386-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,
microblaze-linux-gnu [1], mips{64}-linux-gnu, nios2-linux-gnu,
powerpc{64le}-linux-gnu, s390{x}-linux-gnu, sparc{64}-linux-gnu,
tile{pro,gx}-linux-gnu, and x86_64-linux-gnu).
* include/sched.h (__sched_get_priority_max): Add libc hidden proto.
(__sched_get_prioriry_min): Likewise.
* include/sys/mman.h (__mmap): Likewise.
(__mmap64): Likewise.
(__munmap): Likewise.
(__mprotect): Likewise.
* include/termios.h (__tcsetattr): Likewise.
* include/time.h (__nanosleep): Use hidden_proto instead of
libc_hidden_proto.
* posix/nanosleep.c (__nanosleep): Likewise.
* misc/Versions (libc): Export __mmap, __munmap, __mprotect,
__sched_get_priority_min, and __sched_get_priority_max under
GLIBC_PRIVATE.
* nptl/allocatestack.c (__free_stacks): Use internal definition for
libc symbols.
(change_stack_perm): Likewise.
(allocate_stack): Likewise.
* sysdeps/posix/gethostname.c: Likewise.
* nptl/tpp.c (__init_sched_fifo_prio): Likewise.
* sysdeps/unix/sysv/linux/i386/smp.h (is_smp_system): Likewise.
* sysdeps/unix/sysv/linux/powerpc/ioctl.c (__ioctl): Likewise.
* nptl/pthreadP.h (__pthread_mutex_timedlock): Add definition.
(__pthread_key_delete): Likewise.
(__pthread_detach): Likewise.
(__pthread_cancel): Likewise.
(__pthread_mutex_trylock): Likewise.
(__pthread_mutexattr_init): Likewise.
(__pthread_mutexattr_settype): Likewise.
* nptl/pthread_cancel.c (pthread_cancel): Change to internal name and
create alias for exported one.
* nptl/pthread_join.c (pthread_join): Likewise.
* nptl/pthread_detach.c (pthread_detach): Likewise.
* nptl/pthread_key_delete.c (pthread_key_delete): Likewise.
* nptl/pthread_mutex_timedlock.c (pthread_mutex_timedlock): Likewise.
* nptl/pthread_create.c: Change static requirements for pthread
symbols.
* nptl/pthread_equal.c (__pthread_equal): Change strong alias to weak
for internal definition.
* nptl/pthread_exit.c (__pthread_exit): Likewise.
* nptl/pthread_getspecific.c (__pthread_getspecific): Likewise.
* nptl/pthread_key_create.c (__pthread_key_create): Likewise.
* nptl/pthread_mutex_destroy.c (__pthread_mutex_destroy): Likewise.
* nptl/pthread_mutex_init.c (__pthread_mutex_init): Likewise.
* nptl/pthread_mutex_lock.c (__pthread_mutex_lock): Likewise.
* nptl/pthread_mutex_trylock.c (__pthread_mutex_trylock): Likewise.
* nptl/pthread_mutex_unlock.c (__pthread_mutex_unlock): Likewise.
* nptl/pthread_mutexattr_init.c (__pthread_mutexattr_init): Likwise.
* nptl/pthread_mutexattr_settype.c (__pthread_mutexattr_settype):
Likewise.
* nptl/pthread_self.c (__pthread_self): Likewise.
* nptl/pthread_setspecific.c (__pthread_setspecific): Likewise.
* sysdeps/unix/sysv/linux/tcsetattr.c (tcsetattr): Likewise.
* misc/mmap.c (__mmap): Add internal symbol definition.
* misc/mmap.c (__mmap64): Likewise.
* sysdeps/unix/sysv/linux/mmap.c (__mmap): Likewise.
* sysdeps/unix/sysv/linux/mmap64.c (__mmap): Likewise.
(__mmap64): Likewise.
* sysdeps/unix/sysv/linux/i386/Versions (libc) [GLIBC_PRIVATE):
Add __uname.
2016-12-02 18:32:28 +00:00
|
|
|
libc_hidden_def (__mmap)
|
Consolidate Linux mmap implementation (BZ#21270)
This patch consolidates all Linux mmap implementations on default
sysdeps/unix/sysv/linux/mmap{64}.c one. To accomodate all required
architecture specific requeriments a new internal header is created
(mmap_internal.h) where each architecture add its specific code
requirements. Currently only x86_64 (to define MMAP_PREPARE to add
MAP_32BITS), s390 (which have a different kernel ABI for mmap), m68k
(which have variable minimum page sizes), and MIPS n32 (which zero
extend the offset to handle negative one correctly) redefine the new
header.
The patch also fixes BZ#21270 where default mmap64 on architectures
which uses mmap2 silent truncates large offsets value (larger than
1 << (page shift + 8 * sizeof (off_t)) or 1<<44 on architectures with
4096 bytes page size). The new consolidate implementation returns
EINVAL as allowed by POSIX.
It also adds a tests for on current tst-mmap-offset one. I have run
a full make check on x86_64, x86_64-32, i686, aarch64, armhf, powerpc,
powerpc64le, sparc64, and sparcv9 without any regressions. I also ran
some basic tests (tst-mmap-offset) on sh4, m68k, and on qemu simulated
MIPS32 and MIPS64.
[BZ #21270]
* posix/tst-mmap-offset.c (do_prepare): New function.
(do_test): Rename to do_test_bz18877 and use FAIL_RET.
(do_test_bz21270): New function.
* sysdeps/unix/sysv/linux/aarch64/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/arm/mmap.c: Remove file.
* sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/hppa/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/i386/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/m68k/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/microblaze/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/mmap.S: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/mmap64.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
* sysdeps/unix/sysv/linux/mmap_internal.h: New file.
* sysdeps/unix/sysv/linux/m68k/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/s390/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list: Remove mmap
from auto-generation list.
* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/mmap.c: New file.
* sysdeps/unix/sysv/linux/mmap64.c (__mmap64): Add check for invalid
offsets and support for mmap2 syscall.
2017-04-06 20:01:56 +00:00
|
|
|
|
|
|
|
#endif /* __OFF_T_MATCHES_OFF64_T */
|