2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / i386 / mmap.S
bloba1481feeb55e9124e1706fb57b3e27b67d1ef925
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>
22 #include <kernel-features.h>
24 #define EINVAL  22
26         .text
28 ENTRY (__mmap)
30 /* I don't think it is worthwhile trying to use mmap2 whenever it
31    is available.  Only use it when we are sure the syscall exists.  */
32 #ifdef __ASSUME_MMAP2_SYSCALL
34         /* Save registers.  */
35         pushl %ebp
36         cfi_adjust_cfa_offset (4)
37         pushl %ebx
38         cfi_adjust_cfa_offset (4)
39         pushl %esi
40         cfi_adjust_cfa_offset (4)
41         pushl %edi
42         cfi_adjust_cfa_offset (4)
44         movl 20(%esp), %ebx
45         cfi_rel_offset (ebx, 8)
46         movl 24(%esp), %ecx
47         movl 28(%esp), %edx
48         movl 32(%esp), %esi
49         cfi_rel_offset (esi, 4)
50         movl 36(%esp), %edi
51         cfi_rel_offset (edi, 0)
52         movl 40(%esp), %ebp
53         cfi_rel_offset (ebp, 12)
54         testl $0xfff, %ebp
55         movl $-EINVAL, %eax
56         jne L(skip)
57         shrl $12, %ebp                  /* mmap2 takes the offset in pages.  */
59         movl $SYS_ify(mmap2), %eax      /* System call number in %eax.  */
61         /* Do the system call trap.  */
62         ENTER_KERNEL
63 L(skip):
64         /* Restore registers.  */
65         popl %edi
66         cfi_adjust_cfa_offset (-4)
67         cfi_restore (edi)
68         popl %esi
69         cfi_adjust_cfa_offset (-4)
70         cfi_restore (esi)
71         popl %ebx
72         cfi_adjust_cfa_offset (-4)
73         cfi_restore (ebx)
74         popl %ebp
75         cfi_adjust_cfa_offset (-4)
76         cfi_restore (ebp)
78 #else
80         /* Save registers.  */
81         movl %ebx, %edx
82         cfi_register (ebx, edx)
84         movl $SYS_ify(mmap), %eax       /* System call number in %eax.  */
86         lea 4(%esp), %ebx               /* Address of args is 1st arg.  */
88         /* Do the system call trap.  */
89         int $0x80
91         /* Restore registers.  */
92         movl %edx, %ebx
93         cfi_restore (ebx)
95 #endif
97         /* If 0 > %eax > -4096 there was an error.  */
98         cmpl $-4096, %eax
99         ja SYSCALL_ERROR_LABEL
101         /* Successful; return the syscall's value.  */
102 L(pseudo_end):
103         ret
105 PSEUDO_END (__mmap)
107 weak_alias (__mmap, mmap)