syscalls.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef _BITS_SYSCALLS_H
  2. #define _BITS_SYSCALLS_H
  3. #ifndef _SYSCALL_H
  4. # error "Never use <bits/syscalls.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. /* user-visible error numbers are in the range -1 - -4095: see <asm-frv/errno.h> */
  10. #if defined _LIBC && !defined __set_errno
  11. # define __syscall_return(type, res) \
  12. do { \
  13. unsigned long __sr2 = (res); \
  14. if (__builtin_expect ((unsigned long)(__sr2) \
  15. >= (unsigned long)(-4095), 0)) { \
  16. extern int __syscall_error (int); \
  17. return (type) __syscall_error (__sr2); \
  18. } \
  19. return (type) (__sr2); \
  20. } while (0)
  21. #else
  22. # define __syscall_return(type, res) \
  23. do { \
  24. unsigned long __sr2 = (res); \
  25. if (__builtin_expect ((unsigned long)(__sr2) \
  26. >= (unsigned long)(-4095), 0)) { \
  27. __set_errno (-__sr2); \
  28. __sr2 = -1; \
  29. } \
  30. return (type) (__sr2); \
  31. } while (0)
  32. #endif
  33. #define _syscall0(type,name) \
  34. type name(void) { \
  35. long __res; \
  36. __asm__ __volatile__ ( \
  37. "excpt 0;\n\t" \
  38. : "=q0" (__res) \
  39. : "qA" (__NR_##name) \
  40. : "memory","CC"); \
  41. __syscall_return(type,__res); \
  42. }
  43. #define _syscall1(type,name,type1,arg1) \
  44. type name(type1 arg1) { \
  45. long __res; \
  46. __asm__ __volatile__ ( \
  47. "excpt 0;\n\t" \
  48. : "=q0" (__res) \
  49. : "qA" (__NR_##name), \
  50. "q0" ((long)(arg1)) \
  51. : "memory","CC"); \
  52. __syscall_return(type,__res); \
  53. }
  54. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  55. type name(type1 arg1,type2 arg2) { \
  56. long __res; \
  57. __asm__ __volatile__ ( \
  58. "excpt 0;\n\t" \
  59. "%0=r0;\n\t" \
  60. : "=q0" (__res) \
  61. : "qA" (__NR_##name), \
  62. "q0" ((long)(arg1)), \
  63. "q1" ((long)(arg2)) \
  64. : "memory","CC"); \
  65. __syscall_return(type,__res); \
  66. }
  67. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  68. type name(type1 arg1,type2 arg2,type3 arg3) { \
  69. long __res; \
  70. __asm__ __volatile__ ( \
  71. "excpt 0;\n\t" \
  72. : "=q0" (__res) \
  73. : "qA" (__NR_##name), \
  74. "q0" ((long)(arg1)), \
  75. "q1" ((long)(arg2)), \
  76. "q2" ((long)(arg3)) \
  77. : "memory","CC"); \
  78. __syscall_return(type,__res); \
  79. }
  80. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\
  81. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  82. long __res; \
  83. __asm__ __volatile__ ( \
  84. "excpt 0;\n\t" \
  85. : "=q0" (__res) \
  86. : "qA" (__NR_##name), \
  87. "q0" ((long)(arg1)), \
  88. "q1" ((long)(arg2)), \
  89. "q2" ((long)(arg3)), \
  90. "q3" ((long)(arg4)) \
  91. : "memory","CC"); \
  92. __syscall_return(type,__res); \
  93. }
  94. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  95. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \
  96. long __res; \
  97. __asm__ __volatile__ ( \
  98. "excpt 0;\n\t" \
  99. : "=q0" (__res) \
  100. : "qA" (__NR_##name), \
  101. "q0" ((long)(arg1)), \
  102. "q1" ((long)(arg2)), \
  103. "q2" ((long)(arg3)), \
  104. "q3" ((long)(arg4)), \
  105. "q4" ((long)(arg5)) \
  106. : "memory","CC"); \
  107. __syscall_return(type,__res); \
  108. }
  109. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \
  110. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) { \
  111. long __res; \
  112. __asm__ __volatile__ ( \
  113. "excpt 0;\n\t" \
  114. : "=q0" (__res) \
  115. : "qA" (__NR_##name), \
  116. "q0" ((long)(arg1)), \
  117. "q1" ((long)(arg2)), \
  118. "q2" ((long)(arg3)), \
  119. "q3" ((long)(arg4)), \
  120. "q4" ((long)(arg5)), \
  121. "q5" ((long)(arg6)) \
  122. : "memory","CC"); \
  123. __syscall_return(type,__res); \
  124. }
  125. #endif /* __ASSEMBLER__ */
  126. #endif /* _BITS_SYSCALLS_H */