(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / sysv / linux / i386 / mmap64.S
blob3a03335814ee980d7da2ab44d2a0938bda6cc922
1 /* Copyright (C) 1995,96,97,98,99,2000,2002 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
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.
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.
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.  */
19 #include <sysdep.h>
20 #include <bp-sym.h>
21 #include <bp-asm.h>
23 #include "kernel-features.h"
25 #define EINVAL  22
26 #define ENOSYS  38
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
38         .text
39 ENTRY (BP_SYM (__mmap64))
41 #ifdef __NR_mmap2
43         /* Save registers.  */
44         pushl %ebp
45         pushl %ebx
46         pushl %esi
47         pushl %edi
49         movl OFFLO(%esp), %edx
50         movl OFFHI(%esp), %ecx
51         testl $0xfff, %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
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
64         movl $SYS_ify(mmap2), %eax      /* System call number in %eax.  */
66         /* Do the system call trap.  */
67 L(do_syscall):
68         ENTER_KERNEL
70         /* Restore registers.  */
71         popl %edi
72         popl %esi
73         popl %ebx
74         popl %ebp
76 #ifndef __ASSUME_MMAP2_SYSCALL
78         cmp $-ENOSYS, %eax
79         je 3f
80 #endif
82         /* If 0 > %eax > -4096 there was an error.  */
83         cmpl $-4096, %eax
84         ja SYSCALL_ERROR_LABEL
86         /* Successful; return the syscall's value.  */
87 L(pseudo_end):
88         ret
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
100 #if !defined __ASSUME_MMAP2_SYSCALL || !defined __NR_mmap2
102         /* Save registers.  */
103         movl %ebx, %edx
105         cmpl $0, OFFHI-SVRSP(%esp)
106         jne L(einval2)
108         movl $SYS_ify(mmap), %eax       /* System call number in %eax.  */
110         lea ADDR-SVRSP(%esp), %ebx      /* Address of args is 1st arg.  */
112         /* Do the system call trap.  */
113         ENTER_KERNEL
115         /* Restore registers.  */
116         movl %edx, %ebx
118         /* If 0 > %eax > -4096 there was an error.  */
119         cmpl $-4096, %eax
120         ja SYSCALL_ERROR_LABEL
122         /* Successful; return the syscall's value.  */
123 #ifndef __NR_mmap2
124 L(pseudo_end):
125 #endif
126         ret
128 L(einval2):
129         movl %edx, %ebx
130         movl $-EINVAL, %eax
131         jmp SYSCALL_ERROR_LABEL
132 #endif
134 PSEUDO_END (BP_SYM (__mmap64))
136 weak_alias (BP_SYM (__mmap64), BP_SYM (mmap64))