2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / i386 / socket.S
blob7c8ac29b86a69e3e8275d885a52cb18cc45bde59
1 /* Copyright (C) 1995-1998,2002,2003,2005 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-cancel.h>
20 #include <socketcall.h>
21 #include <tls.h>
23 #define P(a, b) P2(a, b)
24 #define P2(a, b) a##b
26         .text
27 /* The socket-oriented system calls are handled unusally in Linux.
28    They are all gated through the single `socketcall' system call number.
29    `socketcall' takes two arguments: the first is the subcode, specifying
30    which socket function is being called; and the second is a pointer to
31    the arguments to the specific function.
33    The .S files for the other calls just #define socket and #include this.  */
35 #ifndef __socket
36 # ifndef NO_WEAK_ALIAS
37 #  define __socket P(__,socket)
38 # else
39 #  define __socket socket
40 # endif
41 #endif
43 .globl __socket
44 ENTRY (__socket)
45 #if defined NEED_CANCELLATION && defined CENABLE
46         SINGLE_THREAD_P
47         jne 1f
48 #endif
50         /* Save registers.  */
51         movl %ebx, %edx
52         cfi_register (3, 2)
54         movl $SYS_ify(socketcall), %eax /* System call number in %eax.  */
56         /* Use ## so `socket' is a separate token that might be #define'd.  */
57         movl $P(SOCKOP_,socket), %ebx   /* Subcode is first arg to syscall.  */
58         lea 4(%esp), %ecx               /* Address of args is 2nd arg.  */
60         /* Do the system call trap.  */
61         ENTER_KERNEL
63         /* Restore registers.  */
64         movl %edx, %ebx
65         cfi_restore (3)
67         /* %eax is < 0 if there was an error.  */
68         cmpl $-125, %eax
69         jae SYSCALL_ERROR_LABEL
71         /* Successful; return the syscall's value.  */
72 L(pseudo_end):
73         ret
76 #if defined NEED_CANCELLATION && defined CENABLE
77         /* We need one more register.  */
78 1:      pushl %esi
79         cfi_adjust_cfa_offset(4)
81         /* Enable asynchronous cancellation.  */
82         CENABLE
83         movl %eax, %esi
84         cfi_offset(6, -8)               /* %esi */
86         /* Save registers.  */
87         movl %ebx, %edx
88         cfi_register (3, 2)
90         movl $SYS_ify(socketcall), %eax /* System call number in %eax.  */
92         /* Use ## so `socket' is a separate token that might be #define'd.  */
93         movl $P(SOCKOP_,socket), %ebx   /* Subcode is first arg to syscall.  */
94         lea 8(%esp), %ecx               /* Address of args is 2nd arg.  */
96         /* Do the system call trap.  */
97         ENTER_KERNEL
99         /* Restore registers.  */
100         movl %edx, %ebx
101         cfi_restore (3)
103         /* Restore the cancellation.  */
104         xchgl %esi, %eax
105         CDISABLE
107         /* Restore registers.  */
108         movl %esi, %eax
109         popl %esi
110         cfi_restore (6)
111         cfi_adjust_cfa_offset(-4)
113         /* %eax is < 0 if there was an error.  */
114         cmpl $-125, %eax
115         jae SYSCALL_ERROR_LABEL
117         /* Successful; return the syscall's value.  */
118         ret
119 #endif
120 PSEUDO_END (__socket)
122 #ifndef NO_WEAK_ALIAS
123 weak_alias (__socket, socket)
124 #endif