syscalls.h 6.2 KB

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