sysdep.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* syscall error handlers
  2. Copyright (C) 2011-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library. If not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #if IS_IN (libc)
  17. # define errno __libc_errno
  18. #endif
  19. ENTRY (__syscall_error)
  20. mv t0, ra
  21. /* Fall through to __syscall_set_errno. */
  22. END (__syscall_error)
  23. /* Non-standard calling convention: argument in a0, return address in t0,
  24. and clobber only t1. */
  25. ENTRY (__syscall_set_errno)
  26. /* We got here because a0 < 0, but only codes in the range [-4095, -1]
  27. represent errors. Otherwise, just return the result normally. */
  28. li t1, -4096
  29. bleu a0, t1, 1f
  30. neg a0, a0
  31. #if RTLD_PRIVATE_ERRNO
  32. sw a0, rtld_errno, t1
  33. #elif defined(__PIC__)
  34. la.tls.ie t1, errno
  35. add t1, t1, tp
  36. sw a0, 0(t1)
  37. #else
  38. lui t1, %tprel_hi(errno)
  39. add t1, t1, tp, %tprel_add(errno)
  40. sw a0, %tprel_lo(errno)(t1)
  41. #endif
  42. li a0, -1
  43. 1: jr t0
  44. END (__syscall_set_errno)