i386: store errno value before using __set_errno()
[uclibc-ng.git] / libc / sysdeps / linux / i386 / __syscall_error.c
blob36946bc6d00b44f753cd105ff2fd347eccb74fb3
1 /* Wrapper for setting errno.
3 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
8 /* This routine is jumped to by all the syscall handlers, to stash
9 * an error number into errno. */
11 /* This version uses a lot of magic and relies heavily on x86
12 * calling convention ... The advantage is that this is the same
13 * size as the previous __syscall_error() but all the .S functions
14 * need just one instruction.
16 * Local .S files have to set %eax to the negative errno value
17 * and then jump to this function. The neglected return to caller
18 * and return value of -1 is taken care of here so we don't have to
19 * worry about it in the .S functions.
21 * We have to stash the errno from %eax in a local stack var because
22 * __set_errno will prob call a function thus clobbering %eax on us.
25 #include <errno.h>
26 #include <features.h>
28 int __syscall_error(void) attribute_hidden;
29 int __syscall_error(void)
31 register int eax __asm__ ("%eax");
32 int _errno = -eax;
33 __set_errno (_errno);
34 return -1;