syscalls.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #ifndef _BITS_SYSCALLS_H
  2. #define _BITS_SYSCALLS_H
  3. #ifndef _SYSCALL_H
  4. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  5. #endif
  6. #ifndef __ASSEMBLER__
  7. #include <errno.h>
  8. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  9. #define _syscall_return(type) \
  10. return (_sc_err ? __set_errno(_sc_ret), _sc_ret = -1L : 0), (type) _sc_ret
  11. #define _syscall_clobbers \
  12. "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
  13. "$22", "$23", "$24", "$25", "$27", "$28" \
  14. #define _syscall0(type, name) \
  15. type name(void) \
  16. { \
  17. long _sc_ret, _sc_err; \
  18. { \
  19. register long _sc_0 __asm__("$0"); \
  20. register long _sc_19 __asm__("$19"); \
  21. \
  22. _sc_0 = __NR_##name; \
  23. __asm__("callsys # %0 %1 %2" \
  24. : "=r"(_sc_0), "=r"(_sc_19) \
  25. : "0"(_sc_0) \
  26. : _syscall_clobbers); \
  27. _sc_ret = _sc_0, _sc_err = _sc_19; \
  28. } \
  29. _syscall_return(type); \
  30. }
  31. #define _syscall1(type,name,type1,arg1) \
  32. type name(type1 arg1) \
  33. { \
  34. long _sc_ret, _sc_err; \
  35. { \
  36. register long _sc_0 __asm__("$0"); \
  37. register long _sc_16 __asm__("$16"); \
  38. register long _sc_19 __asm__("$19"); \
  39. \
  40. _sc_0 = __NR_##name; \
  41. _sc_16 = (long) (arg1); \
  42. __asm__("callsys # %0 %1 %2 %3" \
  43. : "=r"(_sc_0), "=r"(_sc_19) \
  44. : "0"(_sc_0), "r"(_sc_16) \
  45. : _syscall_clobbers); \
  46. _sc_ret = _sc_0, _sc_err = _sc_19; \
  47. } \
  48. _syscall_return(type); \
  49. }
  50. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  51. type name(type1 arg1,type2 arg2) \
  52. { \
  53. long _sc_ret, _sc_err; \
  54. { \
  55. register long _sc_0 __asm__("$0"); \
  56. register long _sc_16 __asm__("$16"); \
  57. register long _sc_17 __asm__("$17"); \
  58. register long _sc_19 __asm__("$19"); \
  59. \
  60. _sc_0 = __NR_##name; \
  61. _sc_16 = (long) (arg1); \
  62. _sc_17 = (long) (arg2); \
  63. __asm__("callsys # %0 %1 %2 %3 %4" \
  64. : "=r"(_sc_0), "=r"(_sc_19) \
  65. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17) \
  66. : _syscall_clobbers); \
  67. _sc_ret = _sc_0, _sc_err = _sc_19; \
  68. } \
  69. _syscall_return(type); \
  70. }
  71. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  72. type name(type1 arg1,type2 arg2,type3 arg3) \
  73. { \
  74. long _sc_ret, _sc_err; \
  75. { \
  76. register long _sc_0 __asm__("$0"); \
  77. register long _sc_16 __asm__("$16"); \
  78. register long _sc_17 __asm__("$17"); \
  79. register long _sc_18 __asm__("$18"); \
  80. register long _sc_19 __asm__("$19"); \
  81. \
  82. _sc_0 = __NR_##name; \
  83. _sc_16 = (long) (arg1); \
  84. _sc_17 = (long) (arg2); \
  85. _sc_18 = (long) (arg3); \
  86. __asm__("callsys # %0 %1 %2 %3 %4 %5" \
  87. : "=r"(_sc_0), "=r"(_sc_19) \
  88. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
  89. "r"(_sc_18) \
  90. : _syscall_clobbers); \
  91. _sc_ret = _sc_0, _sc_err = _sc_19; \
  92. } \
  93. _syscall_return(type); \
  94. }
  95. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  96. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  97. { \
  98. long _sc_ret, _sc_err; \
  99. { \
  100. register long _sc_0 __asm__("$0"); \
  101. register long _sc_16 __asm__("$16"); \
  102. register long _sc_17 __asm__("$17"); \
  103. register long _sc_18 __asm__("$18"); \
  104. register long _sc_19 __asm__("$19"); \
  105. \
  106. _sc_0 = __NR_##name; \
  107. _sc_16 = (long) (arg1); \
  108. _sc_17 = (long) (arg2); \
  109. _sc_18 = (long) (arg3); \
  110. _sc_19 = (long) (arg4); \
  111. __asm__("callsys # %0 %1 %2 %3 %4 %5 %6" \
  112. : "=r"(_sc_0), "=r"(_sc_19) \
  113. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
  114. "r"(_sc_18), "1"(_sc_19) \
  115. : _syscall_clobbers); \
  116. _sc_ret = _sc_0, _sc_err = _sc_19; \
  117. } \
  118. _syscall_return(type); \
  119. }
  120. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  121. type5,arg5) \
  122. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  123. { \
  124. long _sc_ret, _sc_err; \
  125. { \
  126. register long _sc_0 __asm__("$0"); \
  127. register long _sc_16 __asm__("$16"); \
  128. register long _sc_17 __asm__("$17"); \
  129. register long _sc_18 __asm__("$18"); \
  130. register long _sc_19 __asm__("$19"); \
  131. register long _sc_20 __asm__("$20"); \
  132. \
  133. _sc_0 = __NR_##name; \
  134. _sc_16 = (long) (arg1); \
  135. _sc_17 = (long) (arg2); \
  136. _sc_18 = (long) (arg3); \
  137. _sc_19 = (long) (arg4); \
  138. _sc_20 = (long) (arg5); \
  139. __asm__("callsys # %0 %1 %2 %3 %4 %5 %6 %7" \
  140. : "=r"(_sc_0), "=r"(_sc_19) \
  141. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
  142. "r"(_sc_18), "1"(_sc_19), "r"(_sc_20) \
  143. : _syscall_clobbers); \
  144. _sc_ret = _sc_0, _sc_err = _sc_19; \
  145. } \
  146. _syscall_return(type); \
  147. }
  148. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  149. type5,arg5,type6,arg6) \
  150. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6)\
  151. { \
  152. long _sc_ret, _sc_err; \
  153. { \
  154. register long _sc_0 __asm__("$0"); \
  155. register long _sc_16 __asm__("$16"); \
  156. register long _sc_17 __asm__("$17"); \
  157. register long _sc_18 __asm__("$18"); \
  158. register long _sc_19 __asm__("$19"); \
  159. register long _sc_20 __asm__("$20"); \
  160. register long _sc_21 __asm__("$21"); \
  161. \
  162. _sc_0 = __NR_##name; \
  163. _sc_16 = (long) (arg1); \
  164. _sc_17 = (long) (arg2); \
  165. _sc_18 = (long) (arg3); \
  166. _sc_19 = (long) (arg4); \
  167. _sc_20 = (long) (arg5); \
  168. _sc_21 = (long) (arg6); \
  169. __asm__("callsys # %0 %1 %2 %3 %4 %5 %6 %7 %8" \
  170. : "=r"(_sc_0), "=r"(_sc_19) \
  171. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
  172. "r"(_sc_18), "1"(_sc_19), "r"(_sc_20), "r"(_sc_21) \
  173. : _syscall_clobbers); \
  174. _sc_ret = _sc_0, _sc_err = _sc_19; \
  175. } \
  176. _syscall_return(type); \
  177. }
  178. #endif /* __ASSEMBLER__ */
  179. #endif /* _BITS_SYSCALLS_H */