syscalls.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #ifndef __ASSEMBLER__
  8. #if __WORDSIZE == 32
  9. # define __SYSCALL_STRING \
  10. "t 0x10\n\t" \
  11. "bcc 1f\n\t" \
  12. "mov %%o0, %0\n\t" \
  13. "sub %%g0, %%o0, %0\n\t" \
  14. "1:\n\t"
  15. #elif __WORDSIZE == 64
  16. # define __SYSCALL_STRING \
  17. "t 0x6d\n\t" \
  18. "sub %%g0, %%o0, %0\n\t" \
  19. "movcc %%xcc, %%o0, %0\n\t"
  20. #else
  21. # error unknown __WORDSIZE
  22. #endif
  23. #define __SYSCALL_CLOBBERS "cc", "memory"
  24. #ifndef NOT_IN_libc
  25. #define DEBUG_SYSCALL(name) { \
  26. char d[64];\
  27. write( 2, d, snprintf( d, 64, "syscall %d error %d\n", __NR_##name, _inline_sys_result)); \
  28. }
  29. #else
  30. #define DEBUG_SYSCALL(name) do{} while(0)
  31. #endif
  32. #define INTERNAL_SYSCALL_NCS(sys_num, err, nr, args...) \
  33. ({ \
  34. unsigned int __res; \
  35. { \
  36. register long __o0 __asm__("o0"); \
  37. register long __g1 __asm__("g1") = sys_num; \
  38. LOAD_ARGS_##nr(args) \
  39. __asm__ __volatile__( __SYSCALL_STRING \
  40. : "=r" (__res), "=&r" (__o0) \
  41. : "1" (__o0) ASM_ARGS_##nr, "r" (__g1) \
  42. : __SYSCALL_CLOBBERS ); \
  43. } \
  44. (int)__res; \
  45. })
  46. #define INTERNAL_SYSCALL_ERROR_P(val, err) \
  47. ((unsigned int) (val) >= 0xfffff001u)
  48. # define CALL_ERRNO_LOCATION "call __errno_location;"
  49. #define __CLONE_SYSCALL_STRING \
  50. "ta 0x10;" \
  51. "bcs 2f;" \
  52. " sub %%o1, 1, %%o1;" \
  53. "and %%o0, %%o1, %%o0;" \
  54. "1:" \
  55. ".subsection 2;" \
  56. "2:" \
  57. "save %%sp, -192, %%sp;" \
  58. CALL_ERRNO_LOCATION \
  59. " nop;" \
  60. "st %%i0, [%%o0];" \
  61. "ba 1b;" \
  62. " restore %%g0, -1, %%o0;" \
  63. ".previous;"
  64. #define INLINE_CLONE_SYSCALL(arg1,arg2,arg3,arg4,arg5) \
  65. ({ \
  66. register long __o0 __asm__ ("o0") = (long)(arg1); \
  67. register long __o1 __asm__ ("o1") = (long)(arg2); \
  68. register long __o2 __asm__ ("o2") = (long)(arg3); \
  69. register long __o3 __asm__ ("o3") = (long)(arg4); \
  70. register long __o4 __asm__ ("o4") = (long)(arg5); \
  71. register long __g1 __asm__ ("g1") = __NR_clone; \
  72. __asm__ __volatile__ (__CLONE_SYSCALL_STRING : \
  73. "=r" (__g1), "=r" (__o0), "=r" (__o1) : \
  74. "0" (__g1), "1" (__o0), "2" (__o1), \
  75. "r" (__o2), "r" (__o3), "r" (__o4) : \
  76. __SYSCALL_CLOBBERS); \
  77. __o0; \
  78. })
  79. #define LOAD_ARGS_0()
  80. #define ASM_ARGS_0
  81. #define LOAD_ARGS_1(o0) \
  82. __o0 = (int)o0; \
  83. LOAD_ARGS_0()
  84. #define ASM_ARGS_1 ASM_ARGS_0, "r" (__o0)
  85. #define LOAD_ARGS_2(o0, o1) \
  86. register int __o1 __asm__ ("o1") = (int) (o1); \
  87. LOAD_ARGS_1 (o0)
  88. #define ASM_ARGS_2 ASM_ARGS_1, "r" (__o1)
  89. #define LOAD_ARGS_3(o0, o1, o2) \
  90. register int __o2 __asm__ ("o2") = (int) (o2); \
  91. LOAD_ARGS_2 (o0, o1)
  92. #define ASM_ARGS_3 ASM_ARGS_2, "r" (__o2)
  93. #define LOAD_ARGS_4(o0, o1, o2, o3) \
  94. register int __o3 __asm__ ("o3") = (int) (o3); \
  95. LOAD_ARGS_3 (o0, o1, o2)
  96. #define ASM_ARGS_4 ASM_ARGS_3, "r" (__o3)
  97. #define LOAD_ARGS_5(o0, o1, o2, o3, o4) \
  98. register int __o4 __asm__ ("o4") = (int) (o4); \
  99. LOAD_ARGS_4 (o0, o1, o2, o3)
  100. #define ASM_ARGS_5 ASM_ARGS_4, "r" (__o4)
  101. #define LOAD_ARGS_6(o0, o1, o2, o3, o4, o5) \
  102. register int __o5 __asm__ ("o5") = (int) (o5); \
  103. LOAD_ARGS_5 (o0, o1, o2, o3, o4)
  104. #define ASM_ARGS_6 ASM_ARGS_5, "r" (__o5)
  105. #endif /* __ASSEMBLER__ */
  106. #endif /* _BITS_SYSCALLS_H */