syscalls.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _BITS_SYSCALLS_H
  2. #define _BITS_SYSCALLS_H
  3. #ifndef _SYSCALL_H
  4. # error "Never use <bits/syscall.h> directly; include <sys/syscall.h> instead."
  5. #endif
  6. /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  7. * header files. It also defines the traditional `SYS_<name>' macros for older
  8. * programs. */
  9. #include <bits/syscall.h>
  10. #ifndef __set_errno
  11. # define __set_errno(val) (*__errno_location ()) = (val)
  12. #endif
  13. #ifndef SYS_ify
  14. # define SYS_ify(syscall_name) (__NR_##syscall_name)
  15. #endif
  16. /*
  17. Some of the sneaky macros in the code were taken from
  18. glibc-2.2.5/sysdeps/unix/sysv/linux/arm/sysdep.h
  19. */
  20. #ifndef __ASSEMBLER__
  21. #undef _syscall0
  22. #define _syscall0(type,name) \
  23. type name(void) \
  24. { \
  25. return (type) (INLINE_SYSCALL(name, 0)); \
  26. }
  27. #undef _syscall1
  28. #define _syscall1(type,name,type1,arg1) \
  29. type name(type1 arg1) \
  30. { \
  31. return (type) (INLINE_SYSCALL(name, 1, arg1)); \
  32. }
  33. #undef _syscall2
  34. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  35. type name(type1 arg1,type2 arg2) \
  36. { \
  37. return (type) (INLINE_SYSCALL(name, 2, arg1, arg2)); \
  38. }
  39. #undef _syscall3
  40. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  41. type name(type1 arg1,type2 arg2,type3 arg3) \
  42. { \
  43. return (type) (INLINE_SYSCALL(name, 3, arg1, arg2, arg3)); \
  44. }
  45. #undef _syscall4
  46. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  47. type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  48. { \
  49. return (type) (INLINE_SYSCALL(name, 4, arg1, arg2, arg3, arg4)); \
  50. }
  51. #undef _syscall5
  52. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  53. type5,arg5) \
  54. type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  55. { \
  56. return (type) (INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5)); \
  57. }
  58. #undef INLINE_SYSCALL
  59. #define INLINE_SYSCALL(name, nr, args...) \
  60. ({ unsigned int _sys_result; \
  61. { \
  62. register int _a1 asm ("a1"); \
  63. LOAD_ARGS_##nr (args) \
  64. asm volatile ("swi %1 @ syscall " #name \
  65. : "=r" (_a1) \
  66. : "i" (SYS_ify(name)) ASM_ARGS_##nr \
  67. : "a1", "memory"); \
  68. _sys_result = _a1; \
  69. } \
  70. if (_sys_result >= (unsigned int) -4095) \
  71. { \
  72. __set_errno (-_sys_result); \
  73. _sys_result = (unsigned int) -1; \
  74. } \
  75. (int) _sys_result; })
  76. #define LOAD_ARGS_0()
  77. #define ASM_ARGS_0
  78. #define LOAD_ARGS_1(a1) \
  79. _a1 = (int) (a1); \
  80. LOAD_ARGS_0 ()
  81. #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
  82. #define LOAD_ARGS_2(a1, a2) \
  83. register int _a2 asm ("a2") = (int) (a2); \
  84. LOAD_ARGS_1 (a1)
  85. #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
  86. #define LOAD_ARGS_3(a1, a2, a3) \
  87. register int _a3 asm ("a3") = (int) (a3); \
  88. LOAD_ARGS_2 (a1, a2)
  89. #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
  90. #define LOAD_ARGS_4(a1, a2, a3, a4) \
  91. register int _a4 asm ("a4") = (int) (a4); \
  92. LOAD_ARGS_3 (a1, a2, a3)
  93. #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
  94. #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  95. register int _v1 asm ("v1") = (int) (a5); \
  96. LOAD_ARGS_4 (a1, a2, a3, a4)
  97. #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
  98. #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  99. register int _v2 asm ("v2") = (int) (a6); \
  100. LOAD_ARGS_5 (a1, a2, a3, a4, a5)
  101. #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
  102. #define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
  103. register int _v3 asm ("v3") = (int) (a7); \
  104. LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
  105. #define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
  106. #endif /* __ASSEMBLER__ */
  107. #endif /* _BITS_SYSCALLS_H */