]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/mmap64.S
* sysdeps/i386/fpu/s_frexp.S: Check bounds.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / mmap64.S
1 /* Copyright (C) 1995, 96, 97, 98, 99, 2000 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
18
19 #include <sysdep.h>
20 #include <bp-sym.h>
21 #include <bp-asm.h>
22
23 #include "kernel-features.h"
24
25 #define EINVAL 22
26 #define ENOSYS 38
27
28 #define SVRSP 16 /* saved register space */
29 #define PARMS LINKAGE+SVRSP /* space for 4 saved regs */
30 #define ADDR PARMS
31 #define LEN ADDR+PTR_SIZE
32 #define PROT LEN+4
33 #define FLAGS PROT+4
34 #define FD FLAGS+4
35 #define OFFLO FD+4
36 #define OFFHI OFFLO+4
37
38 .text
39 ENTRY (BP_SYM (__mmap64))
40
41 #ifdef __NR_mmap2
42
43 /* Save registers. */
44 pushl %ebp
45 pushl %ebx
46 pushl %esi
47 pushl %edi
48
49 movl OFFLO(%esp), %edx
50 movl OFFHI(%esp), %ecx
51 testl $0x3ff, %edx
52 jne L(einval)
53 shrdl $12, %ecx, %edx /* mmap2 takes the offset in pages. */
54 shrl $12, %ecx
55 jne L(einval)
56 movl %edx, %ebp
57
58 movl ADDR(%esp), %ebx
59 movl LEN(%esp), %ecx
60 movl PROT(%esp), %edx
61 movl FLAGS(%esp), %esi
62 movl FD(%esp), %edi
63
64 movl $SYS_ify(mmap2), %eax /* System call number in %eax. */
65
66 /* Do the system call trap. */
67 L(do_syscall):
68 int $0x80
69
70 /* Restore registers. */
71 popl %edi
72 popl %esi
73 popl %ebx
74 popl %ebp
75
76 #ifndef __ASSUME_MMAP2_SYSCALL
77 2:
78 cmp $-ENOSYS, %eax
79 je 3f
80 #endif
81
82 /* If 0 > %eax > -4096 there was an error. */
83 cmpl $-4096, %eax
84 ja SYSCALL_ERROR_LABEL
85
86 /* Successful; return the syscall's value. */
87 L(pseudo_end):
88 ret
89
90 /* This means the offset value is too large. */
91 L(einval):
92 popl %edi
93 popl %esi
94 popl %ebx
95 popl %ebp
96 movl $-EINVAL, %eax
97 jmp SYSCALL_ERROR_LABEL
98 #endif
99
100 #if !defined __ASSUME_MMAP2_SYSCALL || !defined __NR_mmap2
101 3:
102 /* Save registers. */
103 movl %ebx, %edx
104
105 cmpl $0, OFFHI-SVRSP(%esp)
106 jne L(einval2)
107
108 movl $SYS_ify(mmap), %eax /* System call number in %eax. */
109
110 lea ADDR-SVRSP(%esp), %ebx /* Address of args is 1st arg. */
111
112 /* Do the system call trap. */
113 int $0x80
114
115 /* Restore registers. */
116 movl %edx, %ebx
117
118 /* If 0 > %eax > -4096 there was an error. */
119 cmpl $-4096, %eax
120 ja SYSCALL_ERROR_LABEL
121
122 /* Successful; return the syscall's value. */
123 #ifndef __NR_mmap2
124 L(pseudo_end):
125 #endif
126 ret
127
128 L(einval2):
129 movl %edx, %ebx
130 movl $-EINVAL, %eax
131 jmp SYSCALL_ERROR_LABEL
132 #endif
133
134 PSEUDO_END (BP_SYM (__mmap64))
135
136 weak_alias (BP_SYM (__mmap64), BP_SYM (mmap64))