]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/arm/mmap.S
Test for stack alignment.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / arm / mmap.S
1 /* Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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. */
18
19 #include <sysdep.h>
20 #include <kernel-features.h>
21
22 #define EINVAL 22
23
24 .text
25
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. */
33
34 /* shuffle args */
35 str r5, [sp, #-4]!
36 ldr r5, [sp, #8]
37 str r4, [sp, #-4]!
38 ldr r4, [sp, #8]
39
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)
47
48 /* restore registers */
49 2:
50 ldr r4, [sp], #4
51 ldr r5, [sp], #4
52
53 cmn r0, $4096
54 RETINSTR(cc, lr)
55 b PLTJMP(syscall_error)
56
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. */
64
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.
69
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. */
74
75 /* store args on the stack */
76 stmdb sp!, {a1-a4}
77
78 /* do the syscall */
79 mov a1, sp
80 swi SYS_ify (mmap)
81
82 /* pop args off the stack. */
83 add sp, sp, #16
84
85 cmn r0, $4096
86 RETINSTR(cc, lr)
87 b PLTJMP(syscall_error);
88 #endif
89
90 PSEUDO_END (__mmap)
91
92 weak_alias (__mmap, mmap)