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" 30 #include "PosixSyscallManager.h" 31 #include "console-syscalls.h" 32 #include "file-syscalls.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" 47 #include "pedigree/kernel/debugger/Backtrace.h" 57 void PosixSyscallManager::initialise()
64 uintptr_t
function, uintptr_t p1, uintptr_t p2, uintptr_t p3, uintptr_t p4,
67 if (
function >= serviceEnd)
70 "PosixSyscallManager: invalid function called: " 71 <<
Dec << static_cast<int>(
function));
82 uint64_t syscallNumber = state.getSyscallNumber();
85 if (state.getSyscallService() == linuxCompat)
92 pSubsystem->
setAbi(PosixSubsystem::LinuxAbi);
97 long which = posix_translate_syscall(syscallNumber);
100 size_t key = (pProcess->
getId() << 32ULL) | syscallNumber;
104 "POSIX: unknown Linux syscall " 105 << syscallNumber <<
" by pid=" << pProcess->
getId()
106 <<
", translation failed!");
109 SYSCALL_ERROR(Unimplemented);
112 #ifdef POSIX_VERBOSE_SYSCALLS 116 "TRANSLATED syscall: Linux #" << syscallNumber
117 <<
" -> Pedigree #" << which);
121 syscallNumber = which;
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);
131 #ifdef POSIX_VERBOSE_SYSCALLS 134 <<
"] : " <<
Dec << syscallNumber <<
Hex);
140 switch (syscallNumber)
144 return posix_open(reinterpret_cast<const char *>(p1), p2, p3);
146 return posix_write(p1, reinterpret_cast<char *>(p2), p3);
148 return posix_read(p1, reinterpret_cast<char *>(p2), p3);
150 return posix_close(p1);
152 return posix_sbrk(p1);
154 return posix_fork(state);
157 reinterpret_cast<const char *>(p1),
158 reinterpret_cast<const char **>(p2),
159 reinterpret_cast<const char **>(p3), state);
161 return posix_waitpid(p1, reinterpret_cast<int *>(p2), p3);
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));
174 return posix_ioctl(p1, p2, reinterpret_cast<void *>(p3));
177 reinterpret_cast<const char *>(p1),
178 reinterpret_cast<struct stat *>(p2));
180 return posix_fstat(p1, reinterpret_cast<struct stat *>(p2));
182 return posix_getpid();
184 return posix_chdir(reinterpret_cast<const char *>(p1));
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));
192 static_cast<int>(p1), static_cast<off_t>(p2),
193 static_cast<int>(p3));
196 static_cast<int>(p1), static_cast<int>(p2),
197 static_cast<int>(p3));
199 return posix_connect(
200 static_cast<int>(p1), reinterpret_cast<sockaddr *>(p2), p3);
203 static_cast<int>(p1), reinterpret_cast<void *>(p2), p3,
204 static_cast<int>(p4));
207 static_cast<int>(p1), reinterpret_cast<void *>(p2), p3,
208 static_cast<int>(p4));
211 static_cast<int>(p1), reinterpret_cast<sockaddr *>(p2), p3);
213 return posix_listen(static_cast<int>(p1), static_cast<int>(p2));
216 static_cast<int>(p1), reinterpret_cast<sockaddr *>(p2),
217 reinterpret_cast<socklen_t *>(p3));
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));
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));
233 return posix_dup(static_cast<int>(p1));
235 return posix_dup2(static_cast<int>(p1), static_cast<int>(p2));
238 reinterpret_cast<char *>(p1),
239 reinterpret_cast<struct stat *>(p2));
241 return posix_unlink(reinterpret_cast<char *>(p1));
243 return posix_symlink(
244 reinterpret_cast<char *>(p1), reinterpret_cast<char *>(p2));
247 static_cast<int>(p1), static_cast<int>(p2),
248 reinterpret_cast<void *>(p3));
250 return posix_pipe(reinterpret_cast<int *>(p1));
253 reinterpret_cast<const char *>(p1), static_cast<int>(p2));
255 return posix_rmdir(reinterpret_cast<const char *>(p1));
257 return posix_getpwent(
258 reinterpret_cast<passwd *>(p1), static_cast<int>(p2),
259 reinterpret_cast<char *>(p3));
261 return posix_getpwnam(
262 reinterpret_cast<passwd *>(p1),
263 reinterpret_cast<const char *>(p2),
264 reinterpret_cast<char *>(p3));
266 return posix_getuid();
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));
276 static_cast<int>(p1), reinterpret_cast<void *>(p2));
278 return posix_raise(static_cast<int>(p1), state);
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));
286 return posix_alarm(p1);
288 return posix_sleep(p1);
291 reinterpret_cast<pollfd *>(p1), static_cast<unsigned int>(p2),
292 static_cast<int>(p3));
295 reinterpret_cast<const char *>(p1),
296 reinterpret_cast<const char *>(p2));
298 return posix_getcwd(reinterpret_cast<char *>(p1), p2);
300 return posix_readlink(
301 reinterpret_cast<const char *>(p1),
302 reinterpret_cast<char *>(p2), static_cast<unsigned int>(p3));
305 reinterpret_cast<char *>(p1), reinterpret_cast<char *>(p2));
307 return posix_isatty(static_cast<int>(p1));
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)));
314 return posix_munmap(reinterpret_cast<void *>(p1), p2);
316 return posix_shutdown(static_cast<int>(p1), static_cast<int>(p2));
319 reinterpret_cast<const char *>(p1), static_cast<int>(p2));
321 return posix_setsid();
323 return posix_setpgid(static_cast<int>(p1), static_cast<int>(p2));
325 return posix_getpgid(static_cast<int>(p1));
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));
335 reinterpret_cast<const char *>(p1), static_cast<int>(p2));
337 case POSIX_FTRUNCATE:
338 return posix_ftruncate(
339 static_cast<int>(p1), static_cast<off_t>(p2));
347 static char buf[128];
348 StringCopyN(buf, reinterpret_cast<char *>(p1), 128);
349 WARNING(
"Using stubbed function '" << buf <<
"'");
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.");
359 case POSIX_SCHED_YIELD:
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));
372 return posix_geteuid();
374 return posix_getegid();
376 return posix_seteuid(static_cast<uid_t>(p1));
378 return posix_setegid(static_cast<gid_t>(p1));
380 return posix_setuid(static_cast<uid_t>(p1));
382 return posix_setgid(static_cast<gid_t>(p1));
386 reinterpret_cast<const char *>(p1), static_cast<uid_t>(p2),
387 static_cast<gid_t>(p3));
390 reinterpret_cast<const char *>(p1), static_cast<mode_t>(p2));
393 static_cast<int>(p1), static_cast<uid_t>(p2),
394 static_cast<gid_t>(p3));
396 return posix_fchmod(static_cast<int>(p1), static_cast<mode_t>(p2));
398 return posix_fchdir(static_cast<int>(p1));
401 return posix_statvfs(
402 reinterpret_cast<const char *>(p1),
403 reinterpret_cast<struct statvfs *>(p2));
405 return posix_fstatvfs(
406 static_cast<int>(p1), reinterpret_cast<struct statvfs *>(p2));
408 case PEDIGREE_UNWIND_SIGNAL:
409 pedigree_unwind_signal();
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));
424 return posix_fsync(static_cast<int>(p1));
427 return console_ptsname(
428 static_cast<int>(p1), reinterpret_cast<char *>(p2));
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));
439 return posix_usleep(p1);
442 return posix_mprotect(
443 reinterpret_cast<void *>(p1), p2, static_cast<int>(p3));
446 return posix_realpath(
447 reinterpret_cast<const char *>(p1),
448 reinterpret_cast<char *>(p2), p3);
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));
461 return posix_getppid();
464 reinterpret_cast<const char *>(p1),
465 reinterpret_cast<const struct utimbuf *>(p2));
468 reinterpret_cast<const char *>(p1),
469 reinterpret_cast<const struct timeval *>(p2));
471 return posix_chroot(reinterpret_cast<const char *>(p1));
474 return posix_getgrnam(
475 reinterpret_cast<const char *>(p1),
476 reinterpret_cast<struct group *>(p2));
478 return posix_getgrgid(
479 static_cast<gid_t>(p1), reinterpret_cast<struct group *>(p2));
481 return posix_umask(static_cast<mode_t>(p1));
484 static_cast<int>(p1),
485 reinterpret_cast<const struct iovec *>(p2), p3);
488 static_cast<int>(p1),
489 reinterpret_cast<const struct iovec *>(p2), p3);
491 return posix_getdents(
492 static_cast<int>(p1),
493 reinterpret_cast<struct linux_dirent *>(p2),
494 static_cast<int>(p3));
496 return posix_gettid();
498 return posix_brk(p1);
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));
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));
510 case POSIX_PEDIGREE_GET_INFO_BLOCK:
514 case POSIX_SET_TLS_AREA:
520 reinterpret_cast<int *>(p1), static_cast<int>(p2),
521 static_cast<int>(p3),
522 reinterpret_cast<const struct timespec *>(p4));
524 return posix_uname(reinterpret_cast<struct utsname *>(p1));
525 case POSIX_ARCH_PRCTL:
526 return posix_arch_prctl(p1, p2);
529 state, p1, reinterpret_cast<void *>(p2),
530 reinterpret_cast<int *>(p3), reinterpret_cast<int *>(p4), p5);
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));
538 return posix_linux_syslog(p1, reinterpret_cast<char *>(p2), p3);
540 return posix_flock(p1, p2);
542 return posix_openat(p1, reinterpret_cast<const char *>(p2), p3, p4);
544 return posix_mkdirat(p1, reinterpret_cast<const char *>(p2), p3);
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));
553 return posix_unlinkat(p1, reinterpret_cast<const char *>(p2), p3);
555 return posix_renameat(
556 p1, reinterpret_cast<const char *>(p2), p3,
557 reinterpret_cast<const char *>(p4));
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);
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);
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);
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);
603 return posix_mknod(reinterpret_cast<const char *>(p1), p2, p3);
605 return posix_setreuid(p1, p2);
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));
622 reinterpret_cast<const char *>(p1),
623 reinterpret_cast<struct statfs *>(p2));
625 return posix_fstatfs(p1, reinterpret_cast<struct statfs *>(p2));
626 case POSIX_SETHOSTNAME:
627 return posix_sethostname(reinterpret_cast<const char *>(p1), p2);
629 return posix_ioperm(p1, p2, p3);
631 return posix_iopl(p1);
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));
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));
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));
670 return posix_sendmsg(
671 p1, reinterpret_cast<const struct msghdr *>(p2), p3);
673 return posix_recvmsg(p1, reinterpret_cast<struct msghdr *>(p2), p3);
676 reinterpret_cast<void *>(p1), reinterpret_cast<void *>(p2));
679 reinterpret_cast<void *>(p1),
680 reinterpret_cast<const void *>(p2));
682 return posix_prctl(p1, p2, p3, p4, p5);
686 "PosixSyscallManager: invalid syscall received: " 687 <<
Dec << syscallNumber <<
Hex);
688 SYSCALL_ERROR(Unimplemented);
static EXPORTED_PUBLIC SyscallManager & instance()
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
static ProcessorInformation & information()
Tree< size_t, bool > m_SeenUnknownSyscalls
virtual ~PosixSyscallManager()
void insert(const K &key, const E &value)
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)
static Scheduler & instance()
static void setInterrupts(bool bEnable)
virtual uintptr_t syscall(SyscallState &state)
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
virtual uintptr_t getGlobalInfoBlock() const