syscalls.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* Unlike the asm/unistd.h kernel header file (which this is partly based on),
  2. * this file must be able to cope with PIC and non-PIC code. For some arches
  3. * there is no difference. For x86 (which has far too few registers) there is
  4. * a difference. Regardless, including asm/unistd.h is hereby officially
  5. * forbidden. Don't do it. It is bad for you. */
  6. #define _syscall_return(type) \
  7. return (_sc_err ? errno = _sc_ret, _sc_ret = -1L : 0), (type) _sc_ret
  8. #define _syscall_clobbers \
  9. "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
  10. "$22", "$23", "$24", "$25", "$27", "$28" \
  11. #define _syscall0(type, name) \
  12. type name(void) \
  13. { \
  14. long _sc_ret, _sc_err; \
  15. { \
  16. register long _sc_0 __asm__("$0"); \
  17. register long _sc_19 __asm__("$19"); \
  18. \
  19. _sc_0 = __NR_##name; \
  20. __asm__("callsys # %0 %1 %2" \
  21. : "=r"(_sc_0), "=r"(_sc_19) \
  22. : "0"(_sc_0) \
  23. : _syscall_clobbers); \
  24. _sc_ret = _sc_0, _sc_err = _sc_19; \
  25. } \
  26. _syscall_return(type); \
  27. }
  28. #define _syscall1(type,name,type1,arg1) \
  29. type name(type1 arg1) \
  30. { \
  31. long _sc_ret, _sc_err; \
  32. { \
  33. register long _sc_0 __asm__("$0"); \
  34. register long _sc_16 __asm__("$16"); \
  35. register long _sc_19 __asm__("$19"); \
  36. \
  37. _sc_0 = __NR_##name; \
  38. _sc_16 = (long) (arg1); \
  39. __asm__("callsys # %0 %1 %2 %3" \
  40. : "=r"(_sc_0), "=r"(_sc_19) \
  41. : "0"(_sc_0), "r"(_sc_16) \
  42. : _syscall_clobbers); \
  43. _sc_ret = _sc_0, _sc_err = _sc_19; \
  44. } \
  45. _syscall_return(type); \
  46. }
  47. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  48. type name(type1 arg1,type2 arg2) \
  49. { \
  50. long _sc_ret, _sc_err; \
  51. { \
  52. register long _sc_0 __asm__("$0"); \
  53. register long _sc_16 __asm__("$16"); \
  54. register long _sc_17 __asm__("$17"); \
  55. register long _sc_19 __asm__("$19"); \
  56. \
  57. _sc_0 = __NR_##name; \
  58. _sc_16 = (long) (arg1); \
  59. _sc_17 = (long) (arg2); \
  60. __asm__("callsys # %0 %1 %2 %3 %4" \
  61. : "=r"(_sc_0), "=r"(_sc_19) \
  62. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17) \
  63. : _syscall_clobbers); \
  64. _sc_ret = _sc_0, _sc_err = _sc_19; \
  65. } \
  66. _syscall_return(type); \
  67. }
  68. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  69. type name(type1 arg1,type2 arg2,type3 arg3) \
  70. { \
  71. long _sc_ret, _sc_err; \
  72. { \
  73. register long _sc_0 __asm__("$0"); \
  74. register long _sc_16 __asm__("$16"); \
  75. register long _sc_17 __asm__("$17"); \
  76. register long _sc_18 __asm__("$18"); \
  77. register long _sc_19 __asm__("$19"); \
  78. \
  79. _sc_0 = __NR_##name; \
  80. _sc_16 = (long) (arg1); \
  81. _sc_17 = (long) (arg2); \
  82. _sc_18 = (long) (arg3); \
  83. __asm__("callsys # %0 %1 %2 %3 %4 %5" \
  84. : "=r"(_sc_0), "=r"(_sc_19) \
  85. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
  86. "r"(_sc_18) \
  87. : _syscall_clobbers); \
  88. _sc_ret = _sc_0, _sc_err = _sc_19; \
  89. } \
  90. _syscall_return(type); \
  91. }
  92. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  93. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  94. { \
  95. long _sc_ret, _sc_err; \
  96. { \
  97. register long _sc_0 __asm__("$0"); \
  98. register long _sc_16 __asm__("$16"); \
  99. register long _sc_17 __asm__("$17"); \
  100. register long _sc_18 __asm__("$18"); \
  101. register long _sc_19 __asm__("$19"); \
  102. \
  103. _sc_0 = __NR_##name; \
  104. _sc_16 = (long) (arg1); \
  105. _sc_17 = (long) (arg2); \
  106. _sc_18 = (long) (arg3); \
  107. _sc_19 = (long) (arg4); \
  108. __asm__("callsys # %0 %1 %2 %3 %4 %5 %6" \
  109. : "=r"(_sc_0), "=r"(_sc_19) \
  110. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
  111. "r"(_sc_18), "1"(_sc_19) \
  112. : _syscall_clobbers); \
  113. _sc_ret = _sc_0, _sc_err = _sc_19; \
  114. } \
  115. _syscall_return(type); \
  116. }
  117. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  118. type5,arg5) \
  119. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  120. { \
  121. long _sc_ret, _sc_err; \
  122. { \
  123. register long _sc_0 __asm__("$0"); \
  124. register long _sc_16 __asm__("$16"); \
  125. register long _sc_17 __asm__("$17"); \
  126. register long _sc_18 __asm__("$18"); \
  127. register long _sc_19 __asm__("$19"); \
  128. register long _sc_20 __asm__("$20"); \
  129. \
  130. _sc_0 = __NR_##name; \
  131. _sc_16 = (long) (arg1); \
  132. _sc_17 = (long) (arg2); \
  133. _sc_18 = (long) (arg3); \
  134. _sc_19 = (long) (arg4); \
  135. _sc_20 = (long) (arg5); \
  136. __asm__("callsys # %0 %1 %2 %3 %4 %5 %6 %7" \
  137. : "=r"(_sc_0), "=r"(_sc_19) \
  138. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
  139. "r"(_sc_18), "1"(_sc_19), "r"(_sc_20) \
  140. : _syscall_clobbers); \
  141. _sc_ret = _sc_0, _sc_err = _sc_19; \
  142. } \
  143. _syscall_return(type); \
  144. }
  145. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  146. type5,arg5,type6,arg6) \
  147. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6)\
  148. { \
  149. long _sc_ret, _sc_err; \
  150. { \
  151. register long _sc_0 __asm__("$0"); \
  152. register long _sc_16 __asm__("$16"); \
  153. register long _sc_17 __asm__("$17"); \
  154. register long _sc_18 __asm__("$18"); \
  155. register long _sc_19 __asm__("$19"); \
  156. register long _sc_20 __asm__("$20"); \
  157. register long _sc_21 __asm__("$21"); \
  158. \
  159. _sc_0 = __NR_##name; \
  160. _sc_16 = (long) (arg1); \
  161. _sc_17 = (long) (arg2); \
  162. _sc_18 = (long) (arg3); \
  163. _sc_19 = (long) (arg4); \
  164. _sc_20 = (long) (arg5); \
  165. _sc_21 = (long) (arg6); \
  166. __asm__("callsys # %0 %1 %2 %3 %4 %5 %6 %7 %8" \
  167. : "=r"(_sc_0), "=r"(_sc_19) \
  168. : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
  169. "r"(_sc_18), "1"(_sc_19), "r"(_sc_20), "r"(_sc_21) \
  170. : _syscall_clobbers); \
  171. _sc_ret = _sc_0, _sc_err = _sc_19; \
  172. } \
  173. _syscall_return(type); \
  174. }