1 /* Copyright (C) 1995-2015 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>
21 #include <kernel-features.h>
26 #ifdef __ASSUME_ACCEPT4_SOCKETCALL
27 # define errlabel SYSCALL_ERROR_LABEL
29 # define errlabel .Lerr
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. */
43 ENTRY (__libc_accept4)
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. */
61 /* Restore registers. */
65 /* %eax is < 0 if there was an error. */
69 /* Successful; return the syscall's value. */
74 /* We need one more register. */
76 cfi_adjust_cfa_offset(4)
78 /* Enable asynchronous cancellation. */
81 cfi_offset(6, -8) /* %esi */
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. */
95 /* Restore registers. */
99 /* Restore the cancellation. */
103 /* Restore registers. */
107 cfi_adjust_cfa_offset(-4)
109 /* %eax is < 0 if there was an error. */
113 /* Successful; return the syscall's value. */
117 #ifndef __ASSUME_ACCEPT4_SOCKETCALL
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. */
125 cfi_adjust_cfa_offset(4)
130 addl $_GLOBAL_OFFSET_TABLE_, %edx
131 movl have_accept4@GOTOFF(%edx), %eax
133 movl have_accept4, %eax
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. */
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. */
158 movl %eax, have_accept4@GOTOFF(%edx)
160 movl %eax, have_accept4
165 1: movl $-EINVAL, %eax
169 /* Restore registers. */
173 jmp SYSCALL_ERROR_LABEL
175 PSEUDO_END (__libc_accept4)
177 weak_alias (__libc_accept4, accept4)