The Pedigree Project  0.1
PosixSyscallManager.cc
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 #include "pedigree/kernel/Log.h"
21 #include "pedigree/kernel/process/Process.h"
22 #include "pedigree/kernel/process/Scheduler.h"
23 #include "pedigree/kernel/processor/PageFaultHandler.h"
24 #include "pedigree/kernel/processor/Processor.h"
25 #include "pedigree/kernel/processor/SyscallManager.h"
26 #include "pedigree/kernel/processor/state.h"
27 #include "pedigree/kernel/syscallError.h"
28 #include "pedigree/kernel/time/Time.h"
29 
30 #include "PosixSyscallManager.h"
31 #include "console-syscalls.h"
32 #include "file-syscalls.h"
33 #include "logging.h"
34 #include "net-syscalls.h"
35 #include "pipe-syscalls.h"
36 #include "poll-syscalls.h"
37 #include "posixSyscallNumbers.h"
38 #include "pthread-syscalls.h"
39 #include "select-syscalls.h"
40 #include "signal-syscalls.h"
41 #include "syscalls/translate.h"
42 #include "system-syscalls.h"
43 
44 #include <fcntl.h>
45 #include <time.h>
46 
47 #include "pedigree/kernel/debugger/Backtrace.h"
48 
50 {
51 }
52 
54 {
55 }
56 
57 void PosixSyscallManager::initialise()
58 {
61 }
62 
64  uintptr_t function, uintptr_t p1, uintptr_t p2, uintptr_t p3, uintptr_t p4,
65  uintptr_t p5)
66 {
67  if (function >= serviceEnd)
68  {
69  ERROR(
70  "PosixSyscallManager: invalid function called: "
71  << Dec << static_cast<int>(function));
72  return 0;
73  }
74 
75  uintptr_t ret =
76  SyscallManager::instance().syscall(posix, function, p1, p2, p3, p4, p5);
77  return ret;
78 }
79 
80 uintptr_t PosixSyscallManager::syscall(SyscallState &state)
81 {
82  uint64_t syscallNumber = state.getSyscallNumber();
83 
84  uintptr_t base = 0;
85  if (state.getSyscallService() == linuxCompat)
86  {
87  // Switch ABI now that we've seen a Linux syscall come in.
88  Process *pProcess =
89  Processor::information().getCurrentThread()->getParent();
90  PosixSubsystem *pSubsystem =
91  reinterpret_cast<PosixSubsystem *>(pProcess->getSubsystem());
92  pSubsystem->setAbi(PosixSubsystem::LinuxAbi);
93 
94  base = 6; // use Linux syscall ABI
95 
96  // Translate the syscall.
97  long which = posix_translate_syscall(syscallNumber);
98  if (which < 0)
99  {
100  size_t key = (pProcess->getId() << 32ULL) | syscallNumber;
101  if (!m_SeenUnknownSyscalls.lookup(key))
102  {
103  ERROR(
104  "POSIX: unknown Linux syscall "
105  << syscallNumber << " by pid=" << pProcess->getId()
106  << ", translation failed!");
107  m_SeenUnknownSyscalls.insert(key, true);
108  }
109  SYSCALL_ERROR(Unimplemented);
110  return -1;
111  }
112 #ifdef POSIX_VERBOSE_SYSCALLS
113  else
114  {
115  NOTICE(
116  "TRANSLATED syscall: Linux #" << syscallNumber
117  << " -> Pedigree #" << which);
118  }
119 #endif
120 
121  syscallNumber = which;
122  }
123 
124  uintptr_t p1 = state.getSyscallParameter(base + 0);
125  uintptr_t p2 = state.getSyscallParameter(base + 1);
126  uintptr_t p3 = state.getSyscallParameter(base + 2);
127  uintptr_t p4 = state.getSyscallParameter(base + 3);
128  uintptr_t p5 = state.getSyscallParameter(base + 4);
129  uintptr_t p6 = state.getSyscallParameter(base + 5);
130 
131 #ifdef POSIX_VERBOSE_SYSCALLS
132  NOTICE(
133  "[" << Processor::information().getCurrentThread()->getParent()->getId()
134  << "] : " << Dec << syscallNumber << Hex);
135 #endif
136 
137  // We're interruptible.
139 
140  switch (syscallNumber)
141  {
142  // POSIX system calls
143  case POSIX_OPEN:
144  return posix_open(reinterpret_cast<const char *>(p1), p2, p3);
145  case POSIX_WRITE:
146  return posix_write(p1, reinterpret_cast<char *>(p2), p3);
147  case POSIX_READ:
148  return posix_read(p1, reinterpret_cast<char *>(p2), p3);
149  case POSIX_CLOSE:
150  return posix_close(p1);
151  case POSIX_SBRK:
152  return posix_sbrk(p1);
153  case POSIX_FORK:
154  return posix_fork(state);
155  case POSIX_EXECVE:
156  return posix_execve(
157  reinterpret_cast<const char *>(p1),
158  reinterpret_cast<const char **>(p2),
159  reinterpret_cast<const char **>(p3), state);
160  case POSIX_WAITPID:
161  return posix_waitpid(p1, reinterpret_cast<int *>(p2), p3);
162  case POSIX_EXIT:
163  // If not Linux mode, we exit the entire process. If Linux, just
164  // the current thread (as glibc uses exit_group for "all process").
165  posix_exit(p1, state.getSyscallService() != linuxCompat);
166  case POSIX_EXIT_GROUP:
167  posix_exit(p1, true);
168  case POSIX_TCGETATTR:
169  return posix_tcgetattr(p1, reinterpret_cast<struct termios *>(p2));
170  case POSIX_TCSETATTR:
171  return posix_tcsetattr(
172  p1, p2, reinterpret_cast<struct termios *>(p3));
173  case POSIX_IOCTL:
174  return posix_ioctl(p1, p2, reinterpret_cast<void *>(p3));
175  case POSIX_STAT:
176  return posix_stat(
177  reinterpret_cast<const char *>(p1),
178  reinterpret_cast<struct stat *>(p2));
179  case POSIX_FSTAT:
180  return posix_fstat(p1, reinterpret_cast<struct stat *>(p2));
181  case POSIX_GETPID:
182  return posix_getpid();
183  case POSIX_CHDIR:
184  return posix_chdir(reinterpret_cast<const char *>(p1));
185  case POSIX_SELECT:
186  return posix_select(
187  static_cast<int>(p1), reinterpret_cast<fd_set *>(p2),
188  reinterpret_cast<fd_set *>(p3), reinterpret_cast<fd_set *>(p4),
189  reinterpret_cast<struct timeval *>(p5));
190  case POSIX_LSEEK:
191  return posix_lseek(
192  static_cast<int>(p1), static_cast<off_t>(p2),
193  static_cast<int>(p3));
194  case POSIX_SOCKET:
195  return posix_socket(
196  static_cast<int>(p1), static_cast<int>(p2),
197  static_cast<int>(p3));
198  case POSIX_CONNECT:
199  return posix_connect(
200  static_cast<int>(p1), reinterpret_cast<sockaddr *>(p2), p3);
201  case POSIX_SEND:
202  return posix_send(
203  static_cast<int>(p1), reinterpret_cast<void *>(p2), p3,
204  static_cast<int>(p4));
205  case POSIX_RECV:
206  return posix_recv(
207  static_cast<int>(p1), reinterpret_cast<void *>(p2), p3,
208  static_cast<int>(p4));
209  case POSIX_BIND:
210  return posix_bind(
211  static_cast<int>(p1), reinterpret_cast<sockaddr *>(p2), p3);
212  case POSIX_LISTEN:
213  return posix_listen(static_cast<int>(p1), static_cast<int>(p2));
214  case POSIX_ACCEPT:
215  return posix_accept(
216  static_cast<int>(p1), reinterpret_cast<sockaddr *>(p2),
217  reinterpret_cast<socklen_t *>(p3));
218  case POSIX_RECVFROM:
219  return posix_recvfrom(
220  static_cast<int>(p1), reinterpret_cast<void *>(p2), p3,
221  static_cast<int>(p4), reinterpret_cast<struct sockaddr *>(p5),
222  reinterpret_cast<socklen_t *>(p6));
223  case POSIX_SENDTO:
224  return posix_sendto(
225  static_cast<int>(p1), reinterpret_cast<void *>(p2), p3,
226  static_cast<int>(p4), reinterpret_cast<struct sockaddr *>(p5),
227  static_cast<socklen_t>(p6));
228  case POSIX_GETTIMEOFDAY:
229  return posix_gettimeofday(
230  reinterpret_cast<struct timeval *>(p1),
231  reinterpret_cast<struct timezone *>(p2));
232  case POSIX_DUP:
233  return posix_dup(static_cast<int>(p1));
234  case POSIX_DUP2:
235  return posix_dup2(static_cast<int>(p1), static_cast<int>(p2));
236  case POSIX_LSTAT:
237  return posix_lstat(
238  reinterpret_cast<char *>(p1),
239  reinterpret_cast<struct stat *>(p2));
240  case POSIX_UNLINK:
241  return posix_unlink(reinterpret_cast<char *>(p1));
242  case POSIX_SYMLINK:
243  return posix_symlink(
244  reinterpret_cast<char *>(p1), reinterpret_cast<char *>(p2));
245  case POSIX_FCNTL:
246  return posix_fcntl(
247  static_cast<int>(p1), static_cast<int>(p2),
248  reinterpret_cast<void *>(p3));
249  case POSIX_PIPE:
250  return posix_pipe(reinterpret_cast<int *>(p1));
251  case POSIX_MKDIR:
252  return posix_mkdir(
253  reinterpret_cast<const char *>(p1), static_cast<int>(p2));
254  case POSIX_RMDIR:
255  return posix_rmdir(reinterpret_cast<const char *>(p1));
256  case POSIX_GETPWENT:
257  return posix_getpwent(
258  reinterpret_cast<passwd *>(p1), static_cast<int>(p2),
259  reinterpret_cast<char *>(p3));
260  case POSIX_GETPWNAM:
261  return posix_getpwnam(
262  reinterpret_cast<passwd *>(p1),
263  reinterpret_cast<const char *>(p2),
264  reinterpret_cast<char *>(p3));
265  case POSIX_GETUID:
266  return posix_getuid();
267  case POSIX_GETGID:
268  return posix_getgid();
269  case POSIX_SIGACTION:
270  return posix_sigaction(
271  static_cast<int>(p1),
272  reinterpret_cast<const struct sigaction *>(p2),
273  reinterpret_cast<struct sigaction *>(p3));
274  case POSIX_SIGNAL:
275  return posix_signal(
276  static_cast<int>(p1), reinterpret_cast<void *>(p2));
277  case POSIX_RAISE:
278  return posix_raise(static_cast<int>(p1), state);
279  case POSIX_KILL:
280  return posix_kill(static_cast<int>(p1), static_cast<int>(p2));
281  case POSIX_SIGPROCMASK:
282  return posix_sigprocmask(
283  static_cast<int>(p1), reinterpret_cast<const uint32_t *>(p2),
284  reinterpret_cast<uint32_t *>(p3));
285  case POSIX_ALARM:
286  return posix_alarm(p1);
287  case POSIX_SLEEP:
288  return posix_sleep(p1);
289  case POSIX_POLL:
290  return posix_poll(
291  reinterpret_cast<pollfd *>(p1), static_cast<unsigned int>(p2),
292  static_cast<int>(p3));
293  case POSIX_RENAME:
294  return posix_rename(
295  reinterpret_cast<const char *>(p1),
296  reinterpret_cast<const char *>(p2));
297  case POSIX_GETCWD:
298  return posix_getcwd(reinterpret_cast<char *>(p1), p2);
299  case POSIX_READLINK:
300  return posix_readlink(
301  reinterpret_cast<const char *>(p1),
302  reinterpret_cast<char *>(p2), static_cast<unsigned int>(p3));
303  case POSIX_LINK:
304  return posix_link(
305  reinterpret_cast<char *>(p1), reinterpret_cast<char *>(p2));
306  case POSIX_ISATTY:
307  return posix_isatty(static_cast<int>(p1));
308  case POSIX_MMAP:
309  return reinterpret_cast<uintptr_t>(posix_mmap(
310  reinterpret_cast<void *>(p1), p2, static_cast<int>(p3),
311  static_cast<int>(p4), static_cast<int>(p5),
312  static_cast<off_t>(p6)));
313  case POSIX_MUNMAP:
314  return posix_munmap(reinterpret_cast<void *>(p1), p2);
315  case POSIX_SHUTDOWN:
316  return posix_shutdown(static_cast<int>(p1), static_cast<int>(p2));
317  case POSIX_ACCESS:
318  return posix_access(
319  reinterpret_cast<const char *>(p1), static_cast<int>(p2));
320  case POSIX_SETSID:
321  return posix_setsid();
322  case POSIX_SETPGID:
323  return posix_setpgid(static_cast<int>(p1), static_cast<int>(p2));
324  case POSIX_GETPGID:
325  return posix_getpgid(static_cast<int>(p1));
326  case POSIX_GETPGRP:
327  return posix_getpgrp();
328  case POSIX_SIGALTSTACK:
329  return posix_sigaltstack(
330  reinterpret_cast<const stack_t *>(p1),
331  reinterpret_cast<stack_t *>(p2));
332 
333  case POSIX_SYSLOG:
334  return posix_syslog(
335  reinterpret_cast<const char *>(p1), static_cast<int>(p2));
336 
337  case POSIX_FTRUNCATE:
338  return posix_ftruncate(
339  static_cast<int>(p1), static_cast<off_t>(p2));
340 
341  // Stub warning
342  case POSIX_STUBBED:
343  // This is the solution to a bug - if the address in p1 traps
344  // (because of demand loading), it MUST trap before we get the log
345  // spinlock, else other things will want to write to it and
346  // deadlock.
347  static char buf[128];
348  StringCopyN(buf, reinterpret_cast<char *>(p1), 128);
349  WARNING("Using stubbed function '" << buf << "'");
350  return 0;
351 
352  // POSIX-specific Pedigree system calls
353  case PEDIGREE_SIGRET:
354  return pedigree_sigret();
355  case PEDIGREE_INIT_SIGRET:
356  WARNING("POSIX: The 'init sigret' system call is no longer valid.");
357  // pedigree_init_sigret();
358  return 0;
359  case POSIX_SCHED_YIELD:
361  return 0;
362 
363  case POSIX_NANOSLEEP:
364  return posix_nanosleep(
365  reinterpret_cast<struct timespec *>(p1),
366  reinterpret_cast<struct timespec *>(p2));
367  case POSIX_CLOCK_GETTIME:
368  return posix_clock_gettime(
369  p1, reinterpret_cast<struct timespec *>(p2));
370 
371  case POSIX_GETEUID:
372  return posix_geteuid();
373  case POSIX_GETEGID:
374  return posix_getegid();
375  case POSIX_SETEUID:
376  return posix_seteuid(static_cast<uid_t>(p1));
377  case POSIX_SETEGID:
378  return posix_setegid(static_cast<gid_t>(p1));
379  case POSIX_SETUID:
380  return posix_setuid(static_cast<uid_t>(p1));
381  case POSIX_SETGID:
382  return posix_setgid(static_cast<gid_t>(p1));
383 
384  case POSIX_CHOWN:
385  return posix_chown(
386  reinterpret_cast<const char *>(p1), static_cast<uid_t>(p2),
387  static_cast<gid_t>(p3));
388  case POSIX_CHMOD:
389  return posix_chmod(
390  reinterpret_cast<const char *>(p1), static_cast<mode_t>(p2));
391  case POSIX_FCHOWN:
392  return posix_fchown(
393  static_cast<int>(p1), static_cast<uid_t>(p2),
394  static_cast<gid_t>(p3));
395  case POSIX_FCHMOD:
396  return posix_fchmod(static_cast<int>(p1), static_cast<mode_t>(p2));
397  case POSIX_FCHDIR:
398  return posix_fchdir(static_cast<int>(p1));
399 
400  case POSIX_STATVFS:
401  return posix_statvfs(
402  reinterpret_cast<const char *>(p1),
403  reinterpret_cast<struct statvfs *>(p2));
404  case POSIX_FSTATVFS:
405  return posix_fstatvfs(
406  static_cast<int>(p1), reinterpret_cast<struct statvfs *>(p2));
407 
408  case PEDIGREE_UNWIND_SIGNAL:
409  pedigree_unwind_signal();
410  return 0;
411 
412  case POSIX_MSYNC:
413  return posix_msync(
414  reinterpret_cast<void *>(p1), p2, static_cast<int>(p3));
415  case POSIX_GETPEERNAME:
416  return posix_getpeername(
417  static_cast<int>(p1), reinterpret_cast<struct sockaddr *>(p2),
418  reinterpret_cast<socklen_t *>(p3));
419  case POSIX_GETSOCKNAME:
420  return posix_getsockname(
421  static_cast<int>(p1), reinterpret_cast<struct sockaddr *>(p2),
422  reinterpret_cast<socklen_t *>(p3));
423  case POSIX_FSYNC:
424  return posix_fsync(static_cast<int>(p1));
425 
426  case POSIX_PTSNAME:
427  return console_ptsname(
428  static_cast<int>(p1), reinterpret_cast<char *>(p2));
429  case POSIX_TTYNAME:
430  return console_ttyname(
431  static_cast<int>(p1), reinterpret_cast<char *>(p2));
432  case POSIX_TCGETPGRP:
433  return posix_tcgetpgrp(static_cast<int>(p1));
434  case POSIX_TCSETPGRP:
435  return posix_tcsetpgrp(
436  static_cast<int>(p1), static_cast<pid_t>(p2));
437 
438  case POSIX_USLEEP:
439  return posix_usleep(p1);
440 
441  case POSIX_MPROTECT:
442  return posix_mprotect(
443  reinterpret_cast<void *>(p1), p2, static_cast<int>(p3));
444 
445  case POSIX_REALPATH:
446  return posix_realpath(
447  reinterpret_cast<const char *>(p1),
448  reinterpret_cast<char *>(p2), p3);
449  case POSIX_TIMES:
450  return posix_times(reinterpret_cast<struct tms *>(p1));
451  case POSIX_GETRUSAGE:
452  return posix_getrusage(p1, reinterpret_cast<struct rusage *>(p2));
453  case POSIX_SETSOCKOPT:
454  return posix_setsockopt(
455  p1, p2, p3, reinterpret_cast<const void *>(p4), p5);
456  case POSIX_GETSOCKOPT:
457  return posix_getsockopt(
458  p1, p2, p3, reinterpret_cast<void *>(p4),
459  reinterpret_cast<socklen_t *>(p5));
460  case POSIX_GETPPID:
461  return posix_getppid();
462  case POSIX_UTIME:
463  return posix_utime(
464  reinterpret_cast<const char *>(p1),
465  reinterpret_cast<const struct utimbuf *>(p2));
466  case POSIX_UTIMES:
467  return posix_utimes(
468  reinterpret_cast<const char *>(p1),
469  reinterpret_cast<const struct timeval *>(p2));
470  case POSIX_CHROOT:
471  return posix_chroot(reinterpret_cast<const char *>(p1));
472 
473  case POSIX_GETGRNAM:
474  return posix_getgrnam(
475  reinterpret_cast<const char *>(p1),
476  reinterpret_cast<struct group *>(p2));
477  case POSIX_GETGRGID:
478  return posix_getgrgid(
479  static_cast<gid_t>(p1), reinterpret_cast<struct group *>(p2));
480  case POSIX_UMASK:
481  return posix_umask(static_cast<mode_t>(p1));
482  case POSIX_WRITEV:
483  return posix_writev(
484  static_cast<int>(p1),
485  reinterpret_cast<const struct iovec *>(p2), p3);
486  case POSIX_READV:
487  return posix_readv(
488  static_cast<int>(p1),
489  reinterpret_cast<const struct iovec *>(p2), p3);
490  case POSIX_GETDENTS:
491  return posix_getdents(
492  static_cast<int>(p1),
493  reinterpret_cast<struct linux_dirent *>(p2),
494  static_cast<int>(p3));
495  case POSIX_GETTID:
496  return posix_gettid();
497  case POSIX_BRK:
498  return posix_brk(p1);
499 
500  case POSIX_PEDIGREE_CREATE_WAITER:
501  return reinterpret_cast<uintptr_t>(posix_pedigree_create_waiter());
502  case POSIX_PEDIGREE_DESTROY_WAITER:
503  posix_pedigree_destroy_waiter(reinterpret_cast<void *>(p1));
504  break;
505  case POSIX_PEDIGREE_THREAD_WAIT_FOR:
506  return posix_pedigree_thread_wait_for(reinterpret_cast<void *>(p1));
507  case POSIX_PEDIGREE_THREAD_TRIGGER:
508  return posix_pedigree_thread_trigger(reinterpret_cast<void *>(p1));
509 
510  case POSIX_PEDIGREE_GET_INFO_BLOCK:
513 
514  case POSIX_SET_TLS_AREA:
515  Processor::information().getCurrentThread()->setTlsBase(p1);
516  return 0;
517 
518  case POSIX_FUTEX:
519  return posix_futex(
520  reinterpret_cast<int *>(p1), static_cast<int>(p2),
521  static_cast<int>(p3),
522  reinterpret_cast<const struct timespec *>(p4));
523  case POSIX_UNAME:
524  return posix_uname(reinterpret_cast<struct utsname *>(p1));
525  case POSIX_ARCH_PRCTL:
526  return posix_arch_prctl(p1, p2);
527  case POSIX_CLONE:
528  return posix_clone(
529  state, p1, reinterpret_cast<void *>(p2),
530  reinterpret_cast<int *>(p3), reinterpret_cast<int *>(p4), p5);
531  case POSIX_PAUSE:
532  return posix_pause();
533  case POSIX_GETDENTS64:
534  return posix_getdents64(
535  static_cast<int>(p1), reinterpret_cast<struct dirent *>(p2),
536  static_cast<int>(p3));
537  case POSIX_L_SYSLOG:
538  return posix_linux_syslog(p1, reinterpret_cast<char *>(p2), p3);
539  case POSIX_FLOCK:
540  return posix_flock(p1, p2);
541  case POSIX_OPENAT:
542  return posix_openat(p1, reinterpret_cast<const char *>(p2), p3, p4);
543  case POSIX_MKDIRAT:
544  return posix_mkdirat(p1, reinterpret_cast<const char *>(p2), p3);
545  case POSIX_FCHOWNAT:
546  return posix_fchownat(
547  p1, reinterpret_cast<const char *>(p2), p3, p4, p5);
548  case POSIX_FUTIMESAT:
549  return posix_futimesat(
550  p1, reinterpret_cast<const char *>(p2),
551  reinterpret_cast<struct timeval *>(p3));
552  case POSIX_UNLINKAT:
553  return posix_unlinkat(p1, reinterpret_cast<const char *>(p2), p3);
554  case POSIX_RENAMEAT:
555  return posix_renameat(
556  p1, reinterpret_cast<const char *>(p2), p3,
557  reinterpret_cast<const char *>(p4));
558  case POSIX_LINKAT:
559  return posix_linkat(
560  p1, reinterpret_cast<const char *>(p2), p3,
561  reinterpret_cast<const char *>(p4), p5);
562  case POSIX_SYMLINKAT:
563  return posix_symlinkat(
564  reinterpret_cast<const char *>(p1), p2,
565  reinterpret_cast<const char *>(p3));
566  case POSIX_READLINKAT:
567  return posix_readlinkat(
568  p1, reinterpret_cast<const char *>(p2),
569  reinterpret_cast<char *>(p3), p4);
570  case POSIX_FCHMODAT:
571  return posix_fchmodat(
572  p1, reinterpret_cast<const char *>(p2), p3, p4);
573  case POSIX_FACCESSAT:
574  return posix_faccessat(
575  p1, reinterpret_cast<const char *>(p2), p3, p4);
576  case POSIX_FSTATAT:
577  return posix_fstatat(
578  p1, reinterpret_cast<const char *>(p2),
579  reinterpret_cast<struct stat *>(p3), p4);
580  case POSIX_SETGROUPS:
581  return posix_setgroups(p1, reinterpret_cast<const gid_t *>(p2));
582  case POSIX_GETRLIMIT:
583  return posix_getrlimit(p1, reinterpret_cast<struct rlimit *>(p2));
584  case POSIX_GETPRIORITY:
585  return posix_getpriority(p1, p2);
586  case POSIX_SETPRIORITY:
587  return posix_setpriority(p1, p2, p3);
588  case POSIX_GETXATTR:
589  return posix_getxattr(
590  reinterpret_cast<const char *>(p1),
591  reinterpret_cast<const char *>(p2),
592  reinterpret_cast<void *>(p3), p4);
593  case POSIX_LGETXATTR:
594  return posix_lgetxattr(
595  reinterpret_cast<const char *>(p1),
596  reinterpret_cast<const char *>(p2),
597  reinterpret_cast<void *>(p3), p4);
598  case POSIX_FGETXATTR:
599  return posix_fgetxattr(
600  p1, reinterpret_cast<const char *>(p2),
601  reinterpret_cast<void *>(p3), p4);
602  case POSIX_MKNOD:
603  return posix_mknod(reinterpret_cast<const char *>(p1), p2, p3);
604  case POSIX_SETREUID:
605  return posix_setreuid(p1, p2);
606  case POSIX_SETREGID:
607  return posix_setregid(p1, p2);
608  case POSIX_SETRESUID:
609  return posix_setresuid(p1, p2, p3);
610  case POSIX_SETRESGID:
611  return posix_setresgid(p1, p2, p3);
612  case POSIX_GETRESUID:
613  return posix_getresuid(
614  reinterpret_cast<uid_t *>(p1), reinterpret_cast<uid_t *>(p2),
615  reinterpret_cast<uid_t *>(p3));
616  case POSIX_GETRESGID:
617  return posix_getresgid(
618  reinterpret_cast<gid_t *>(p1), reinterpret_cast<gid_t *>(p2),
619  reinterpret_cast<gid_t *>(p3));
620  case POSIX_STATFS:
621  return posix_statfs(
622  reinterpret_cast<const char *>(p1),
623  reinterpret_cast<struct statfs *>(p2));
624  case POSIX_FSTATFS:
625  return posix_fstatfs(p1, reinterpret_cast<struct statfs *>(p2));
626  case POSIX_SETHOSTNAME:
627  return posix_sethostname(reinterpret_cast<const char *>(p1), p2);
628  case POSIX_IOPERM:
629  return posix_ioperm(p1, p2, p3);
630  case POSIX_IOPL:
631  return posix_iopl(p1);
632  case POSIX_CREAT:
633  return posix_open(
634  reinterpret_cast<const char *>(p1),
635  O_WRONLY | O_CREAT | O_TRUNC, p2);
636  case POSIX_SET_ROBUST_LIST:
637  return posix_set_robust_list(
638  reinterpret_cast<struct robust_list_head *>(p1), p2);
639  case POSIX_GET_ROBUST_LIST:
640  return posix_get_robust_list(
641  p1, reinterpret_cast<struct robust_list_head **>(p2),
642  reinterpret_cast<size_t *>(p3));
643  case POSIX_GETGROUPS:
644  return posix_getgroups(p1, reinterpret_cast<gid_t *>(p2));
645  case POSIX_MOUNT:
646  return posix_mount(
647  reinterpret_cast<const char *>(p1),
648  reinterpret_cast<const char *>(p2),
649  reinterpret_cast<const char *>(p3), p4,
650  reinterpret_cast<const void *>(p5));
651  case POSIX_SETTIMEOFDAY:
652  return posix_settimeofday(
653  reinterpret_cast<const struct timeval *>(p1),
654  reinterpret_cast<const struct timezone *>(p2));
655  case POSIX_SETRLIMIT:
656  return posix_setrlimit(
657  p1, reinterpret_cast<const struct rlimit *>(p2));
658  case POSIX_TIME:
659  return posix_time(reinterpret_cast<time_t *>(p1));
660  case POSIX_GETITIMER:
661  return posix_getitimer(
662  p1, reinterpret_cast<struct itimerval *>(p2));
663  case POSIX_SETITIMER:
664  return posix_setitimer(
665  p1, reinterpret_cast<const struct itimerval *>(p2),
666  reinterpret_cast<struct itimerval *>(p3));
667  case POSIX_SOCKETPAIR:
668  return posix_socketpair(p1, p2, p3, reinterpret_cast<int *>(p4));
669  case POSIX_SENDMSG:
670  return posix_sendmsg(
671  p1, reinterpret_cast<const struct msghdr *>(p2), p3);
672  case POSIX_RECVMSG:
673  return posix_recvmsg(p1, reinterpret_cast<struct msghdr *>(p2), p3);
674  case POSIX_CAPGET:
675  return posix_capget(
676  reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
677  case POSIX_CAPSET:
678  return posix_capset(
679  reinterpret_cast<void *>(p1),
680  reinterpret_cast<const void *>(p2));
681  case POSIX_PRCTL:
682  return posix_prctl(p1, p2, p3, p4, p5);
683 
684  default:
685  ERROR(
686  "PosixSyscallManager: invalid syscall received: "
687  << Dec << syscallNumber << Hex);
688  SYSCALL_ERROR(Unimplemented);
689  return -1;
690  }
691 
692  return 0;
693 }
size_t getId()
Definition: Process.h:108
static EXPORTED_PUBLIC SyscallManager & instance()
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
static ProcessorInformation & information()
Definition: Processor.cc:45
Tree< size_t, bool > m_SeenUnknownSyscalls
#define WARNING(text)
Definition: Log.h:78
void insert(const K &key, const E &value)
Definition: Tree.h:173
#define NOTICE(text)
Definition: Log.h:74
uintptr_t call(uintptr_t function, uintptr_t p1=0, uintptr_t p2=0, uintptr_t p3=0, uintptr_t p4=0, uintptr_t p5=0)
Definition: Log.h:136
static Scheduler & instance()
Definition: Scheduler.h:48
static void setInterrupts(bool bEnable)
void setAbi(Abi which)
virtual uintptr_t syscall(SyscallState &state)
#define ERROR(text)
Definition: Log.h:82
void yield()
Definition: Scheduler.cc:135
Definition: Log.h:138
virtual bool registerSyscallHandler(Service_t Service, SyscallHandler *pHandler)=0
virtual uintptr_t syscall(Service_t service, uintptr_t function, uintptr_t p1=0, uintptr_t p2=0, uintptr_t p3=0, uintptr_t p4=0, uintptr_t p5=0)=0
E lookup(const K &key) const
Definition: Tree.h:192