syscalls.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <asm/unistd.h>
  2. #undef __syscall_return
  3. #define __syscall_return(type, res) \
  4. do { \
  5. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  6. errno = -(res); \
  7. res = -1; \
  8. } \
  9. return (type) (res); \
  10. } while (0)
  11. #if defined(__PIC__)
  12. /*
  13. * PIC uses %ebx, so we need to save it during system calls
  14. */
  15. #undef _syscall1
  16. #define _syscall1(type,name,type1,arg1) \
  17. type name(type1 arg1) \
  18. { \
  19. long __res; \
  20. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  21. : "=a" (__res) \
  22. : "0" (__NR_##name),"r" ((long)(arg1))); \
  23. __syscall_return(type,__res); \
  24. }
  25. #undef _syscall2
  26. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  27. type name(type1 arg1,type2 arg2) \
  28. { \
  29. long __res; \
  30. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  31. : "=a" (__res) \
  32. : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2))); \
  33. __syscall_return(type,__res); \
  34. }
  35. #undef _syscall3
  36. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  37. type name(type1 arg1,type2 arg2,type3 arg3) \
  38. { \
  39. long __res; \
  40. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  41. : "=a" (__res) \
  42. : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
  43. "d" ((long)(arg3))); \
  44. __syscall_return(type,__res); \
  45. }
  46. #undef _syscall4
  47. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  48. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  49. { \
  50. long __res; \
  51. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  52. : "=a" (__res) \
  53. : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \
  54. "d" ((long)(arg3)),"S" ((long)(arg4))); \
  55. __syscall_return(type,__res); \
  56. }
  57. #undef _syscall5
  58. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  59. type5,arg5) \
  60. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  61. { \
  62. long __res; \
  63. __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
  64. : "=a" (__res) \
  65. : "0" (__NR_##name),"m" ((long)(arg1)),"c" ((long)(arg2)), \
  66. "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
  67. __syscall_return(type,__res); \
  68. }
  69. #endif /* __PIC__ */