syscalls.h 4.8 KB

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