syscalls.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  3. * ported from GNU C Library
  4. */
  5. /* Copyright (C) 2000-2017 Free Software Foundation, Inc.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public License as
  8. published by the Free Software Foundation; either version 2.1 of the
  9. License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, see
  16. <http://www.gnu.org/licenses/>. */
  17. #ifndef _BITS_SYSCALLS_H
  18. #define _BITS_SYSCALLS_H
  19. #ifndef _SYSCALL_H
  20. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  21. #endif
  22. #ifndef __ASSEMBLER__
  23. #define __SYSCALL_CLOBBERS \
  24. "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
  25. "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
  26. "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
  27. "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
  28. "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \
  29. "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62", \
  30. "cc", "memory"
  31. #define __SYSCALL_STRING \
  32. "ta 0x6d;" \
  33. "bcc,pt %%xcc, 1f;" \
  34. " mov 0, %%g1;" \
  35. "sub %%g0, %%o0, %%o0;" \
  36. "mov 1, %%g1;" \
  37. "1:"
  38. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  39. ({ \
  40. register long __o0 __asm__("o0"); \
  41. long err = name; \
  42. LOAD_ARGS_##nr(args) \
  43. \
  44. __asm__ __volatile__( __SYSCALL_STRING \
  45. : "=r" (err), "=r" (__o0) \
  46. : "0" (err), "1" (__o0) ASM_ARGS_##nr \
  47. : __SYSCALL_CLOBBERS ); \
  48. __o0; \
  49. })
  50. #define INTERNAL_SYSCALL_ERROR_P(val, err) \
  51. ((unsigned int) (val) >= 0xfffff001u)
  52. #define INLINE_CLONE_SYSCALL(arg1,arg2,arg3,arg4,arg5) \
  53. ({ \
  54. register long __o0 __asm__ ("o0") = (long)(arg1); \
  55. register long __o1 __asm__ ("o1") = (long)(arg2); \
  56. register long __o2 __asm__ ("o2") = (long)(arg3); \
  57. register long __o3 __asm__ ("o3") = (long)(arg4); \
  58. register long __o4 __asm__ ("o4") = (long)(arg5); \
  59. register long __g1 __asm__ ("g1") = __NR_clone; \
  60. __asm __volatile (__SYSCALL_STRING : \
  61. "=r" (__g1), "=r" (__o0), "=r" (__o1) : \
  62. "0" (__g1), "1" (__o0), "2" (__o1), \
  63. "r" (__o2), "r" (__o3), "r" (__o4) : \
  64. __SYSCALL_CLOBBERS); \
  65. if (INTERNAL_SYSCALL_ERROR_P (__o0, __g1)) \
  66. { \
  67. __set_errno (INTERNAL_SYSCALL_ERRNO (__o0, __g1)); \
  68. __o0 = -1L; \
  69. } \
  70. else \
  71. { \
  72. __o0 &= (__o1 - 1); \
  73. } \
  74. __o0; \
  75. })
  76. #define LOAD_ARGS_0()
  77. #define ASM_ARGS_0
  78. #define LOAD_ARGS_1(o0) \
  79. __o0 = (long)o0; \
  80. LOAD_ARGS_0()
  81. #define ASM_ARGS_1 ASM_ARGS_0, "r" (__o0)
  82. #define LOAD_ARGS_2(o0, o1) \
  83. register long __o1 __asm__ ("o1") = (long) (o1); \
  84. LOAD_ARGS_1 (o0)
  85. #define ASM_ARGS_2 ASM_ARGS_1, "r" (__o1)
  86. #define LOAD_ARGS_3(o0, o1, o2) \
  87. register long __o2 __asm__ ("o2") = (long) (o2); \
  88. LOAD_ARGS_2 (o0, o1)
  89. #define ASM_ARGS_3 ASM_ARGS_2, "r" (__o2)
  90. #define LOAD_ARGS_4(o0, o1, o2, o3) \
  91. register long __o3 __asm__ ("o3") = (long) (o3); \
  92. LOAD_ARGS_3 (o0, o1, o2)
  93. #define ASM_ARGS_4 ASM_ARGS_3, "r" (__o3)
  94. #define LOAD_ARGS_5(o0, o1, o2, o3, o4) \
  95. register long __o4 __asm__ ("o4") = (long) (o4); \
  96. LOAD_ARGS_4 (o0, o1, o2, o3)
  97. #define ASM_ARGS_5 ASM_ARGS_4, "r" (__o4)
  98. #define LOAD_ARGS_6(o0, o1, o2, o3, o4, o5) \
  99. register long __o5 __asm__ ("o5") = (long) (o5); \
  100. LOAD_ARGS_5 (o0, o1, o2, o3, o4)
  101. #define ASM_ARGS_6 ASM_ARGS_5, "r" (__o5)
  102. #endif /* __ASSEMBLER__ */
  103. #endif /* _BITS_SYSCALLS_H */