MentOS  0.8.0
The Mentoring Operating System
syscall_types.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #define __NR_exit 1
9 #define __NR_fork 2
10 #define __NR_read 3
11 #define __NR_write 4
12 #define __NR_open 5
13 #define __NR_close 6
14 #define __NR_waitpid 7
15 #define __NR_creat 8
16 #define __NR_link 9
17 #define __NR_unlink 10
18 #define __NR_execve 11
19 #define __NR_chdir 12
20 #define __NR_time 13
21 #define __NR_mknod 14
22 #define __NR_chmod 15
23 #define __NR_lchown 16
24 #define __NR_stat 18
25 #define __NR_lseek 19
26 #define __NR_getpid 20
27 #define __NR_mount 21
28 #define __NR_oldumount 22
29 #define __NR_setuid 23
30 #define __NR_getuid 24
31 #define __NR_stime 25
32 #define __NR_ptrace 26
33 #define __NR_alarm 27
34 #define __NR_fstat 28
35 #define __NR_pause 29
36 #define __NR_utime 30
37 #define __NR_access 33
38 #define __NR_nice 34
39 #define __NR_sync 36
40 #define __NR_kill 37
41 #define __NR_rename 38
42 #define __NR_mkdir 39
43 #define __NR_rmdir 40
44 #define __NR_dup 41
45 #define __NR_pipe 42
46 #define __NR_times 43
47 #define __NR_brk 45
48 #define __NR_setgid 46
49 #define __NR_getgid 47
50 #define __NR_signal 48
51 #define __NR_geteuid 49
52 #define __NR_getegid 50
53 #define __NR_acct 51
54 #define __NR_umount 52
55 #define __NR_ioctl 54
56 #define __NR_fcntl 55
57 #define __NR_setpgid 57
58 #define __NR_olduname 59
59 #define __NR_umask 60
60 #define __NR_chroot 61
61 #define __NR_ustat 62
62 #define __NR_dup2 63
63 #define __NR_getppid 64
64 #define __NR_getpgrp 65
65 #define __NR_setsid 66
66 #define __NR_sigaction 67
67 #define __NR_sgetmask 68
68 #define __NR_ssetmask 69
69 #define __NR_setreuid 70
70 #define __NR_setregid 71
71 #define __NR_sigsuspend 72
72 #define __NR_sigpending 73
73 #define __NR_sethostname 74
74 #define __NR_setrlimit 75
75 #define __NR_getrlimit 76
76 #define __NR_getrusage 77
77 #define __NR_gettimeofday 78
78 #define __NR_settimeofday 79
79 #define __NR_getgroups 80
80 #define __NR_setgroups 81
81 #define __NR_symlink 83
82 #define __NR_lstat 84
83 #define __NR_readlink 85
84 #define __NR_uselib 86
85 #define __NR_swapon 87
86 #define __NR_reboot 88
87 #define __NR_readdir 89
88 #define __NR_mmap 90
89 #define __NR_munmap 91
90 #define __NR_truncate 92
91 #define __NR_ftruncate 93
92 #define __NR_fchmod 94
93 #define __NR_fchown 95
94 #define __NR_getpriority 96
95 #define __NR_setpriority 97
96 #define __NR_statfs 99
97 #define __NR_fstatfs 100
98 #define __NR_ioperm 101
99 #define __NR_socketcall 102
100 #define __NR_syslog 103
101 #define __NR_setitimer 104
102 #define __NR_getitimer 105
103 #define __NR_newstat 106
104 #define __NR_newlstat 107
105 #define __NR_newfstat 108
106 #define __NR_uname 109
107 #define __NR_iopl 110
108 #define __NR_vhangup 111
109 #define __NR_idle 112
110 #define __NR_vm86old 113
111 #define __NR_wait4 114
112 #define __NR_swapoff 115
113 #define __NR_sysinfo 116
114 #define __NR_ipc 117
115 #define __NR_fsync 118
116 #define __NR_sigreturn 119
117 #define __NR_clone 120
118 #define __NR_setdomainname 121
119 #define __NR_newuname 122
120 #define __NR_modify_ldt 123
121 #define __NR_adjtimex 124
122 #define __NR_mprotect 125
123 #define __NR_sigprocmask 126
124 #define __NR_create_module 127
125 #define __NR_init_module 128
126 #define __NR_delete_module 129
127 #define __NR_get_kernel_syms 130
128 #define __NR_quotactl 131
129 #define __NR_getpgid 132
130 #define __NR_fchdir 133
131 #define __NR_bdflush 134
132 #define __NR_sysfs 135
133 #define __NR_personality 136
134 #define __NR_setfsuid 138
135 #define __NR_setfsgid 139
136 #define __NR_llseek 140
137 #define __NR_getdents 141
138 #define __NR_select 142
139 #define __NR_flock 143
140 #define __NR_msync 144
141 #define __NR_readv 145
142 #define __NR_writev 146
143 #define __NR_getsid 147
144 #define __NR_fdatasync 148
145 #define __NR_sysctl 149
146 #define __NR_mlock 150
147 #define __NR_munlock 151
148 #define __NR_mlockall 152
149 #define __NR_munlockall 153
150 #define __NR_sched_setparam 154
151 #define __NR_sched_getparam 155
152 #define __NR_sched_setscheduler 156
153 #define __NR_sched_getscheduler 157
154 #define __NR_sched_yield 158
155 #define __NR_sched_get_priority_max 159
156 #define __NR_sched_get_priority_min 160
157 #define __NR_sched_rr_get_interval 161
158 #define __NR_nanosleep 162
159 #define __NR_mremap 163
160 #define __NR_setresuid 164
161 #define __NR_getresuid 165
162 #define __NR_vm86 166
163 #define __NR_query_module 167
164 #define __NR_poll 168
165 #define __NR_nfsservctl 169
166 #define __NR_setresgid 170
167 #define __NR_getresgid 171
168 #define __NR_prctl 172
169 #define __NR_rt_sigreturn 173
170 #define __NR_rt_sigaction 174
171 #define __NR_rt_sigprocmask 175
172 #define __NR_rt_sigpending 176
173 #define __NR_rt_sigtimedwait 177
174 #define __NR_rt_sigqueueinfo 178
175 #define __NR_rt_sigsuspend 179
176 #define __NR_pread 180
177 #define __NR_pwrite 181
178 #define __NR_chown 182
179 #define __NR_getcwd 183
180 #define __NR_capget 184
181 #define __NR_capset 185
182 #define __NR_sigaltstack 186
183 #define __NR_sendfile 187
184 #define __NR_waitperiod 188
185 #define __NR_msgctl 189
186 #define __NR_msgget 190
187 #define __NR_msgrcv 191
188 #define __NR_msgsnd 192
189 #define __NR_semctl 193
190 #define __NR_semget 194
191 #define __NR_semop 195
192 #define __NR_shmat 196
193 #define __NR_shmctl 197
194 #define __NR_shmdt 198
195 #define __NR_shmget 199
196 #define SYSCALL_NUMBER 200
197 
201 #define __syscall_return(type, res) \
202  do { \
203  if ((unsigned int)(res) >= (unsigned int)(-125)) { \
204  errno = -(res); \
205  (res) = -1; \
206  } \
207  return (type)(res); \
208  } while (0)
209 
210 // Few things about what follows:
211 //
212 // 1. The symbol "=", is a a constraint modifier, and it means that the operand
213 // is write-only, meaning that the previous value is discarded and replaced
214 // by output data.
215 //
216 // 2. Using "0" here specifies that the input is read from a variable which also
217 // serves as an output, the 0-th output variable in this case.
218 //
219 //
220 
222 #define __inline_syscall0(res, name) \
223  __asm__ __volatile__("int $0x80" \
224  : "=a"(res) \
225  : "0"(__NR_##name))
226 
228 #define __inline_syscall1(res, name, arg1) \
229  __asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
230  : "=a"(res) \
231  : "0"(__NR_##name), "ri"(arg1) \
232  : "memory");
233 
235 #define __inline_syscall2(res, name, arg1, arg2) \
236  __asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
237  : "=a"(res) \
238  : "0"(__NR_##name), "ri"(arg1), "c"(arg2) \
239  : "memory");
240 
242 #define __inline_syscall3(res, name, arg1, arg2, arg3) \
243  __asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
244  : "=a"(res) \
245  : "0"(__NR_##name), "ri"(arg1), "c"(arg2), "d"(arg3) \
246  : "memory");
247 
249 #define __inline_syscall4(res, name, arg1, arg2, arg3, arg4) \
250  __asm__ __volatile__("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \
251  : "=a"(res) \
252  : "0"(__NR_##name), "ri"(arg1), "c"(arg2), "d"(arg3), "S"(arg4) \
253  : "memory");
254 
256 #define __inline_syscall5(res, name, arg1, arg2, arg3, arg4, arg5) \
257  __asm__ __volatile__("push %%ebx; movl %2,%%ebx; movl %1,%%eax; " \
258  "int $0x80; pop %%ebx" \
259  : "=a"(res) \
260  : "i"(__NR_##name), "ri"(arg1), "c"(arg2), "d"(arg3), "S"(arg4), "D"(arg5) \
261  : "memory");
262 
264 #define _syscall0(type, name) \
265  type name(void) \
266  { \
267  long __res; \
268  __inline_syscall0(__res, name); \
269  __syscall_return(type, __res); \
270  }
271 
273 #define _syscall1(type, name, type1, arg1) \
274  type name(type1 arg1) \
275  { \
276  long __res; \
277  __inline_syscall1(__res, name, arg1); \
278  __syscall_return(type, __res); \
279  }
280 
282 #define _syscall2(type, name, type1, arg1, type2, arg2) \
283  type name(type1 arg1, type2 arg2) \
284  { \
285  long __res; \
286  __inline_syscall2(__res, name, arg1, arg2); \
287  __syscall_return(type, __res); \
288  }
289 
291 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
292  type name(type1 arg1, type2 arg2, type3 arg3) \
293  { \
294  long __res; \
295  __inline_syscall3(__res, name, arg1, arg2, arg3); \
296  __syscall_return(type, __res); \
297  }
298 
300 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \
301  type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
302  { \
303  long __res; \
304  __inline_syscall4(__res, name, arg1, arg2, arg3, arg4); \
305  __syscall_return(type, __res); \
306  }
307 
309 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \
310  type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
311  { \
312  long __res; \
313  __inline_syscall5(__res, name, arg1, arg2, arg3, arg4, arg5); \
314  __syscall_return(type, __res); \
315  }
316 
318 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6) \
319  type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \
320  { \
321  long __res; \
322  unsigned args[6] = { 0 }; \
323  args[0] = (unsigned)arg1; \
324  args[1] = (unsigned)arg2; \
325  args[2] = (unsigned)arg3; \
326  args[3] = (unsigned)arg4; \
327  args[4] = (unsigned)arg5; \
328  args[5] = (unsigned)arg6; \
329  __inline_syscall1(__res, name, args); \
330  __syscall_return(type, __res); \
331  }