syscalls.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. (__extension__ \
  34. ({ \
  35. unsigned int __res; \
  36. { \
  37. register long __o0 __asm__("o0"); \
  38. register long __g1 __asm__("g1") = sys_num; \
  39. LOAD_ARGS_##nr(args) \
  40. __asm__ __volatile__( __SYSCALL_STRING \
  41. : "=r" (__res), "=&r" (__o0) \
  42. : "1" (__o0) ASM_ARGS_##nr, "r" (__g1) \
  43. : __SYSCALL_CLOBBERS ); \
  44. } \
  45. (int)__res; \
  46. }) \
  47. )
  48. #define INTERNAL_SYSCALL_ERROR_P(val, err) \
  49. ((unsigned int) (val) >= 0xfffff001u)
  50. # define CALL_ERRNO_LOCATION "call __errno_location;"
  51. #define __CLONE_SYSCALL_STRING \
  52. "ta 0x10;" \
  53. "bcs 2f;" \
  54. " sub %%o1, 1, %%o1;" \
  55. "and %%o0, %%o1, %%o0;" \
  56. "1:" \
  57. ".subsection 2;" \
  58. "2:" \
  59. "save %%sp, -192, %%sp;" \
  60. CALL_ERRNO_LOCATION \
  61. " nop;" \
  62. "st %%i0, [%%o0];" \
  63. "ba 1b;" \
  64. " restore %%g0, -1, %%o0;" \
  65. ".previous;"
  66. #define INLINE_CLONE_SYSCALL(arg1,arg2,arg3,arg4,arg5) \
  67. ({ \
  68. register long __o0 __asm__ ("o0") = (long)(arg1); \
  69. register long __o1 __asm__ ("o1") = (long)(arg2); \
  70. register long __o2 __asm__ ("o2") = (long)(arg3); \
  71. register long __o3 __asm__ ("o3") = (long)(arg4); \
  72. register long __o4 __asm__ ("o4") = (long)(arg5); \
  73. register long __g1 __asm__ ("g1") = __NR_clone; \
  74. __asm__ __volatile__ (__CLONE_SYSCALL_STRING : \
  75. "=r" (__g1), "=r" (__o0), "=r" (__o1) : \
  76. "0" (__g1), "1" (__o0), "2" (__o1), \
  77. "r" (__o2), "r" (__o3), "r" (__o4) : \
  78. __SYSCALL_CLOBBERS); \
  79. __o0; \
  80. })
  81. #define LOAD_ARGS_0()
  82. #define ASM_ARGS_0
  83. #define LOAD_ARGS_1(o0) \
  84. __o0 = (int)o0; \
  85. LOAD_ARGS_0()
  86. #define ASM_ARGS_1 ASM_ARGS_0, "r" (__o0)
  87. #define LOAD_ARGS_2(o0, o1) \
  88. register int __o1 __asm__ ("o1") = (int) (o1); \
  89. LOAD_ARGS_1 (o0)
  90. #define ASM_ARGS_2 ASM_ARGS_1, "r" (__o1)
  91. #define LOAD_ARGS_3(o0, o1, o2) \
  92. register int __o2 __asm__ ("o2") = (int) (o2); \
  93. LOAD_ARGS_2 (o0, o1)
  94. #define ASM_ARGS_3 ASM_ARGS_2, "r" (__o2)
  95. #define LOAD_ARGS_4(o0, o1, o2, o3) \
  96. register int __o3 __asm__ ("o3") = (int) (o3); \
  97. LOAD_ARGS_3 (o0, o1, o2)
  98. #define ASM_ARGS_4 ASM_ARGS_3, "r" (__o3)
  99. #define LOAD_ARGS_5(o0, o1, o2, o3, o4) \
  100. register int __o4 __asm__ ("o4") = (int) (o4); \
  101. LOAD_ARGS_4 (o0, o1, o2, o3)
  102. #define ASM_ARGS_5 ASM_ARGS_4, "r" (__o4)
  103. #define LOAD_ARGS_6(o0, o1, o2, o3, o4, o5) \
  104. register int __o5 __asm__ ("o5") = (int) (o5); \
  105. LOAD_ARGS_5 (o0, o1, o2, o3, o4)
  106. #define ASM_ARGS_6 ASM_ARGS_5, "r" (__o5)
  107. #endif /* __ASSEMBLER__ */
  108. #endif /* _BITS_SYSCALLS_H */