syscalls.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #include <bits/wordsize.h>
  7. /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  8. * header files. It also defines the traditional `SYS_<name>' macros for older
  9. * programs. */
  10. #include <bits/sysnum.h>
  11. #ifndef __set_errno
  12. # define __set_errno(val) (*__errno_location ()) = (val)
  13. #endif
  14. #ifndef __ASSEMBLER__
  15. #undef __SYSCALL_STRING
  16. #if __WORDSIZE == 32
  17. # define __SYSCALL_STRING \
  18. "t 0x10\n\t" \
  19. "bcc 1f\n\t" \
  20. "mov %%o0, %0\n\t" \
  21. "sub %%g0, %%o0, %0\n\t" \
  22. "1:\n\t"
  23. # define __SYSCALL_RES_CHECK (__res < -255 || __res >= 0)
  24. #elif __WORDSIZE == 64
  25. # define __SYSCALL_STRING \
  26. "t 0x6d\n\t" \
  27. "sub %%g0, %%o0, %0\n\t" \
  28. "movcc %%xcc, %%o0, %0\n\t"
  29. # define __SYSCALL_RES_CHECK (__res >= 0)
  30. #else
  31. # error unknown __WORDSIZE
  32. #endif
  33. #define __SYSCALL_RETURN(type) \
  34. if (__SYSCALL_RES_CHECK) \
  35. return (type) __res; \
  36. __set_errno (-__res); \
  37. return (type) -1;
  38. #undef _syscall0
  39. #define _syscall0(type,name) \
  40. type name(void) \
  41. { \
  42. long __res; \
  43. register long __g1 __asm__ ("g1") = __NR_##name; \
  44. __asm__ __volatile__ (__SYSCALL_STRING \
  45. : "=r" (__res)\
  46. : "r" (__g1) \
  47. : "o0", "cc"); \
  48. __SYSCALL_RETURN(type) \
  49. }
  50. #undef _syscall1
  51. #define _syscall1(type,name,type1,arg1) \
  52. type name(type1 arg1) \
  53. { \
  54. long __res; \
  55. register long __g1 __asm__ ("g1") = __NR_##name; \
  56. register long __o0 __asm__ ("o0") = (long)(arg1); \
  57. __asm__ __volatile__ (__SYSCALL_STRING \
  58. : "=r" (__res), "=&r" (__o0) \
  59. : "1" (__o0), "r" (__g1) \
  60. : "cc"); \
  61. __SYSCALL_RETURN(type) \
  62. }
  63. #undef _syscall2
  64. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  65. type name(type1 arg1,type2 arg2) \
  66. { \
  67. long __res; \
  68. register long __g1 __asm__ ("g1") = __NR_##name; \
  69. register long __o0 __asm__ ("o0") = (long)(arg1); \
  70. register long __o1 __asm__ ("o1") = (long)(arg2); \
  71. __asm__ __volatile__ (__SYSCALL_STRING \
  72. : "=r" (__res), "=&r" (__o0) \
  73. : "1" (__o0), "r" (__o1), "r" (__g1) \
  74. : "cc"); \
  75. __SYSCALL_RETURN(type) \
  76. }
  77. #undef _syscall3
  78. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  79. type name(type1 arg1,type2 arg2,type3 arg3) \
  80. { \
  81. long __res; \
  82. register long __g1 __asm__ ("g1") = __NR_##name; \
  83. register long __o0 __asm__ ("o0") = (long)(arg1); \
  84. register long __o1 __asm__ ("o1") = (long)(arg2); \
  85. register long __o2 __asm__ ("o2") = (long)(arg3); \
  86. __asm__ __volatile__ (__SYSCALL_STRING \
  87. : "=r" (__res), "=&r" (__o0) \
  88. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) \
  89. : "cc"); \
  90. __SYSCALL_RETURN(type) \
  91. }
  92. #undef _syscall4
  93. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  94. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  95. { \
  96. long __res; \
  97. register long __g1 __asm__ ("g1") = __NR_##name; \
  98. register long __o0 __asm__ ("o0") = (long)(arg1); \
  99. register long __o1 __asm__ ("o1") = (long)(arg2); \
  100. register long __o2 __asm__ ("o2") = (long)(arg3); \
  101. register long __o3 __asm__ ("o3") = (long)(arg4); \
  102. __asm__ __volatile__ (__SYSCALL_STRING \
  103. : "=r" (__res), "=&r" (__o0) \
  104. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__g1) \
  105. : "cc"); \
  106. __SYSCALL_RETURN(type) \
  107. }
  108. #undef _syscall5
  109. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  110. type5,arg5) \
  111. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  112. { \
  113. long __res; \
  114. register long __g1 __asm__ ("g1") = __NR_##name; \
  115. register long __o0 __asm__ ("o0") = (long)(arg1); \
  116. register long __o1 __asm__ ("o1") = (long)(arg2); \
  117. register long __o2 __asm__ ("o2") = (long)(arg3); \
  118. register long __o3 __asm__ ("o3") = (long)(arg4); \
  119. register long __o4 __asm__ ("o4") = (long)(arg5); \
  120. __asm__ __volatile__ (__SYSCALL_STRING \
  121. : "=r" (__res), "=&r" (__o0) \
  122. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__g1) \
  123. : "cc"); \
  124. __SYSCALL_RETURN(type) \
  125. }
  126. #undef _syscall6
  127. #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  128. type5,arg5,type6,arg6) \
  129. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
  130. { \
  131. long __res; \
  132. register long __g1 __asm__ ("g1") = __NR_##name; \
  133. register long __o0 __asm__ ("o0") = (long)(arg1); \
  134. register long __o1 __asm__ ("o1") = (long)(arg2); \
  135. register long __o2 __asm__ ("o2") = (long)(arg3); \
  136. register long __o3 __asm__ ("o3") = (long)(arg4); \
  137. register long __o4 __asm__ ("o4") = (long)(arg5); \
  138. register long __o5 __asm__ ("o5") = (long)(arg6); \
  139. __asm__ __volatile__ (__SYSCALL_STRING \
  140. : "=r" (__res), "=&r" (__o0) \
  141. : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__o5), "r" (__g1) \
  142. : "cc"); \
  143. __SYSCALL_RETURN(type) \
  144. }
  145. #endif /* __ASSEMBLER__ */
  146. #endif /* _BITS_SYSCALLS_H */