syscalls.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* Unlike the asm/unistd.h kernel header file (which this is partly based on),
  2. * this file must be able to cope with PIC and non-PIC code. For some arches
  3. * there is no difference. For x86 (which has far too few registers) there is
  4. * a difference. Regardless, including asm/unistd.h is hereby officially
  5. * forbidden. Don't do it. It is bad for you. */
  6. #include <features.h>
  7. #ifndef __UCLIBC_USE_UNIFIED_SYSCALL__
  8. #undef __syscall_return
  9. #define __syscall_return(type, res) \
  10. do { \
  11. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  12. errno = -(res); \
  13. res = -1; \
  14. } \
  15. return (type) (res); \
  16. } while (0)
  17. #undef _syscall0
  18. #define _syscall0(type,name) \
  19. type name(void) \
  20. { \
  21. long __res; \
  22. __asm__ volatile ("int $0x80" \
  23. : "=a" (__res) \
  24. : "0" (__NR_##name)); \
  25. __syscall_return(type,__res); \
  26. }
  27. #if defined(__PIC__)
  28. /*
  29. * PIC uses %ebx, so we need to save it during system calls
  30. */
  31. #undef _syscall1
  32. #define _syscall1(type,name,type1,arg1) \
  33. type name(type1 arg1) \
  34. { \
  35. long __res; \
  36. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  37. : "=a" (__res) \
  38. : "0" (__NR_##name),"r" ((long)(arg1))); \
  39. __syscall_return(type,__res); \
  40. }
  41. #undef _syscall2
  42. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  43. type name(type1 arg1,type2 arg2) \
  44. { \
  45. long __res; \
  46. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  47. : "=a" (__res) \
  48. : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2))); \
  49. __syscall_return(type,__res); \
  50. }
  51. #undef _syscall3
  52. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  53. type name(type1 arg1,type2 arg2,type3 arg3) \
  54. { \
  55. long __res; \
  56. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  57. : "=a" (__res) \
  58. : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
  59. "d" ((long)(arg3))); \
  60. __syscall_return(type,__res); \
  61. }
  62. #undef _syscall4
  63. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  64. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  65. { \
  66. long __res; \
  67. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  68. : "=a" (__res) \
  69. : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
  70. "d" ((long)(arg3)),"S" ((long)(arg4))); \
  71. __syscall_return(type,__res); \
  72. }
  73. #undef _syscall5
  74. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  75. type5,arg5) \
  76. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  77. { \
  78. long __res; \
  79. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  80. : "=a" (__res) \
  81. : "0" (__NR_##name),"m" ((long)(arg1)),"c" ((long)(arg2)), \
  82. "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
  83. __syscall_return(type,__res); \
  84. }
  85. #else /* not doing __PIC__ */
  86. #undef _syscall1
  87. #define _syscall1(type,name,type1,arg1) \
  88. type name(type1 arg1) \
  89. { \
  90. long __res; \
  91. __asm__ volatile ("int $0x80" \
  92. : "=a" (__res) \
  93. : "0" (__NR_##name),"b" ((long)(arg1))); \
  94. __syscall_return(type,__res); \
  95. }
  96. #undef _syscall2
  97. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  98. type name(type1 arg1,type2 arg2) \
  99. { \
  100. long __res; \
  101. __asm__ volatile ("int $0x80" \
  102. : "=a" (__res) \
  103. : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \
  104. __syscall_return(type,__res); \
  105. }
  106. #undef _syscall3
  107. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  108. type name(type1 arg1,type2 arg2,type3 arg3) \
  109. { \
  110. long __res; \
  111. __asm__ volatile ("int $0x80" \
  112. : "=a" (__res) \
  113. : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
  114. "d" ((long)(arg3))); \
  115. __syscall_return(type,__res); \
  116. }
  117. #undef _syscall4
  118. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  119. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  120. { \
  121. long __res; \
  122. __asm__ volatile ("int $0x80" \
  123. : "=a" (__res) \
  124. : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
  125. "d" ((long)(arg3)),"S" ((long)(arg4))); \
  126. __syscall_return(type,__res); \
  127. }
  128. #undef _syscall5
  129. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  130. type5,arg5) \
  131. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  132. { \
  133. long __res; \
  134. __asm__ volatile ("int $0x80" \
  135. : "=a" (__res) \
  136. : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
  137. "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
  138. __syscall_return(type,__res); \
  139. }
  140. #endif /* __PIC__ */
  141. #else
  142. #define unified_syscall_body(name) \
  143. __asm__ ( \
  144. ".text\n.align 4\n.global "###name"\n.type "###name",@function\n" \
  145. #name":\nmovb $"__STR_NR_##name \
  146. ",%al;\n jmp __uClibc_syscall\n.Lfe1"###name":\n.size "###name \
  147. ",.Lfe1"###name"-"###name \
  148. )
  149. #undef _syscall0
  150. #define _syscall0(type,name) \
  151. unified_syscall_body(name)
  152. #undef _syscall1
  153. #define _syscall1(type,name,type1,arg1) \
  154. unified_syscall_body(name)
  155. #undef _syscall2
  156. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  157. unified_syscall_body(name)
  158. #undef _syscall3
  159. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  160. unified_syscall_body(name)
  161. #undef _syscall4
  162. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  163. unified_syscall_body(name)
  164. #undef _syscall5
  165. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
  166. unified_syscall_body(name)
  167. #endif