syscalls.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. /* Include the __NR_<name> definitions. */
  7. #include <bits/sysnum.h>
  8. #if 0
  9. #ifndef __set_errno
  10. #define __set_errno(val) (*__errno_location()) = (val)
  11. #endif
  12. #endif
  13. #undef SYS_ify
  14. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  15. #ifndef __ASSEMBLER__
  16. #undef _syscall0
  17. #define _syscall0(type,name) \
  18. type name(void) \
  19. { \
  20. return (type) (INLINE_SYSCALL(name, 0)); \
  21. }
  22. #undef _syscall1
  23. #define _syscall1(type,name,type1,arg1) \
  24. type name(type1 arg1) \
  25. { \
  26. return (type) (INLINE_SYSCALL(name, 1, arg1)); \
  27. }
  28. #undef _syscall2
  29. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  30. type name(type1 arg1,type2 arg2) \
  31. { \
  32. return (type) (INLINE_SYSCALL(name, 2, arg1, arg2)); \
  33. }
  34. #undef _syscall3
  35. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  36. type name(type1 arg1,type2 arg2,type3 arg3) \
  37. { \
  38. return (type) (INLINE_SYSCALL(name, 3, arg1, arg2, arg3)); \
  39. }
  40. #undef _syscall4
  41. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  42. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  43. { \
  44. return (type) (INLINE_SYSCALL(name, 4, arg1, arg2, arg3, arg4)); \
  45. }
  46. #undef _syscall5
  47. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  48. type5,arg5) \
  49. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  50. { \
  51. return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \
  52. }
  53. #undef _syscall6
  54. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  55. type5,arg5,type6,arg6) \
  56. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \
  57. { \
  58. return (type) (INLINE_SYSCALL(name, 6, arg1, arg2, arg3, arg4, arg5, arg6)); \
  59. }
  60. #undef INLINE_SYSCALL
  61. #define INLINE_SYSCALL(name, nr, args...) \
  62. ({ \
  63. unsigned long __sys_res; \
  64. register unsigned long __res asm ("r10"); \
  65. LOAD_ARGS_c_##nr (args) \
  66. register unsigned long __callno asm ("r9") \
  67. = SYS_ify (name); \
  68. asm volatile (LOAD_ARGS_asm_##nr (args) \
  69. CHECK_ARGS_asm_##nr \
  70. "break 13" \
  71. : "=r" (__res) \
  72. : ASM_ARGS_##nr (args) \
  73. : ASM_CLOBBER_##nr); \
  74. __sys_res = __res; \
  75. \
  76. if (__sys_res >= (unsigned long) -4096) \
  77. { \
  78. __set_errno (- __sys_res); \
  79. __sys_res = (unsigned long) -1; \
  80. } \
  81. __sys_res; \
  82. })
  83. #define LOAD_ARGS_c_0()
  84. #define LOAD_ARGS_asm_0()
  85. #define ASM_CLOBBER_0 "memory"
  86. #define ASM_ARGS_0() "r" (__callno)
  87. #define CHECK_ARGS_asm_0
  88. #define LOAD_ARGS_c_1(r10) \
  89. LOAD_ARGS_c_0() \
  90. register unsigned long __r10 __asm__ ("r10") = (unsigned long) (r10);
  91. #define LOAD_ARGS_asm_1(r10) LOAD_ARGS_asm_0 ()
  92. #define ASM_CLOBBER_1 ASM_CLOBBER_0
  93. #define ASM_ARGS_1(r10) ASM_ARGS_0 (), "0" (__r10)
  94. #define CHECK_ARGS_asm_1 \
  95. ".ifnc %0,$r10\n\t" \
  96. ".err\n\t" \
  97. ".endif\n\t"
  98. #define LOAD_ARGS_c_2(r10, r11) \
  99. LOAD_ARGS_c_1(r10) \
  100. register unsigned long __r11 __asm__ ("r11") = (unsigned long) (r11);
  101. #define LOAD_ARGS_asm_2(r10, r11) LOAD_ARGS_asm_1 (r10)
  102. #define ASM_CLOBBER_2 ASM_CLOBBER_1
  103. #define ASM_ARGS_2(r10, r11) ASM_ARGS_1 (r10), "r" (__r11)
  104. #define CHECK_ARGS_asm_2 \
  105. ".ifnc %0-%3,$r10-$r11\n\t" \
  106. ".err\n\t" \
  107. ".endif\n\t"
  108. #define LOAD_ARGS_c_3(r10, r11, r12) \
  109. LOAD_ARGS_c_2(r10, r11) \
  110. register unsigned long __r12 __asm__ ("r12") = (unsigned long) (r12);
  111. #define LOAD_ARGS_asm_3(r10, r11, r12) LOAD_ARGS_asm_2 (r10, r11)
  112. #define ASM_CLOBBER_3 ASM_CLOBBER_2
  113. #define ASM_ARGS_3(r10, r11, r12) ASM_ARGS_2 (r10, r11), "r" (__r12)
  114. #define CHECK_ARGS_asm_3 \
  115. ".ifnc %0-%3-%4,$r10-$r11-$r12\n\t" \
  116. ".err\n\t" \
  117. ".endif\n\t"
  118. #define LOAD_ARGS_c_4(r10, r11, r12, r13) \
  119. LOAD_ARGS_c_3(r10, r11, r12) \
  120. register unsigned long __r13 __asm__ ("r13") = (unsigned long) (r13);
  121. #define LOAD_ARGS_asm_4(r10, r11, r12, r13) LOAD_ARGS_asm_3 (r10, r11, r12)
  122. #define ASM_CLOBBER_4 ASM_CLOBBER_3
  123. #define ASM_ARGS_4(r10, r11, r12, r13) ASM_ARGS_3 (r10, r11, r12), "r" (__r13)
  124. #define CHECK_ARGS_asm_4 \
  125. ".ifnc %0-%3-%4-%5,$r10-$r11-$r12-$r13\n\t" \
  126. ".err\n\t" \
  127. ".endif\n\t"
  128. #define LOAD_ARGS_c_5(r10, r11, r12, r13, mof) \
  129. LOAD_ARGS_c_4(r10, r11, r12, r13)
  130. #define LOAD_ARGS_asm_5(r10, r11, r12, r13, mof) \
  131. LOAD_ARGS_asm_4 (r10, r11, r12, r13) "move %6,$mof\n\t"
  132. #define ASM_CLOBBER_5 ASM_CLOBBER_4
  133. #define ASM_ARGS_5(r10, r11, r12, r13, mof) \
  134. ASM_ARGS_4 (r10, r11, r12, r13), "g" (mof)
  135. #define CHECK_ARGS_asm_5 CHECK_ARGS_asm_4
  136. #define LOAD_ARGS_c_6(r10, r11, r12, r13, mof, srp) \
  137. LOAD_ARGS_c_5(r10, r11, r12, r13, mof)
  138. #define LOAD_ARGS_asm_6(r10, r11, r12, r13, mof, srp) \
  139. LOAD_ARGS_asm_5(r10, r11, r12, r13, mof) \
  140. "move %7,$srp\n\t"
  141. #define ASM_CLOBBER_6 ASM_CLOBBER_5, "srp"
  142. #define ASM_ARGS_6(r10, r11, r12, r13, mof, srp) \
  143. ASM_ARGS_5 (r10, r11, r12, r13, mof), "g" (srp)
  144. #define CHECK_ARGS_asm_6 CHECK_ARGS_asm_5
  145. #endif /* not __ASSEMBLER__ */
  146. #endif /* _BITS_SYSCALLS_H */