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