2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / i386 / mmap64.S
blobf53e6e8c68aca7f62d9be8fa91578f16683d2640
1 /* Copyright (C) 1995,96,97,98,99,2000,2002,2005,2006
2         Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
21 #include <bp-sym.h>
22 #include <bp-asm.h>
24 #include <kernel-features.h>
26 #define EINVAL  22
27 #define ENOSYS  38
29 #define SVRSP   16              /* saved register space */
30 #define PARMS   LINKAGE+SVRSP   /* space for 4 saved regs */
31 #define ADDR    PARMS
32 #define LEN     ADDR+PTR_SIZE
33 #define PROT    LEN+4
34 #define FLAGS   PROT+4
35 #define FD      FLAGS+4
36 #define OFFLO   FD+4
37 #define OFFHI   OFFLO+4
39         .text
40 ENTRY (BP_SYM (__mmap64))
42 #ifdef __NR_mmap2
44         /* Save registers.  */
45         pushl %ebp
46         cfi_adjust_cfa_offset (4)
47         pushl %ebx
48         cfi_adjust_cfa_offset (4)
49         pushl %esi
50         cfi_adjust_cfa_offset (4)
51         pushl %edi
52         cfi_adjust_cfa_offset (4)
54         movl OFFLO(%esp), %edx
55         movl OFFHI(%esp), %ecx
56         testl $0xfff, %edx
57         jne L(einval)
58         shrdl $12, %ecx, %edx           /* mmap2 takes the offset in pages.  */
59         shrl $12, %ecx
60         jne L(einval)
61         movl %edx, %ebp
62         cfi_rel_offset (ebp, 12)
64         movl ADDR(%esp), %ebx
65         cfi_rel_offset (ebx, 8)
66         movl LEN(%esp), %ecx
67         movl PROT(%esp), %edx
68         movl FLAGS(%esp), %esi
69         cfi_rel_offset (esi, 4)
70         movl FD(%esp), %edi
71         cfi_rel_offset (edi, 0)
73         movl $SYS_ify(mmap2), %eax      /* System call number in %eax.  */
75         /* Do the system call trap.  */
76 L(do_syscall):
77         ENTER_KERNEL
79         /* Restore registers.  */
80         popl %edi
81         cfi_adjust_cfa_offset (-4)
82         cfi_restore (edi)
83         popl %esi
84         cfi_adjust_cfa_offset (-4)
85         cfi_restore (esi)
86         popl %ebx
87         cfi_adjust_cfa_offset (-4)
88         cfi_restore (ebx)
89         popl %ebp
90         cfi_adjust_cfa_offset (-4)
91         cfi_restore (ebp)
93 #ifndef __ASSUME_MMAP2_SYSCALL
95         cmp $-ENOSYS, %eax
96         je 3f
97 #endif
99         /* If 0 > %eax > -4096 there was an error.  */
100         cmpl $-4096, %eax
101         ja SYSCALL_ERROR_LABEL
103         /* Successful; return the syscall's value.  */
104 L(pseudo_end):
105         ret
107         cfi_adjust_cfa_offset (16)
108         cfi_rel_offset (ebp, 12)
109         cfi_rel_offset (ebx, 8)
110         cfi_rel_offset (esi, 4)
111         cfi_rel_offset (edi, 0)
112         /* This means the offset value is too large.  */
113 L(einval):
114         popl %edi
115         cfi_adjust_cfa_offset (-4)
116         cfi_restore (edi)
117         popl %esi
118         cfi_adjust_cfa_offset (-4)
119         cfi_restore (esi)
120         popl %ebx
121         cfi_adjust_cfa_offset (-4)
122         cfi_restore (ebx)
123         popl %ebp
124         cfi_adjust_cfa_offset (-4)
125         cfi_restore (ebp)
126         movl $-EINVAL, %eax
127         jmp SYSCALL_ERROR_LABEL
128 #endif
130 #if !defined __ASSUME_MMAP2_SYSCALL || !defined __NR_mmap2
132         /* Save registers.  */
133         movl %ebx, %edx
134         cfi_register (ebx, edx)
136         cmpl $0, OFFHI-SVRSP(%esp)
137         jne L(einval2)
139         movl $SYS_ify(mmap), %eax       /* System call number in %eax.  */
141         lea ADDR-SVRSP(%esp), %ebx      /* Address of args is 1st arg.  */
143         /* Do the system call trap.  */
144         ENTER_KERNEL
146         /* Restore registers.  */
147         movl %edx, %ebx
148         cfi_restore (ebx)
150         /* If 0 > %eax > -4096 there was an error.  */
151         cmpl $-4096, %eax
152         ja SYSCALL_ERROR_LABEL
154         /* Successful; return the syscall's value.  */
155 #ifndef __NR_mmap2
156 L(pseudo_end):
157 #endif
158         ret
160         cfi_register (ebx, edx)
161 L(einval2):
162         movl %edx, %ebx
163         cfi_restore (ebx)
164         movl $-EINVAL, %eax
165         jmp SYSCALL_ERROR_LABEL
166 #endif
168 PSEUDO_END (BP_SYM (__mmap64))
170 weak_alias (BP_SYM (__mmap64), BP_SYM (mmap64))