Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame^] | 1 | struct syscall_result { |
| 2 | long val; |
| 3 | int errno; |
| 4 | }; |
| 5 | |
| 6 | static struct syscall_result syscall_return(long result) |
| 7 | { |
| 8 | struct syscall_result res; |
| 9 | if (((unsigned long)result) >= ((unsigned long)-125)) { |
| 10 | res.errno = - result; |
| 11 | res.val = -1; |
| 12 | } else { |
| 13 | res.errno = 0; |
| 14 | res.val = result; |
| 15 | } |
| 16 | return res; |
| 17 | } |
| 18 | |
| 19 | static struct syscall_result syscall0(unsigned long nr) |
| 20 | { |
| 21 | long res; |
| 22 | asm volatile( |
| 23 | "int $0x80" |
| 24 | : "=a" (res) |
| 25 | : "a" (nr)); |
| 26 | return syscall_return(res); |
| 27 | } |
| 28 | |
| 29 | static struct syscall_result syscall1(unsigned long nr, unsigned long arg1) |
| 30 | { |
| 31 | long res; |
| 32 | asm volatile( |
| 33 | "int $0x80" |
| 34 | : "=a" (res) |
| 35 | : "a" (nr), "b" (arg1)); |
| 36 | return syscall_return(res); |
| 37 | |
| 38 | } |
| 39 | |
| 40 | static struct syscall_result syscall2(unsigned long nr, unsigned long arg1, unsigned long arg2) |
| 41 | { |
| 42 | long res; |
| 43 | asm volatile( |
| 44 | "int $0x80" |
| 45 | : "=a" (res) |
| 46 | : "a" (nr), "b" (arg1), "c" (arg2)); |
| 47 | return syscall_return(res); |
| 48 | |
| 49 | } |
| 50 | |
| 51 | |
| 52 | static struct syscall_result syscall3(unsigned long nr, unsigned long arg1, unsigned long arg2, |
| 53 | unsigned long arg3) |
| 54 | { |
| 55 | long res; |
| 56 | asm volatile( |
| 57 | "int $0x80" |
| 58 | : "=a" (res) |
| 59 | : "a" (nr), "b" (arg1), "c" (arg2), "d" (arg3)); |
| 60 | return syscall_return(res); |
| 61 | |
| 62 | } |
| 63 | |
| 64 | static struct syscall_result syscall4(unsigned long nr, unsigned long arg1, unsigned long arg2, |
| 65 | unsigned long arg3, unsigned long arg4) |
| 66 | { |
| 67 | long res; |
| 68 | asm volatile( |
| 69 | "int $0x80" |
| 70 | : "=a" (res) |
| 71 | : "a" (nr), "b" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)); |
| 72 | return syscall_return(res); |
| 73 | |
| 74 | } |
| 75 | |
| 76 | static struct syscall_result syscall5(unsigned long nr, unsigned long arg1, unsigned long arg2, |
| 77 | unsigned long arg3, unsigned long arg4, unsigned long arg5) |
| 78 | { |
| 79 | long res; |
| 80 | asm volatile( |
| 81 | "int $0x80" |
| 82 | : "=a" (res) |
| 83 | : "a" (nr), "b" (arg1), "c" (arg2), "d" (arg3), |
| 84 | "S" (arg4), "D" (arg5)); |
| 85 | return syscall_return(res); |
| 86 | |
| 87 | } |
| 88 | |
| 89 | #define NR_exit 1 |
| 90 | #define NR_fork 2 |
| 91 | #define NR_read 3 |
| 92 | #define NR_write 4 |
| 93 | #define NR_open 5 |
| 94 | #define NR_close 6 |
| 95 | #define NR_waitpid 7 |
| 96 | #define NR_creat 8 |
| 97 | #define NR_link 9 |
| 98 | #define NR_unlink 10 |
| 99 | #define NR_execve 11 |
| 100 | #define NR_chdir 12 |
| 101 | #define NR_time 13 |
| 102 | #define NR_mknod 14 |
| 103 | #define NR_chmod 15 |
| 104 | #define NR_lchown 16 |
| 105 | #define NR_break 17 |
| 106 | #define NR_oldstat 18 |
| 107 | #define NR_lseek 19 |
| 108 | #define NR_getpid 20 |
| 109 | #define NR_mount 21 |
| 110 | #define NR_umount 22 |
| 111 | #define NR_setuid 23 |
| 112 | #define NR_getuid 24 |
| 113 | #define NR_stime 25 |
| 114 | #define NR_ptrace 26 |
| 115 | #define NR_alarm 27 |
| 116 | #define NR_oldfstat 28 |
| 117 | #define NR_pause 29 |
| 118 | #define NR_utime 30 |
| 119 | #define NR_stty 31 |
| 120 | #define NR_gtty 32 |
| 121 | #define NR_access 33 |
| 122 | #define NR_nice 34 |
| 123 | #define NR_ftime 35 |
| 124 | #define NR_sync 36 |
| 125 | #define NR_kill 37 |
| 126 | #define NR_rename 38 |
| 127 | #define NR_mkdir 39 |
| 128 | #define NR_rmdir 40 |
| 129 | #define NR_dup 41 |
| 130 | #define NR_pipe 42 |
| 131 | #define NR_times 43 |
| 132 | #define NR_prof 44 |
| 133 | #define NR_brk 45 |
| 134 | #define NR_setgid 46 |
| 135 | #define NR_getgid 47 |
| 136 | #define NR_signal 48 |
| 137 | #define NR_geteuid 49 |
| 138 | #define NR_getegid 50 |
| 139 | #define NR_acct 51 |
| 140 | #define NR_umount2 52 |
| 141 | #define NR_lock 53 |
| 142 | #define NR_ioctl 54 |
| 143 | #define NR_fcntl 55 |
| 144 | #define NR_mpx 56 |
| 145 | #define NR_setpgid 57 |
| 146 | #define NR_ulimit 58 |
| 147 | #define NR_oldolduname 59 |
| 148 | #define NR_umask 60 |
| 149 | #define NR_chroot 61 |
| 150 | #define NR_ustat 62 |
| 151 | #define NR_dup2 63 |
| 152 | #define NR_getppid 64 |
| 153 | #define NR_getpgrp 65 |
| 154 | #define NR_setsid 66 |
| 155 | #define NR_sigaction 67 |
| 156 | #define NR_sgetmask 68 |
| 157 | #define NR_ssetmask 69 |
| 158 | #define NR_setreuid 70 |
| 159 | #define NR_setregid 71 |
| 160 | #define NR_sigsuspend 72 |
| 161 | #define NR_sigpending 73 |
| 162 | #define NR_sethostname 74 |
| 163 | #define NR_setrlimit 75 |
| 164 | #define NR_getrlimit 76 |
| 165 | #define NR_getrusage 77 |
| 166 | #define NR_gettimeofday 78 |
| 167 | #define NR_settimeofday 79 |
| 168 | #define NR_getgroups 80 |
| 169 | #define NR_setgroups 81 |
| 170 | #define NR_select 82 |
| 171 | #define NR_symlink 83 |
| 172 | #define NR_oldlstat 84 |
| 173 | #define NR_readlink 85 |
| 174 | #define NR_uselib 86 |
| 175 | #define NR_swapon 87 |
| 176 | #define NR_reboot 88 |
| 177 | #define NR_readdir 89 |
| 178 | #define NR_mmap 90 |
| 179 | #define NR_munmap 91 |
| 180 | #define NR_truncate 92 |
| 181 | #define NR_ftruncate 93 |
| 182 | #define NR_fchmod 94 |
| 183 | #define NR_fchown 95 |
| 184 | #define NR_getpriority 96 |
| 185 | #define NR_setpriority 97 |
| 186 | #define NR_profil 98 |
| 187 | #define NR_statfs 99 |
| 188 | #define NR_fstatfs 100 |
| 189 | #define NR_ioperm 101 |
| 190 | #define NR_socketcall 102 |
| 191 | #define NR_syslog 103 |
| 192 | #define NR_setitimer 104 |
| 193 | #define NR_getitimer 105 |
| 194 | #define NR_stat 106 |
| 195 | #define NR_lstat 107 |
| 196 | #define NR_fstat 108 |
| 197 | #define NR_olduname 109 |
| 198 | #define NR_iopl 110 |
| 199 | #define NR_vhangup 111 |
| 200 | #define NR_idle 112 |
| 201 | #define NR_vm86old 113 |
| 202 | #define NR_wait4 114 |
| 203 | #define NR_swapoff 115 |
| 204 | #define NR_sysinfo 116 |
| 205 | #define NR_ipc 117 |
| 206 | #define NR_fsync 118 |
| 207 | #define NR_sigreturn 119 |
| 208 | #define NR_clone 120 |
| 209 | #define NR_setdomainname 121 |
| 210 | #define NR_uname 122 |
| 211 | #define NR_modify_ldt 123 |
| 212 | #define NR_adjtimex 124 |
| 213 | #define NR_mprotect 125 |
| 214 | #define NR_sigprocmask 126 |
| 215 | #define NR_create_module 127 |
| 216 | #define NR_init_module 128 |
| 217 | #define NR_delete_module 129 |
| 218 | #define NR_get_kernel_syms 130 |
| 219 | #define NR_quotactl 131 |
| 220 | #define NR_getpgid 132 |
| 221 | #define NR_fchdir 133 |
| 222 | #define NR_bdflush 134 |
| 223 | #define NR_sysfs 135 |
| 224 | #define NR_personality 136 |
| 225 | #define NR_afs_syscall 137 /* Syscall for Andrew File System */ |
| 226 | #define NR_setfsuid 138 |
| 227 | #define NR_setfsgid 139 |
| 228 | #define NR__llseek 140 |
| 229 | #define NR_getdents 141 |
| 230 | #define NR__newselect 142 |
| 231 | #define NR_flock 143 |
| 232 | #define NR_msync 144 |
| 233 | #define NR_readv 145 |
| 234 | #define NR_writev 146 |
| 235 | #define NR_getsid 147 |
| 236 | #define NR_fdatasync 148 |
| 237 | #define NR__sysctl 149 |
| 238 | #define NR_mlock 150 |
| 239 | #define NR_munlock 151 |
| 240 | #define NR_mlockall 152 |
| 241 | #define NR_munlockall 153 |
| 242 | #define NR_sched_setparam 154 |
| 243 | #define NR_sched_getparam 155 |
| 244 | #define NR_sched_setscheduler 156 |
| 245 | #define NR_sched_getscheduler 157 |
| 246 | #define NR_sched_yield 158 |
| 247 | #define NR_sched_get_priority_max 159 |
| 248 | #define NR_sched_get_priority_min 160 |
| 249 | #define NR_sched_rr_get_interval 161 |
| 250 | #define NR_nanosleep 162 |
| 251 | #define NR_mremap 163 |
| 252 | #define NR_setresuid 164 |
| 253 | #define NR_getresuid 165 |
| 254 | #define NR_vm86 166 |
| 255 | #define NR_query_module 167 |
| 256 | #define NR_poll 168 |
| 257 | #define NR_nfsservctl 169 |
| 258 | #define NR_setresgid 170 |
| 259 | #define NR_getresgid 171 |
| 260 | #define NR_prctl 172 |
| 261 | #define NR_rt_sigreturn 173 |
| 262 | #define NR_rt_sigaction 174 |
| 263 | #define NR_rt_sigprocmask 175 |
| 264 | #define NR_rt_sigpending 176 |
| 265 | #define NR_rt_sigtimedwait 177 |
| 266 | #define NR_rt_sigqueueinfo 178 |
| 267 | #define NR_rt_sigsuspend 179 |
| 268 | #define NR_pread 180 |
| 269 | #define NR_pwrite 181 |
| 270 | #define NR_chown 182 |
| 271 | #define NR_getcwd 183 |
| 272 | #define NR_capget 184 |
| 273 | #define NR_capset 185 |
| 274 | #define NR_sigaltstack 186 |
| 275 | #define NR_sendfile 187 |
| 276 | #define NR_getpmsg 188 /* some people actually want streams */ |
| 277 | #define NR_putpmsg 189 /* some people actually want streams */ |
| 278 | #define NR_vfork 190 |
| 279 | |
| 280 | /* Standard file descriptors */ |
| 281 | #define STDIN_FILENO 0 /* Standard input */ |
| 282 | #define STDOUT_FILENO 1 /* Standard output */ |
| 283 | #define STDERR_FILENO 2 /* Standard error output */ |
| 284 | |
| 285 | typedef long ssize_t; |
| 286 | typedef unsigned long size_t; |
| 287 | |
| 288 | static ssize_t write(int fd, const void *buf, size_t count) |
| 289 | { |
| 290 | struct syscall_result res; |
| 291 | res = syscall3(NR_write, fd, (unsigned long)buf, count); |
| 292 | return res.val; |
| 293 | } |
| 294 | |
| 295 | static void _exit(int status) |
| 296 | { |
| 297 | struct syscall_result res; |
| 298 | res = syscall1(NR_exit, status); |
| 299 | } |