__syscall_error.c 1.1 KB

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