Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / i386 / accept4.S
blobcdce27b57fa463f79cba79f046fe79880320cbd9
1 /* Copyright (C) 1995-2014 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, see
16    <http://www.gnu.org/licenses/>.  */
18 #include <sysdep-cancel.h>
19 #include <socketcall.h>
20 #include <tls.h>
21 #include <kernel-features.h>
23 #define EINVAL  22
24 #define ENOSYS  38
26 #ifdef __ASSUME_ACCEPT4
27 # define errlabel SYSCALL_ERROR_LABEL
28 #else
29 # define errlabel .Lerr
30         .data
31 have_accept4:
32         .long   0
33 #endif
35         .text
36 /* The socket-oriented system calls are handled unusally in Linux/i386.
37    They are all gated through the single `socketcall' system call number.
38    `socketcall' takes two arguments: the first is the subcode, specifying
39    which socket function is being called; and the second is a pointer to
40    the arguments to the specific function.  */
42 .globl __libc_accept4
43 ENTRY (__libc_accept4)
44 #ifdef CENABLE
45         SINGLE_THREAD_P
46         jne 1f
47 #endif
49         /* Save registers.  */
50         movl %ebx, %edx
51         cfi_register (3, 2)
53         movl $SYS_ify(socketcall), %eax /* System call number in %eax.  */
55         movl $SOCKOP_accept4, %ebx      /* Subcode is first arg to syscall.  */
56         lea 4(%esp), %ecx               /* Address of args is 2nd arg.  */
58         /* Do the system call trap.  */
59         ENTER_KERNEL
61         /* Restore registers.  */
62         movl %edx, %ebx
63         cfi_restore (3)
65         /* %eax is < 0 if there was an error.  */
66         cmpl $-125, %eax
67         jae errlabel
69         /* Successful; return the syscall's value.  */
70         ret
73 #ifdef CENABLE
74         /* We need one more register.  */
75 1:      pushl %esi
76         cfi_adjust_cfa_offset(4)
78         /* Enable asynchronous cancellation.  */
79         CENABLE
80         movl %eax, %esi
81         cfi_offset(6, -8)               /* %esi */
83         /* Save registers.  */
84         movl %ebx, %edx
85         cfi_register (3, 2)
87         movl $SYS_ify(socketcall), %eax /* System call number in %eax.  */
89         movl $SOCKOP_accept4, %ebx      /* Subcode is first arg to syscall.  */
90         lea 8(%esp), %ecx               /* Address of args is 2nd arg.  */
92         /* Do the system call trap.  */
93         ENTER_KERNEL
95         /* Restore registers.  */
96         movl %edx, %ebx
97         cfi_restore (3)
99         /* Restore the cancellation.  */
100         xchgl %esi, %eax
101         CDISABLE
103         /* Restore registers.  */
104         movl %esi, %eax
105         popl %esi
106         cfi_restore (6)
107         cfi_adjust_cfa_offset(-4)
109         /* %eax is < 0 if there was an error.  */
110         cmpl $-125, %eax
111         jae errlabel
113         /* Successful; return the syscall's value.  */
114         ret
115 #endif
117 #ifndef __ASSUME_ACCEPT4
118         /* The kernel returns -EINVAL for unknown socket operations.
119            We need to convert that error to an ENOSYS error.  */
120 .Lerr:  cmpl $-EINVAL, %eax
121         jne SYSCALL_ERROR_LABEL
123         /* Save registers.  */
124         pushl %ebx
125         cfi_adjust_cfa_offset(4)
126         cfi_offset(ebx, -8)
128 # ifdef PIC
129         SETUP_PIC_REG (dx)
130         addl $_GLOBAL_OFFSET_TABLE_, %edx
131         movl have_accept4@GOTOFF(%edx), %eax
132 # else
133         movl have_accept4, %eax
134 # endif
135         testl %eax, %eax
136         jne 1f
138         /* Try another call, this time with the FLAGS parameter
139            cleared and an invalid file descriptor.  This call will not
140            cause any harm and it will return immediately.  */
141         movl $-1, 8(%esp)
142         movl $0, 20(%esp)
144         movl $SYS_ify(socketcall), %eax /* System call number in %eax.  */
146         movl $SOCKOP_accept4, %ebx      /* Subcode is first arg to syscall.  */
147         lea 8(%esp), %ecx               /* Address of args is 2nd arg.  */
149         /* Do the system call trap.  */
150         ENTER_KERNEL
152         cmpl $-EINVAL, %eax
153         movl $-1, %eax
154         je 3f
155         movl $1, %eax
157 # ifdef PIC
158         movl %eax, have_accept4@GOTOFF(%edx)
159 # else
160         movl %eax, have_accept4
161 # endif
163         testl %eax, %eax
165 1:      movl $-EINVAL, %eax
166         jns 2f
167         movl $-ENOSYS, %eax
169         /* Restore registers.  */
170 2:      popl %ebx
171         cfi_restore (ebx)
173         jmp SYSCALL_ERROR_LABEL
174 #endif
175 PSEUDO_END (__libc_accept4)
177 weak_alias (__libc_accept4, accept4)