2.9
[glibc/nacl-glibc.git] / sysdeps / unix / i386 / sysdep.S
blob3bc872add84c5a44eeabd95dff542045172571bc
1 /* Copyright (C) 1991,1992,1993,1994,1995,1996,1997,2000,2002,2004,2005
2         Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
21 #define _ERRNO_H
22 #include <bits/errno.h>
23 #include <bp-asm.h>
24 #include <bp-sym.h>
26 #ifdef IS_IN_rtld
27 # include <dl-sysdep.h>         /* Defines RTLD_PRIVATE_ERRNO.  */
28 #endif
30 .globl C_SYMBOL_NAME(errno)
31 .globl syscall_error
33 #undef syscall_error
34 #ifdef NO_UNDERSCORES
35 __syscall_error:
36 #else
37 syscall_error:
38 #endif
39 #if defined (EWOULDBLOCK_sys) && EWOULDBLOCK_sys != EAGAIN
40         /* We translate the system's EWOULDBLOCK error into EAGAIN.
41            The GNU C library always defines EWOULDBLOCK==EAGAIN.
42            EWOULDBLOCK_sys is the original number.  */
43         cmpl $EWOULDBLOCK_sys, %eax /* Is it the old EWOULDBLOCK?  */
44         jne notb                /* Branch if not.  */
45         movl $EAGAIN, %eax      /* Yes; translate it to EAGAIN.  */
46 notb:
47 #endif
48 #ifndef PIC
49 # if USE___THREAD
50 #  ifndef NO_TLS_DIRECT_SEG_REFS
51         movl %eax, %gs:C_SYMBOL_NAME(errno@NTPOFF)
52 #  else
53         movl %gs:0, %ecx
54         movl %eax, C_SYMBOL_NAME(errno@NTPOFF)(%ecx)
55 #  endif
56 # elif !defined _LIBC_REENTRANT
57         movl %eax, C_SYMBOL_NAME(errno)
58 # else
59         pushl %eax
60         PUSH_ERRNO_LOCATION_RETURN
61         call BP_SYM (__errno_location)
62         POP_ERRNO_LOCATION_RETURN
63         popl %ecx
64         movl %ecx, (%eax)
65 # endif
66 #else
67         /* The caller has pushed %ebx and then set it up to
68            point to the GOT before calling us through the PLT.  */
69 # if USE___THREAD
70         movl C_SYMBOL_NAME(errno@GOTNTPOFF)(%ebx), %ecx
72         /* Pop %ebx value saved before jumping here.  */
73         popl %ebx
74 #  ifndef NO_TLS_DIRECT_SEG_REFS
75         addl %gs:0, %ecx
76         movl %eax, (%ecx)
77 #  else
78         movl %eax, %gs:0(%ecx)
79 #  endif
80 # elif RTLD_PRIVATE_ERRNO
81         movl %eax, C_SYMBOL_NAME(rtld_errno@GOTOFF)(%ebx)
83         /* Pop %ebx value saved before jumping here.  */
84         popl %ebx
85 # elif !defined _LIBC_REENTRANT
86         movl C_SYMBOL_NAME(errno@GOT)(%ebx), %ecx
88         /* Pop %ebx value saved before jumping here.  */
89         popl %ebx
90         movl %eax, (%ecx)
91 # else
92         pushl %eax
93         PUSH_ERRNO_LOCATION_RETURN
94         call C_SYMBOL_NAME (BP_SYM (__errno_location)@PLT)
95         POP_ERRNO_LOCATION_RETURN
96         popl %ecx
97         /* Pop %ebx value saved before jumping here.  */
98         popl %ebx
99         movl %ecx, (%eax)
100 # endif
101 #endif
102         movl $-1, %eax
103         ret
105 #undef  __syscall_error
106 END (__syscall_error)