The Pedigree Project  0.1
translate.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _POSIX_SYSCALLS_TRANSLATE_H
21 #define _POSIX_SYSCALLS_TRANSLATE_H
22 
23 // from musl
24 #include <bits/syscall.h>
25 
26 #include <posixSyscallNumbers.h>
27 
28 inline long posix_translate_syscall(long which)
29 {
30  long pedigree_translation = -1;
31 
32  switch (which)
33  {
34  case SYS_read:
35  pedigree_translation = POSIX_READ;
36  break;
37  case SYS_write:
38  pedigree_translation = POSIX_WRITE;
39  break;
40  case SYS_open:
41  pedigree_translation = POSIX_OPEN;
42  break;
43  case SYS_close:
44  pedigree_translation = POSIX_CLOSE;
45  break;
46  case SYS_stat:
47  pedigree_translation = POSIX_STAT;
48  break;
49  case SYS_fstat:
50  pedigree_translation = POSIX_FSTAT;
51  break;
52  case SYS_lstat:
53  pedigree_translation = POSIX_LSTAT;
54  break;
55  case SYS_poll:
56  pedigree_translation = POSIX_POLL;
57  break;
58  case SYS_lseek:
59  pedigree_translation = POSIX_LSEEK;
60  break;
61  case SYS_mmap:
62  pedigree_translation = POSIX_MMAP;
63  break;
64  case SYS_mprotect:
65  pedigree_translation = POSIX_MPROTECT;
66  break;
67  case SYS_munmap:
68  pedigree_translation = POSIX_MUNMAP;
69  break;
70  case SYS_brk:
71  pedigree_translation = POSIX_BRK;
72  break;
73  case SYS_rt_sigaction:
74  pedigree_translation = POSIX_SIGACTION;
75  break;
76  case SYS_rt_sigprocmask:
77  pedigree_translation = POSIX_SIGPROCMASK;
78  break;
79  case SYS_rt_sigreturn:
80  pedigree_translation = PEDIGREE_SIGRET;
81  break;
82  case SYS_ioctl:
83  pedigree_translation = POSIX_IOCTL;
84  break;
85  // ...
86  case SYS_readv:
87  pedigree_translation = POSIX_READV;
88  break;
89  case SYS_writev:
90  pedigree_translation = POSIX_WRITEV;
91  break;
92  case SYS_access:
93  pedigree_translation = POSIX_ACCESS;
94  break;
95  case SYS_pipe:
96  pedigree_translation = POSIX_PIPE;
97  break;
98  case SYS_select:
99  pedigree_translation = POSIX_SELECT;
100  break;
101  case SYS_sched_yield:
102  pedigree_translation = POSIX_SCHED_YIELD;
103  break;
104  // ...
105  case SYS_msync:
106  pedigree_translation = POSIX_MSYNC;
107  break;
108  // ...
109  case SYS_dup:
110  pedigree_translation = POSIX_DUP;
111  break;
112  case SYS_dup2:
113  pedigree_translation = POSIX_DUP2;
114  break;
115  case SYS_pause:
116  pedigree_translation = POSIX_PAUSE;
117  break;
118  // ...
119  case SYS_nanosleep:
120  pedigree_translation = POSIX_NANOSLEEP;
121  break;
122  case SYS_getitimer:
123  pedigree_translation = POSIX_GETITIMER;
124  break;
125  case SYS_alarm:
126  pedigree_translation = POSIX_ALARM;
127  break;
128  case SYS_setitimer:
129  pedigree_translation = POSIX_SETITIMER;
130  break;
131  case SYS_getpid:
132  pedigree_translation = POSIX_GETPID;
133  break;
134  // ...
135  case SYS_socket:
136  pedigree_translation = POSIX_SOCKET;
137  break;
138  case SYS_connect:
139  pedigree_translation = POSIX_CONNECT;
140  break;
141  case SYS_accept:
142  pedigree_translation = POSIX_ACCEPT;
143  break;
144  case SYS_sendto:
145  pedigree_translation = POSIX_SENDTO;
146  break;
147  case SYS_recvfrom:
148  pedigree_translation = POSIX_RECVFROM;
149  break;
150  case SYS_sendmsg:
151  pedigree_translation = POSIX_SENDMSG;
152  break;
153  case SYS_recvmsg:
154  pedigree_translation = POSIX_RECVMSG;
155  break;
156  case SYS_shutdown:
157  pedigree_translation = POSIX_SHUTDOWN;
158  break;
159  case SYS_bind:
160  pedigree_translation = POSIX_BIND;
161  break;
162  case SYS_listen:
163  pedigree_translation = POSIX_LISTEN;
164  break;
165  case SYS_getsockname:
166  pedigree_translation = POSIX_GETSOCKNAME;
167  break;
168  case SYS_getpeername:
169  pedigree_translation = POSIX_GETPEERNAME;
170  break;
171  case SYS_socketpair:
172  pedigree_translation = POSIX_SOCKETPAIR;
173  break;
174  case SYS_setsockopt:
175  pedigree_translation = POSIX_SETSOCKOPT;
176  break;
177  case SYS_getsockopt:
178  pedigree_translation = POSIX_GETSOCKOPT;
179  break;
180  case SYS_clone:
181  pedigree_translation = POSIX_CLONE;
182  break;
183  case SYS_fork:
184  pedigree_translation = POSIX_FORK;
185  break;
186  // ...
187  case SYS_execve:
188  pedigree_translation = POSIX_EXECVE;
189  break;
190  case SYS_exit:
191  pedigree_translation = POSIX_EXIT;
192  break;
193  case SYS_wait4:
194  pedigree_translation = POSIX_WAITPID;
195  break;
196  case SYS_kill:
197  pedigree_translation = POSIX_KILL;
198  break;
199  case SYS_uname:
200  pedigree_translation = POSIX_UNAME;
201  break;
202  // ...
203  case SYS_fcntl:
204  pedigree_translation = POSIX_FCNTL;
205  break;
206  case SYS_flock:
207  pedigree_translation = POSIX_FLOCK;
208  break;
209  case SYS_fsync:
210  pedigree_translation = POSIX_FSYNC;
211  break;
212  // ...
213  case SYS_ftruncate:
214  pedigree_translation = POSIX_FTRUNCATE;
215  break;
216  case SYS_getdents:
217  pedigree_translation = POSIX_GETDENTS;
218  break;
219  case SYS_getcwd:
220  pedigree_translation = POSIX_GETCWD;
221  break;
222  case SYS_chdir:
223  pedigree_translation = POSIX_CHDIR;
224  break;
225  case SYS_fchdir:
226  pedigree_translation = POSIX_FCHDIR;
227  break;
228  case SYS_rename:
229  pedigree_translation = POSIX_RENAME;
230  break;
231  case SYS_mkdir:
232  pedigree_translation = POSIX_MKDIR;
233  break;
234  case SYS_rmdir:
235  pedigree_translation = POSIX_RMDIR;
236  break;
237  case SYS_creat:
238  pedigree_translation = POSIX_CREAT;
239  break;
240  case SYS_link:
241  pedigree_translation = POSIX_LINK;
242  break;
243  case SYS_unlink:
244  pedigree_translation = POSIX_UNLINK;
245  break;
246  case SYS_symlink:
247  pedigree_translation = POSIX_SYMLINK;
248  break;
249  case SYS_readlink:
250  pedigree_translation = POSIX_READLINK;
251  break;
252  case SYS_chmod:
253  pedigree_translation = POSIX_CHMOD;
254  break;
255  case SYS_fchmod:
256  pedigree_translation = POSIX_FCHMOD;
257  break;
258  case SYS_chown:
259  pedigree_translation = POSIX_CHOWN;
260  break;
261  case SYS_fchown:
262  pedigree_translation = POSIX_FCHOWN;
263  break;
264  // ...
265  case SYS_umask:
266  pedigree_translation = POSIX_UMASK;
267  break;
268  case SYS_gettimeofday:
269  pedigree_translation = POSIX_GETTIMEOFDAY;
270  break;
271  case SYS_getrlimit:
272  pedigree_translation = POSIX_GETRLIMIT;
273  break;
274  // ...
275  case SYS_times:
276  pedigree_translation = POSIX_TIMES;
277  break;
278  // ...
279  case SYS_getuid:
280  pedigree_translation = POSIX_GETUID;
281  break;
282  case SYS_syslog:
283  pedigree_translation = POSIX_L_SYSLOG;
284  break;
285  case SYS_getgid:
286  pedigree_translation = POSIX_GETGID;
287  break;
288  case SYS_setuid:
289  pedigree_translation = POSIX_SETUID;
290  break;
291  case SYS_setgid:
292  pedigree_translation = POSIX_SETGID;
293  break;
294  case SYS_geteuid:
295  pedigree_translation = POSIX_GETEUID;
296  break;
297  case SYS_getegid:
298  pedigree_translation = POSIX_GETEGID;
299  break;
300  case SYS_setpgid:
301  pedigree_translation = POSIX_SETPGID;
302  break;
303  case SYS_getppid:
304  pedigree_translation = POSIX_GETPPID;
305  break;
306  case SYS_getpgrp:
307  pedigree_translation = POSIX_GETPGRP;
308  break;
309  case SYS_setsid:
310  pedigree_translation = POSIX_SETSID;
311  break;
312  case SYS_setreuid:
313  pedigree_translation = POSIX_SETREUID;
314  break;
315  case SYS_setregid:
316  pedigree_translation = POSIX_SETREGID;
317  break;
318  case SYS_getgroups:
319  pedigree_translation = POSIX_GETGROUPS;
320  break;
321  case SYS_setgroups:
322  pedigree_translation = POSIX_SETGROUPS;
323  break;
324  case SYS_setresuid:
325  pedigree_translation = POSIX_SETRESUID;
326  break;
327  case SYS_getresuid:
328  pedigree_translation = POSIX_GETRESUID;
329  break;
330  case SYS_setresgid:
331  pedigree_translation = POSIX_SETRESGID;
332  break;
333  case SYS_getresgid:
334  pedigree_translation = POSIX_GETRESGID;
335  break;
336  case SYS_getpgid:
337  pedigree_translation = POSIX_GETPGID;
338  break;
339  // ...
340  case SYS_capget:
341  pedigree_translation = POSIX_CAPGET;
342  break;
343  case SYS_capset:
344  pedigree_translation = POSIX_CAPSET;
345  break;
346  // ...
347  case SYS_utime:
348  pedigree_translation = POSIX_UTIME;
349  break;
350  case SYS_mknod:
351  pedigree_translation = POSIX_MKNOD;
352  break;
353  // ...
354  case SYS_statfs:
355  pedigree_translation = POSIX_STATFS;
356  break;
357  case SYS_fstatfs:
358  pedigree_translation = POSIX_FSTATFS;
359  break;
360  // ...
361  case SYS_getpriority:
362  pedigree_translation = POSIX_GETPRIORITY;
363  break;
364  case SYS_setpriority:
365  pedigree_translation = POSIX_SETPRIORITY;
366  break;
367  // ...
368  case SYS_prctl:
369  pedigree_translation = POSIX_PRCTL;
370  break;
371  case SYS_arch_prctl:
372  pedigree_translation = POSIX_ARCH_PRCTL;
373  break;
374  // ...
375  case SYS_setrlimit:
376  pedigree_translation = POSIX_SETRLIMIT;
377  break;
378  case SYS_chroot:
379  pedigree_translation = POSIX_CHROOT;
380  break;
381  // ...
382  case SYS_settimeofday:
383  pedigree_translation = POSIX_SETTIMEOFDAY;
384  break;
385  case SYS_mount:
386  pedigree_translation = POSIX_MOUNT;
387  break;
388  // ...
389  case SYS_sethostname:
390  pedigree_translation = POSIX_SETHOSTNAME;
391  break;
392  // ...
393  case SYS_iopl:
394  pedigree_translation = POSIX_IOPL;
395  break;
396  case SYS_ioperm:
397  pedigree_translation = POSIX_IOPERM;
398  break;
399  // ...
400  case SYS_gettid:
401  pedigree_translation = POSIX_GETTID;
402  break;
403  // ...
404  case SYS_getxattr:
405  pedigree_translation = POSIX_GETXATTR;
406  break;
407  case SYS_lgetxattr:
408  pedigree_translation = POSIX_LGETXATTR;
409  break;
410  case SYS_fgetxattr:
411  pedigree_translation = POSIX_FGETXATTR;
412  break;
413  // ...
414  case SYS_time:
415  pedigree_translation = POSIX_TIME;
416  break;
417  case SYS_futex:
418  pedigree_translation = POSIX_FUTEX;
419  break;
420  // ...
421  case SYS_set_thread_area:
422  pedigree_translation = POSIX_SET_TLS_AREA;
423  break;
424  // ...
425  case SYS_getdents64:
426  pedigree_translation = POSIX_GETDENTS64;
427  break;
429  case SYS_set_tid_address:
430  return 0;
431  // ...
432  case SYS_clock_gettime:
433  pedigree_translation = POSIX_CLOCK_GETTIME;
434  break;
435  // ...
436  case SYS_exit_group:
437  pedigree_translation = POSIX_EXIT_GROUP;
438  break;
439  // ...
440  case SYS_utimes:
441  pedigree_translation = POSIX_UTIMES;
442  break;
443  // ...
444  case SYS_openat:
445  pedigree_translation = POSIX_OPENAT;
446  break;
447  case SYS_mkdirat:
448  pedigree_translation = POSIX_MKDIRAT;
449  break;
450  // ...
451  case SYS_fchownat:
452  pedigree_translation = POSIX_FCHOWNAT;
453  break;
454  case SYS_futimesat:
455  pedigree_translation = POSIX_FUTIMESAT;
456  break;
457  case SYS_newfstatat:
458  pedigree_translation = POSIX_FSTATAT;
459  break;
460  case SYS_unlinkat:
461  pedigree_translation = POSIX_UNLINKAT;
462  break;
463  case SYS_renameat:
464  pedigree_translation = POSIX_RENAMEAT;
465  break;
466  case SYS_linkat:
467  pedigree_translation = POSIX_LINKAT;
468  break;
469  case SYS_symlinkat:
470  pedigree_translation = POSIX_SYMLINKAT;
471  break;
472  case SYS_readlinkat:
473  pedigree_translation = POSIX_READLINKAT;
474  break;
475  case SYS_fchmodat:
476  pedigree_translation = POSIX_FCHMODAT;
477  break;
478  case SYS_faccessat:
479  pedigree_translation = POSIX_FACCESSAT;
480  break;
481  // ...
482  case SYS_set_robust_list:
483  pedigree_translation = POSIX_SET_ROBUST_LIST;
484  break;
485  case SYS_get_robust_list:
486  pedigree_translation = POSIX_GET_ROBUST_LIST;
487  break;
488 
489  // Pedigree pass-through syscalls.
490  case 0x8000:
491  pedigree_translation = POSIX_TTYNAME;
492  }
493 
494  return pedigree_translation;
495 }
496 
497 #endif // _POSIX_SYSCALLS_TRANSLATE_H