__syscall_error.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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 edx __asm__ ("%edx");
  28. __asm__ ("mov %eax, %edx\n\t"
  29. "negl %edx");
  30. __set_errno (edx);
  31. return -1;
  32. }