__syscall_error.c 1.1 KB

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