(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / sysv / linux / arm / mmap.S
blobcf6f253378cc6fb882547df2fb4c6a3c2b18cde4
1 /* Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
19 #include <sysdep.h>
20 #include <kernel-features.h>
22 #define EINVAL          22
24         .text
26 ENTRY (__mmap)
27 # ifdef __ASSUME_MMAP2_SYSCALL
28         /* This code is actually a couple of cycles slower than the
29            sys_mmap version below, so it might seem like a loss.  But the
30            code path inside the kernel is sufficiently much shorter to
31            make it a net gain to use mmap2 when it's known to be
32            available.  */
34         /* shuffle args */
35         str     r5, [sp, #-4]!
36         ldr     r5, [sp, #8]
37         str     r4, [sp, #-4]!
38         ldr     r4, [sp, #8]
40         /* convert offset to pages */
41         movs    ip, r5, lsl #20
42         bne     .Linval
43         mov     r5, r5, lsr #12
44         
45         /* do the syscall */
46         swi     SYS_ify (mmap2)
48         /* restore registers */
50         ldr     r4, [sp], #4
51         ldr     r5, [sp], #4
53         cmn     r0, $4096
54         RETINSTR(cc, lr)
55         b       PLTJMP(syscall_error)
57 .Linval:
58         mov     r0, #-EINVAL
59         b       2b
60 # else
61         /* Because we can only get five args through the syscall interface, and
62            mmap() takes six, we need to build a parameter block and pass its
63            address instead.  The 386 port does a similar trick.  */
65         /* This code previously moved sp into ip and stored the args using
66            stmdb ip!, {a1-a4}.  It did not modify sp, so the stack never had
67            to be restored after the syscall completed.  It saved an
68            instruction and meant no stack cleanup work was required.
70            This will not work in the case of a mmap call being interrupted
71            by a signal.  If the signal handler uses any stack the arguments
72            to mmap will be trashed.  The results of a restart of mmap are
73            then unpredictable. */
75         /* store args on the stack */
76         stmdb   sp!, {a1-a4}
78         /* do the syscall */
79         mov     a1, sp
80         swi     SYS_ify (mmap)
82         /* pop args off the stack. */
83         add     sp, sp, #16
85         cmn     r0, $4096
86         RETINSTR(cc, lr)
87         b       PLTJMP(syscall_error);
88 #endif
90 PSEUDO_END (__mmap)
92 weak_alias (__mmap, mmap)