syscalls.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. #undef __syscall_return
  7. #define __syscall_return(type, res) \
  8. do { \
  9. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  10. errno = -(res); \
  11. res = -1; \
  12. } \
  13. return (type) (res); \
  14. } while (0)
  15. #undef _syscall0
  16. #define _syscall0(type,name) \
  17. type name(void) \
  18. { \
  19. long __res; \
  20. __asm__ volatile ("int $0x80" \
  21. : "=a" (__res) \
  22. : "0" (__NR_##name)); \
  23. __syscall_return(type,__res); \
  24. }
  25. #if defined(__PIC__)
  26. /*
  27. * PIC uses %ebx, so we need to save it during system calls
  28. */
  29. #undef _syscall1
  30. #define _syscall1(type,name,type1,arg1) \
  31. type name(type1 arg1) \
  32. { \
  33. long __res; \
  34. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  35. : "=a" (__res) \
  36. : "0" (__NR_##name),"r" ((long)(arg1))); \
  37. __syscall_return(type,__res); \
  38. }
  39. #undef _syscall2
  40. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  41. type name(type1 arg1,type2 arg2) \
  42. { \
  43. long __res; \
  44. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  45. : "=a" (__res) \
  46. : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2))); \
  47. __syscall_return(type,__res); \
  48. }
  49. #undef _syscall3
  50. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  51. type name(type1 arg1,type2 arg2,type3 arg3) \
  52. { \
  53. long __res; \
  54. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  55. : "=a" (__res) \
  56. : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
  57. "d" ((long)(arg3))); \
  58. __syscall_return(type,__res); \
  59. }
  60. #undef _syscall4
  61. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  62. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  63. { \
  64. long __res; \
  65. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  66. : "=a" (__res) \
  67. : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
  68. "d" ((long)(arg3)),"S" ((long)(arg4))); \
  69. __syscall_return(type,__res); \
  70. }
  71. #undef _syscall5
  72. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  73. type5,arg5) \
  74. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  75. { \
  76. long __res; \
  77. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  78. : "=a" (__res) \
  79. : "0" (__NR_##name),"m" ((long)(arg1)),"c" ((long)(arg2)), \
  80. "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
  81. __syscall_return(type,__res); \
  82. }
  83. #else /* not doing __PIC__ */
  84. #undef _syscall1
  85. #define _syscall1(type,name,type1,arg1) \
  86. type name(type1 arg1) \
  87. { \
  88. long __res; \
  89. __asm__ volatile ("int $0x80" \
  90. : "=a" (__res) \
  91. : "0" (__NR_##name),"b" ((long)(arg1))); \
  92. __syscall_return(type,__res); \
  93. }
  94. #undef _syscall2
  95. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  96. type name(type1 arg1,type2 arg2) \
  97. { \
  98. long __res; \
  99. __asm__ volatile ("int $0x80" \
  100. : "=a" (__res) \
  101. : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \
  102. __syscall_return(type,__res); \
  103. }
  104. #undef _syscall3
  105. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  106. type name(type1 arg1,type2 arg2,type3 arg3) \
  107. { \
  108. long __res; \
  109. __asm__ volatile ("int $0x80" \
  110. : "=a" (__res) \
  111. : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
  112. "d" ((long)(arg3))); \
  113. __syscall_return(type,__res); \
  114. }
  115. #undef _syscall4
  116. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  117. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  118. { \
  119. long __res; \
  120. __asm__ volatile ("int $0x80" \
  121. : "=a" (__res) \
  122. : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
  123. "d" ((long)(arg3)),"S" ((long)(arg4))); \
  124. __syscall_return(type,__res); \
  125. }
  126. #undef _syscall5
  127. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  128. type5,arg5) \
  129. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  130. { \
  131. long __res; \
  132. __asm__ volatile ("int $0x80" \
  133. : "=a" (__res) \
  134. : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \
  135. "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
  136. __syscall_return(type,__res); \
  137. }
  138. #endif /* __PIC__ */