1 /* libc/sys/linux/machine/i386/syscall.h - x86 linux system calls */ 2 3 /* Written 2000 by Werner Almesberger */ 4 5 6 #ifndef SYSCALL_H 7 8 #include <machine/weakalias.h> 9 #include <sys/errno.h> 10 #include <asm/unistd.h> 11 12 13 /* 14 * Note: several system calls are for SysV or BSD compatibility, or are 15 * specific Linuxisms. Most of those system calls are not implemented in 16 * this library. 17 */ 18 19 20 #if defined(__PIC__) && defined(__i386__) 21 22 /* 23 * PIC uses %ebx, so we need to save it during system calls 24 */ 25 26 #undef __inline_syscall0 27 #define __inline_syscall0(name,ret) \ 28 __asm__ volatile ("int $0x80" \ 29 : "=a" (ret) \ 30 : "0" (__NR_##name)); 31 32 #undef __inline_syscall1 33 #define __inline_syscall1(name,ret,arg1) \ 34 __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ 35 : "=a" (ret) \ 36 : "0" (__NR_##name),"r" ((long)(arg1))); 37 38 #undef __inline_syscall2 39 #define __inline_syscall2(name,ret,arg1,arg2) \ 40 __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ 41 : "=a" (ret) \ 42 : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2))); 43 44 #undef __inline_syscall3 45 #define __inline_syscall3(name,ret,arg1,arg2,arg3) \ 46 __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ 47 : "=a" (ret) \ 48 : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \ 49 "d" ((long)(arg3))); 50 51 #undef __inline_syscall4 52 #define __inline_syscall4(name,ret,arg1,arg2,arg3,arg4) \ 53 __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ 54 : "=a" (ret) \ 55 : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \ 56 "d" ((long)(arg3)),"S" ((long)(arg4))); 57 58 #undef __inline_syscall5 59 #define __inline_syscall5(name,ret,arg1,arg2,arg3,arg4,arg5) \ 60 __asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ 61 : "=a" (ret) \ 62 : "0" (__NR_##name),"m" ((long)(arg1)),"c" ((long)(arg2)), \ 63 "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); 64 65 #undef __inline_syscall6 66 #define __inline_syscall6(name,ret,arg1,arg2,arg3,arg4,arg5,arg6) \ 67 __asm__ volatile ("push %%ebx; lea 8(%%ebp),%%ebx; int $0x80; pop %%ebx" \ 68 : "=a" (ret) \ 69 : "0" (__NR_##name)); 70 71 #undef _syscall0_base 72 #define _syscall0_base(type,name) \ 73 type __libc_##name (void) \ 74 { \ 75 long __res; \ 76 __inline_syscall0(name,__res) \ 77 __syscall_return(type,__res); \ 78 } 79 80 #undef _syscall0 81 #define _syscall0(type,name) \ 82 _syscall0_base(type,name) \ 83 weak_alias(__libc_##name,name); 84 85 #undef _syscall1_base 86 #define _syscall1_base(type,name,type1,arg1) \ 87 type __libc_##name (type1 arg1) \ 88 { \ 89 long __res; \ 90 __inline_syscall1(name,__res,arg1) \ 91 __syscall_return(type,__res); \ 92 } 93 94 #undef _syscall1 95 #define _syscall1(type,name,type1,arg1) \ 96 _syscall1_base(type,name,type1,arg1) \ 97 weak_alias(__libc_##name,name); 98 99 #undef _syscall2_base 100 #define _syscall2_base(type,name,type1,arg1,type2,arg2) \ 101 type __libc_##name (type1 arg1,type2 arg2) \ 102 { \ 103 long __res; \ 104 __inline_syscall2(name,__res,arg1,arg2) \ 105 __syscall_return(type,__res); \ 106 } 107 108 #undef _syscall2 109 #define _syscall2(type,name,type1,arg1,type2,arg2) \ 110 _syscall2_base(type,name,type1,arg1,type2,arg2) \ 111 weak_alias(__libc_##name,name); 112 113 #undef _syscall3_base 114 #define _syscall3_base(type,name,type1,arg1,type2,arg2,type3,arg3) \ 115 type __libc_##name (type1 arg1,type2 arg2,type3 arg3) \ 116 { \ 117 long __res; \ 118 __inline_syscall3(name,__res,arg1,arg2,arg3) \ 119 __syscall_return(type,__res); \ 120 } 121 122 #undef _syscall3 123 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ 124 _syscall3_base(type,name,type1,arg1,type2,arg2,type3,arg3) \ 125 weak_alias(__libc_##name,name); 126 127 #undef _syscall4_base 128 #define _syscall4_base(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ 129 type __libc_##name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ 130 { \ 131 long __res; \ 132 __inline_syscall4(name,__res,arg1,arg2,arg3,arg4) \ 133 __syscall_return(type,__res); \ 134 } 135 136 #undef _syscall4 137 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ 138 _syscall4_base(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ 139 weak_alias(__libc_##name,name); 140 141 #undef _syscall5_base 142 #define _syscall5_base(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ 143 type5,arg5) \ 144 type __libc_##name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ 145 { \ 146 long __res; \ 147 __inline_syscall5(name,__res,arg1,arg2,arg3,arg4,arg5) \ 148 __syscall_return(type,__res); \ 149 } \ 150 151 #undef _syscall5 152 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ 153 type5,arg5) \ 154 _syscall5_base(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ 155 weak_alias(__libc_##name,name); 156 157 #undef _syscall6_base 158 #define _syscall6_base(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ 159 type5,arg5,type6,arg6) \ 160 type __libc_##name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \ 161 { \ 162 long __res; \ 163 __inline_syscall6(name,__res,arg1,arg2,arg3,arg4,arg5,arg6) \ 164 __syscall_return(type,__res); \ 165 } 166 167 #undef _syscall6 168 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ 169 type5,arg5,type6,arg6) \ 170 _syscall6_base(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \ 171 weak_alias(__libc_##name,name); 172 173 #endif /* __PIC__ && __i386__ */ 174 175 #endif /* SYSCALL_H */ 176