syscalls.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #ifndef _BITS_SYSCALLS_H
  2. #define _BITS_SYSCALLS_H
  3. #ifndef _SYSCALL_H
  4. # error "Never use <bits/syscall.h> directly; include <sys/syscall.h> instead."
  5. #endif
  6. /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  7. * header files. It also defines the traditional `SYS_<name>' macros for older
  8. * programs. */
  9. #include <bits/sysnum.h>
  10. #ifndef __set_errno
  11. # define __set_errno(val) (*__errno_location())=(val)
  12. #endif
  13. #ifndef SYS_ify
  14. # define SYS_ify(syscall_name) (__NR_##syscall_name)
  15. #endif
  16. #undef _syscall_return
  17. #define _syscall_return(type) \
  18. do { \
  19. if ((unsigned long) (_sc_ret) >= (unsigned long) (-125)) { \
  20. __set_errno(-_sc_ret); \
  21. _sc_ret = -1; \
  22. } \
  23. \
  24. return (type) (_sc_ret); \
  25. } while (0)
  26. #define _syscall_clobbers \
  27. "r1", "r2", "r3", "r4", \
  28. "r5", "r6", "r7", "r8", \
  29. "r9", "r10", "r11"
  30. #ifdef _syscall0
  31. # undef _syscall0
  32. #endif
  33. #define _syscall0(type, name) \
  34. type name (void) \
  35. { \
  36. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  37. long _sc_ret; \
  38. \
  39. __asm__ __volatile__ ( \
  40. " pushl %%ap \n" \
  41. " pushl $0x0 \n" \
  42. " movl %%sp, %%ap \n" \
  43. " chmk %%r0 \n" \
  44. " addl2 $4, %%sp \n" \
  45. " movl (%%sp)+, %%ap \n" \
  46. : "=r" (_sc_0) \
  47. : "0" (_sc_0) \
  48. : _syscall_clobbers); \
  49. \
  50. _sc_ret = _sc_0; \
  51. _syscall_return (type); \
  52. }
  53. #ifdef _syscall1
  54. # undef _syscall1
  55. #endif
  56. #define _syscall1(type, name, type1, arg1) \
  57. type name (type1 arg1) \
  58. { \
  59. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  60. long _sc_ret; \
  61. \
  62. __asm__ __volatile__ ( \
  63. " pushl %%ap \n" \
  64. " pushl %2 \n" \
  65. " pushl $0x1 \n" \
  66. " movl %%sp, %%ap \n" \
  67. " chmk %%r0 \n" \
  68. " addl2 $8, %%sp \n" \
  69. " movl (%%sp)+, %%ap \n" \
  70. : "=r" (_sc_0) \
  71. : "0" (_sc_0), \
  72. "m" (arg1) \
  73. : _syscall_clobbers); \
  74. \
  75. _sc_ret = _sc_0; \
  76. _syscall_return (type); \
  77. }
  78. #ifdef _syscall2
  79. # undef _syscall2
  80. #endif
  81. #define _syscall2(type, name, type1, arg1, type2, arg2) \
  82. type name (type1 arg1, \
  83. type2 arg2) \
  84. { \
  85. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  86. long _sc_ret; \
  87. \
  88. __asm__ __volatile__ ( \
  89. " pushl %%ap \n" \
  90. " pushl %3 \n" \
  91. " pushl %2 \n" \
  92. " pushl $0x2 \n" \
  93. " movl %%sp, %%ap \n" \
  94. " chmk %%r0 \n" \
  95. " addl2 $12, %%sp \n" \
  96. " movl (%%sp)+, %%ap \n" \
  97. : "=r" (_sc_0) \
  98. : "0" (_sc_0), \
  99. "m" (arg1), \
  100. "m" (arg2) \
  101. : _syscall_clobbers); \
  102. \
  103. _sc_ret = _sc_0; \
  104. _syscall_return (type); \
  105. }
  106. #ifdef _syscall3
  107. # undef _syscall3
  108. #endif
  109. #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  110. type name (type1 arg1, \
  111. type2 arg2, \
  112. type3 arg3) \
  113. { \
  114. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  115. long _sc_ret; \
  116. \
  117. __asm__ __volatile__ ( \
  118. " pushl %%ap \n" \
  119. " pushl %4 \n" \
  120. " pushl %3 \n" \
  121. " pushl %2 \n" \
  122. " pushl $0x3 \n" \
  123. " movl %%sp, %%ap \n" \
  124. " chmk %%r0 \n" \
  125. " addl2 $16, %%sp \n" \
  126. " movl (%%sp)+, %%ap \n" \
  127. : "=r" (_sc_0) \
  128. : "0" (_sc_0), \
  129. "m" (arg1), \
  130. "m" (arg2), \
  131. "m" (arg3) \
  132. : _syscall_clobbers); \
  133. \
  134. _sc_ret = _sc_0; \
  135. _syscall_return (type); \
  136. }
  137. #ifdef _syscall4
  138. # undef _syscall4
  139. #endif
  140. #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
  141. type4, arg4) \
  142. type name (type1 arg1, \
  143. type2 arg2, \
  144. type3 arg3, \
  145. type4 arg4) \
  146. { \
  147. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  148. long _sc_ret; \
  149. \
  150. __asm__ __volatile__ ( \
  151. " pushl %%ap \n" \
  152. " pushl %5 \n" \
  153. " pushl %4 \n" \
  154. " pushl %3 \n" \
  155. " pushl %2 \n" \
  156. " pushl $0x4 \n" \
  157. " movl %%sp, %%ap \n" \
  158. " chmk %%r0 \n" \
  159. " addl2 $20, %%sp \n" \
  160. " movl (%%sp)+, %%ap \n" \
  161. : "=r" (_sc_0) \
  162. : "0" (_sc_0), \
  163. "m" (arg1), \
  164. "m" (arg2), \
  165. "m" (arg3), \
  166. "m" (arg4) \
  167. : _syscall_clobbers); \
  168. \
  169. _sc_ret = _sc_0; \
  170. _syscall_return (type); \
  171. }
  172. #ifdef _syscall5
  173. # undef _syscall5
  174. #endif
  175. #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
  176. type4, arg4, type5, arg5) \
  177. type name (type1 arg1, \
  178. type2 arg2, \
  179. type3 arg3, \
  180. type4 arg4, \
  181. type5 arg5) \
  182. { \
  183. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  184. long _sc_ret; \
  185. \
  186. __asm__ __volatile__ ( \
  187. " pushl %%ap \n" \
  188. " pushl %6 \n" \
  189. " pushl %5 \n" \
  190. " pushl %4 \n" \
  191. " pushl %3 \n" \
  192. " pushl %2 \n" \
  193. " pushl $0x5 \n" \
  194. " movl %%sp, %%ap \n" \
  195. " chmk %%r0 \n" \
  196. " addl2 $24, %%sp \n" \
  197. " movl (%%sp)+, %%ap \n" \
  198. : "=r" (_sc_0) \
  199. : "0" (_sc_0), \
  200. "m" (arg1), \
  201. "m" (arg2), \
  202. "m" (arg3), \
  203. "m" (arg4), \
  204. "m" (arg5) \
  205. : _syscall_clobbers); \
  206. \
  207. _sc_ret = _sc_0; \
  208. _syscall_return (type); \
  209. }
  210. #ifdef _syscall6
  211. # undef _syscall6
  212. #endif
  213. #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
  214. type4, arg4, type5, arg5, type6, arg6) \
  215. type name (type1 arg1, \
  216. type2 arg2, \
  217. type3 arg3, \
  218. type4 arg4, \
  219. type5 arg5, \
  220. type6 arg6) \
  221. { \
  222. register long _sc_0 __asm__("r0") = SYS_ify (name); \
  223. long _sc_ret; \
  224. \
  225. __asm__ __volatile__ ( \
  226. " pushl %%ap \n" \
  227. " pushl %7 \n" \
  228. " pushl %6 \n" \
  229. " pushl %5 \n" \
  230. " pushl %4 \n" \
  231. " pushl %3 \n" \
  232. " pushl %2 \n" \
  233. " pushl $0x6 \n" \
  234. " movl %%sp, %%ap \n" \
  235. " chmk %%r0 \n" \
  236. " addl2 $28, %%sp \n" \
  237. " movl (%%sp)+, %%ap \n" \
  238. : "=r" (_sc_0) \
  239. : "0" (_sc_0), \
  240. "m" (arg1), \
  241. "m" (arg2), \
  242. "m" (arg3), \
  243. "m" (arg4), \
  244. "m" (arg5), \
  245. "m" (arg6) \
  246. : _syscall_clobbers); \
  247. \
  248. _sc_ret = _sc_0; \
  249. _syscall_return (type); \
  250. }
  251. #endif /* _BITS_SYSCALLS_H */