yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1995,96,97,98,99,2000,2002 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 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. |
| 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 | Lesser General Public License for more details. |
| 13 | |
| 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. */ |
| 18 | |
| 19 | |
| 20 | #define _ERRNO_H 1 |
| 21 | #include <features.h> |
| 22 | #include <bits/errno.h> |
| 23 | #include <sys/syscall.h> |
| 24 | |
| 25 | #if defined __UCLIBC_HAS_LFS__ && defined __NR_mmap2 |
| 26 | |
| 27 | |
| 28 | #define LINKAGE 4 |
| 29 | #define PTR_SIZE 4 |
| 30 | #define SVRSP 16 /* saved register space */ |
| 31 | #define PARMS LINKAGE+SVRSP /* space for 4 saved regs */ |
| 32 | #define ADDR PARMS |
| 33 | #define LEN ADDR+PTR_SIZE |
| 34 | #define PROT LEN+4 |
| 35 | #define FLAGS PROT+4 |
| 36 | #define FD FLAGS+4 |
| 37 | #define OFFLO FD+4 |
| 38 | #define OFFHI OFFLO+4 |
| 39 | |
| 40 | .text |
| 41 | .global mmap64 |
| 42 | .type mmap64,%function |
| 43 | |
| 44 | mmap64: |
| 45 | /* Save registers. */ |
| 46 | pushl %ebp |
| 47 | pushl %ebx |
| 48 | pushl %esi |
| 49 | pushl %edi |
| 50 | |
| 51 | movl OFFLO(%esp), %edx |
| 52 | movl OFFHI(%esp), %ecx |
| 53 | testl $0xfff, %edx |
| 54 | jne L_einval |
| 55 | shrdl $12, %ecx, %edx /* mmap2 takes the offset in pages. */ |
| 56 | shrl $12, %ecx |
| 57 | jne L_einval |
| 58 | movl %edx, %ebp |
| 59 | |
| 60 | movl ADDR(%esp), %ebx |
| 61 | movl LEN(%esp), %ecx |
| 62 | movl PROT(%esp), %edx |
| 63 | movl FLAGS(%esp), %esi |
| 64 | movl FD(%esp), %edi |
| 65 | |
| 66 | movl $__NR_mmap2, %eax /* System call number in %eax. */ |
| 67 | /* Do the system call trap. */ |
| 68 | int $0x80 |
| 69 | |
| 70 | /* Restore registers. */ |
| 71 | popl %edi |
| 72 | popl %esi |
| 73 | popl %ebx |
| 74 | popl %ebp |
| 75 | |
| 76 | /* If 0 > %eax > -4096 there was an error. */ |
| 77 | cmpl $-4095,%eax |
| 78 | ja __syscall_error |
| 79 | /* Successful; return the syscall's value. */ |
| 80 | ret |
| 81 | |
| 82 | /* This means the offset value is too large. */ |
| 83 | L_einval: |
| 84 | popl %edi |
| 85 | popl %esi |
| 86 | popl %ebx |
| 87 | popl %ebp |
| 88 | movl $-EINVAL, %eax |
| 89 | jmp __syscall_error |
| 90 | |
| 91 | .size mmap64,.-mmap64 |
| 92 | |
| 93 | #endif |