Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / sysv / linux / i386 / mmap.S
blob7fc2f11e14a49d8f108b31b771ac420eac88d94b
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, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
21 #include <kernel-features.h>
23 #define EINVAL  22
25         .text
27 ENTRY (__mmap)
29 /* I don't think it is worthwhile trying to use mmap2 whenever it
30    is available.  Only use it when we are sure the syscall exists.  */
31 #ifdef __ASSUME_MMAP2_SYSCALL
33         /* Save registers.  */
34         pushl %ebp
35         cfi_adjust_cfa_offset (4)
36         pushl %ebx
37         cfi_adjust_cfa_offset (4)
38         pushl %esi
39         cfi_adjust_cfa_offset (4)
40         pushl %edi
41         cfi_adjust_cfa_offset (4)
43         movl 20(%esp), %ebx
44         cfi_rel_offset (ebx, 8)
45         movl 24(%esp), %ecx
46         movl 28(%esp), %edx
47         movl 32(%esp), %esi
48         cfi_rel_offset (esi, 4)
49         movl 36(%esp), %edi
50         cfi_rel_offset (edi, 0)
51         movl 40(%esp), %ebp
52         cfi_rel_offset (ebp, 12)
53         testl $0xfff, %ebp
54         movl $-EINVAL, %eax
55         jne L(skip)
56         shrl $12, %ebp                  /* mmap2 takes the offset in pages.  */
58         movl $SYS_ify(mmap2), %eax      /* System call number in %eax.  */
60         /* Do the system call trap.  */
61         ENTER_KERNEL
62 L(skip):
63         /* Restore registers.  */
64         popl %edi
65         cfi_adjust_cfa_offset (-4)
66         cfi_restore (edi)
67         popl %esi
68         cfi_adjust_cfa_offset (-4)
69         cfi_restore (esi)
70         popl %ebx
71         cfi_adjust_cfa_offset (-4)
72         cfi_restore (ebx)
73         popl %ebp
74         cfi_adjust_cfa_offset (-4)
75         cfi_restore (ebp)
77 #else
79         /* Save registers.  */
80         movl %ebx, %edx
81         cfi_register (ebx, edx)
83         movl $SYS_ify(mmap), %eax       /* System call number in %eax.  */
85         lea 4(%esp), %ebx               /* Address of args is 1st arg.  */
87         /* Do the system call trap.  */
88         int $0x80
90         /* Restore registers.  */
91         movl %edx, %ebx
92         cfi_restore (ebx)
94 #endif
96         /* If 0 > %eax > -4096 there was an error.  */
97         cmpl $-4096, %eax
98         ja SYSCALL_ERROR_LABEL
100         /* Successful; return the syscall's value.  */
101 L(pseudo_end):
102         ret
104 PSEUDO_END (__mmap)
106 weak_alias (__mmap, mmap)