20#include "pedigree/kernel/LockGuard.h"
21#include "pedigree/kernel/Log.h"
22#include "pedigree/kernel/compiler.h"
23#include "pedigree/kernel/debugger/Backtrace.h"
24#include "pedigree/kernel/process/Process.h"
25#include "pedigree/kernel/process/Scheduler.h"
26#include "pedigree/kernel/process/TerminationDeferral.h"
27#include "pedigree/kernel/processor/PageFaultHandler.h"
28#include "pedigree/kernel/processor/Processor.h"
29#include "pedigree/kernel/processor/SyscallManager.h"
30#include "pedigree/kernel/processor/state.h"
31#include "pedigree/kernel/syscallError.h"
32#include "pedigree/kernel/time/Time.h"
37#include "PosixSyscallManager.h"
38#include "clock-adjust-syscalls.h"
39#include "clone3-syscalls.h"
40#include "console-syscalls.h"
41#include "epoll-syscalls.h"
42#include "eventfd-syscalls.h"
43#include "execveat-syscalls.h"
44#include "fanotify-syscalls.h"
45#include "file-handle-syscalls.h"
46#include "file-sync-syscalls.h"
47#include "file-syscalls.h"
48#include "filesystem-capability-syscalls.h"
49#include "global-sync-syscalls.h"
50#include "init-module-syscalls.h"
51#include "inotify-syscalls.h"
52#include "job-control-syscalls.h"
54#include "linux-amd64-signal.h"
56#include "memfd-syscalls.h"
57#include "metadata-syscalls.h"
58#include "module-syscalls.h"
59#include "mount-view-syscalls.h"
60#include "mqueue-syscalls.h"
61#include "namespace-syscalls.h"
62#include "net-syscalls.h"
63#include "pipe-syscalls.h"
64#include "pipe-transfer-syscalls.h"
65#include "poll-syscalls.h"
66#include "posix-timer-syscalls.h"
67#include "posixSyscallNumbers.h"
68#include "process-accounting.h"
69#include "process-vm-syscalls.h"
70#include "pthread-syscalls.h"
71#include "ptrace-syscalls.h"
72#include "queued-signal.h"
73#include "quota-syscalls.h"
74#include "recvmmsg-syscalls.h"
75#include "sandbox-state.h"
76#include "scheduling-syscalls.h"
77#include "select-syscalls.h"
78#include "signal-syscalls.h"
79#include "signalfd-syscalls.h"
80#include "swap-syscalls.h"
81#include "syscalls/translate.h"
82#include "system-information-syscalls.h"
83#include "system-syscalls.h"
84#include "sysv-message-syscalls.h"
85#include "sysv-semaphore-syscalls.h"
86#include "sysv-shm-syscalls.h"
87#include "terminal-syscalls.h"
88#include "timerfd-syscalls.h"
89#include "transfer-syscalls.h"
90#include "vm-syscalls.h"
91#include "wait-syscalls.h"
92#include "xattr-syscalls.h"
94#if PEDIGREE_BENCHMARK_SYSCALL_TRACE
95#include "syscall-trace.h"
99class UnsupportedSyscallLog {
102 : m_State(state), m_Seen(seen), m_Lock(lock) {}
104 ~UnsupportedSyscallLog() {
106 const size_t error = thread->
getErrno();
107 if (error != Error::Unimplemented && error != Error::OperationNotSupported) {
112 const uint64_t number = m_State.getSyscallNumber();
113 const bool linuxAbi = m_State.getSyscallService() == linuxCompat;
114 const uint64_t key = (
static_cast<uint64_t
>(process->
getId()) << 32) |
115 ((number & 0x3fffffff) << 2) | (
static_cast<uint64_t
>(linuxAbi) << 1) |
116 (error == Error::OperationNotSupported);
117 bool firstOccurrence =
false;
121 firstOccurrence = !m_Seen.lookup(key);
122 if (firstOccurrence) {
123 m_Seen.insert(key,
true);
126 if (firstOccurrence) {
127 NOTICE(
"POSIX: pid=" <<
Dec << process->
getId() <<
" " << (linuxAbi ?
"Linux" :
"native")
128 <<
" syscall #" << number <<
" set "
129 << (error == Error::Unimplemented ?
"ENOSYS" :
"ENOTSUP") <<
Hex);
134 SyscallState& m_State;
139off_t linuxAmd64VectorOffset(uintptr_t low, uintptr_t high) {
140 const uint64_t bits =
141 (
static_cast<uint64_t
>(high) << 32U) | (
static_cast<uint64_t
>(low) & 0xFFFFFFFFULL);
142 return static_cast<off_t
>(bits);
145#if PEDIGREE_SYSCALL_COUNTER
146class SyscallLatencyRecorder {
148 explicit SyscallLatencyRecorder(
Process* process)
149 : m_pProcess(process), m_Start(Time::getTicks()) {}
151 ~SyscallLatencyRecorder() {
153 m_pProcess->recordSyscallDuration(Time::getTicks() - m_Start);
159 Time::Timestamp m_Start;
168bool PosixSyscallManager::initialise() {
174 if (!m_LinuxRegistration.reset()) {
175 FATAL(
"POSIX syscall registration rollback failed.");
182bool PosixSyscallManager::closeAdmission() {
185 return posixClosed && linuxClosed;
188bool PosixSyscallManager::finishShutdown() {
189 const bool posixRetired = m_PosixRegistration.reset();
190 const bool linuxRetired = m_LinuxRegistration.reset();
191 return posixRetired && linuxRetired;
194bool PosixSyscallManager::shutdown() {
195 return closeAdmission() && finishShutdown();
199 uintptr_t p4, uintptr_t p5) {
200 if (function >= serviceEnd) {
201 ERROR(
"PosixSyscallManager: invalid function called: " <<
Dec <<
static_cast<int>(function));
210 return syscallEntry(
this, state);
213uintptr_t PosixSyscallManager::syscallEntry(
SyscallHandler* handler, SyscallState& state) {
215 UnsupportedSyscallLog unsupported(state, manager->m_SeenUnsupportedSyscalls,
216 manager->m_UnsupportedSyscallsLock);
217#if PEDIGREE_BENCHMARK_SYSCALL_TRACE
220 if (!process || !process->benchmarkSyscallTraceEnabled()) {
221 return syscallDispatch(handler, state);
224 const int entryError = thread->
getErrno();
225 SyscallTrace trace(state, *thread);
227 const Time::Timestamp start = Time::getTicks();
228 const uintptr_t result = syscallDispatch(handler, state);
229 const int error = thread->
getErrno();
230 const Time::Timestamp elapsed = Time::getTicks() - start;
231 trace.finish(result, error, elapsed);
236uintptr_t PosixSyscallManager::syscallDispatch(
SyscallHandler* handler, SyscallState& state) {
238#if PEDIGREE_SYSCALL_COUNTER
240 if (syscallProcess) {
243 syscallProcess->recordSyscall();
245 SyscallLatencyRecorder syscallLatencyRecorder(syscallProcess);
247 const uint64_t syscallNumber = state.getSyscallNumber();
248 const bool linuxAbi = state.getSyscallService() == linuxCompat;
249 const uintptr_t base = linuxAbi ? 6 : 0;
250 const auto argument = [&state, base](
size_t index)
251 ALWAYS_INLINE {
return state.getSyscallParameter(base + index); };
257 pSubsystem->
setAbi(PosixSubsystem::LinuxAbi);
259 EMIT_IF(POSIX_LOG_FACILITIES & 128) {
260 const long which = posix_translate_syscall(syscallNumber);
262 NOTICE(
"TRANSLATED syscall: Linux #" << syscallNumber <<
" -> Pedigree #" << which);
263 NOTICE(
"[" << pProcess->
getId() <<
"] : " <<
Dec << which <<
Hex);
267 switch (syscallNumber) {
273 const off_t offset = (
static_cast<uint64_t
>(argument(1)) << 32) | argument(2);
275 posix_lseek(
static_cast<int>(argument(0)), offset,
static_cast<int>(argument(4)));
281 SYSCALL_ERROR(BadAddress);
288#define PEDIGREE_LINUX_ARM64_SYSCALL(name, number, target) \
289 case PedigreeLinuxArm64Syscall_##name: \
290 goto handle_##target;
291#include "syscalls/linuxSyscallMappings-arm64.h"
292#undef PEDIGREE_LINUX_ARM64_SYSCALL
294#define PEDIGREE_LINUX_ARMV7_SYSCALL(name, number, target) \
295 case PedigreeLinuxArmv7Syscall_##name: \
296 goto handle_##target;
297#include "syscalls/linuxSyscallMappings-armv7.h"
298#undef PEDIGREE_LINUX_ARMV7_SYSCALL
300#define PEDIGREE_LINUX_AMD64_SYSCALL(name, number, target) \
301 case PedigreeLinuxAmd64Syscall_##name: \
302 goto handle_##target;
303#include "syscalls/linuxSyscallMappings-amd64.h"
304#undef PEDIGREE_LINUX_AMD64_SYSCALL
308 SYSCALL_ERROR(Unimplemented);
312 EMIT_IF(POSIX_LOG_FACILITIES & 128) {
314 << syscallNumber <<
Hex);
318#define POSIX_CASE(target) \
321 switch (syscallNumber) {
323 POSIX_CASE(POSIX_SECCOMP)
324 return posix_seccomp(argument(0), argument(1),
reinterpret_cast<const void*
>(argument(2)));
325 POSIX_CASE(POSIX_LANDLOCK_CREATE_RULESET)
326 return posix_landlock_create_ruleset(
reinterpret_cast<const void*
>(argument(0)), argument(1),
328 POSIX_CASE(POSIX_LANDLOCK_ADD_RULE)
329 return posix_landlock_add_rule(argument(0), argument(1),
330 reinterpret_cast<const void*
>(argument(2)), argument(3));
331 POSIX_CASE(POSIX_LANDLOCK_RESTRICT_SELF)
332 return posix_landlock_restrict_self(argument(0), argument(1));
333 POSIX_CASE(POSIX_OPEN)
334 return posix_open(
reinterpret_cast<const char*
>(argument(0)), argument(1), argument(2));
335 POSIX_CASE(POSIX_WRITE)
336 return posix_write(argument(0),
reinterpret_cast<char*
>(argument(1)), argument(2));
337 POSIX_CASE(POSIX_READ) {
338 const int result = posix_read(argument(0),
reinterpret_cast<char*
>(argument(1)), argument(2));
340 F_NOTICE(
"read(" <<
Dec << argument(0) <<
") -> " << result
345 POSIX_CASE(POSIX_PREAD64)
346 return posix_pread64(
static_cast<int>(argument(0)),
reinterpret_cast<char*
>(argument(1)),
347 static_cast<size_t>(argument(2)),
static_cast<off_t
>(argument(3)));
348 POSIX_CASE(POSIX_PWRITE64)
349 return posix_pwrite64(
static_cast<int>(argument(0)),
350 reinterpret_cast<const char*
>(argument(1)),
351 static_cast<size_t>(argument(2)),
static_cast<off_t
>(argument(3)));
352 POSIX_CASE(POSIX_PREADV)
354 static_cast<int>(argument(0)),
reinterpret_cast<const struct iovec*
>(argument(1)),
355 static_cast<int>(argument(2)), linuxAmd64VectorOffset(argument(3), argument(4)));
356 POSIX_CASE(POSIX_PWRITEV)
357 return posix_pwritev(
358 static_cast<int>(argument(0)),
reinterpret_cast<const struct iovec*
>(argument(1)),
359 static_cast<int>(argument(2)), linuxAmd64VectorOffset(argument(3), argument(4)));
360 POSIX_CASE(POSIX_PREADV2)
361 return posix_preadv2(
362 static_cast<int>(argument(0)),
reinterpret_cast<const struct iovec*
>(argument(1)),
363 static_cast<int>(argument(2)), linuxAmd64VectorOffset(argument(3), argument(4)),
364 static_cast<int>(argument(5)));
365 POSIX_CASE(POSIX_PWRITEV2)
366 return posix_pwritev2(
367 static_cast<int>(argument(0)),
reinterpret_cast<const struct iovec*
>(argument(1)),
368 static_cast<int>(argument(2)), linuxAmd64VectorOffset(argument(3), argument(4)),
369 static_cast<int>(argument(5)));
370 POSIX_CASE(POSIX_CLOSE)
371 return posix_close(argument(0));
373 return posix_sbrk(argument(0));
374 POSIX_CASE(POSIX_FORK)
375 return posix_fork(state);
376 POSIX_CASE(POSIX_VFORK)
377 return posix_vfork(state);
378 POSIX_CASE(POSIX_EXECVE)
379 return posix_execve(
reinterpret_cast<const char*
>(argument(0)),
380 reinterpret_cast<const char**
>(argument(1)),
381 reinterpret_cast<const char**
>(argument(2)), state);
382 POSIX_CASE(POSIX_EXECVEAT)
383 return posix_execveat(
384 static_cast<int>(argument(0)),
reinterpret_cast<const char*
>(argument(1)),
385 reinterpret_cast<const char**
>(argument(2)),
reinterpret_cast<const char**
>(argument(3)),
386 static_cast<int>(argument(4)), state);
387 POSIX_CASE(POSIX_INIT_MODULE)
388 return posix_init_module(
reinterpret_cast<const void*
>(argument(0)), argument(1),
389 reinterpret_cast<const char*
>(argument(2)));
390 POSIX_CASE(POSIX_ACCT)
391 return posix_acct(
reinterpret_cast<const char*
>(argument(0)));
392 POSIX_CASE(POSIX_VHANGUP)
393 return posix_vhangup();
394 POSIX_CASE(POSIX_QUOTACTL)
395 return posix_quotactl(
static_cast<int>(argument(0)),
396 reinterpret_cast<const char*
>(argument(1)),
397 static_cast<int>(argument(2)),
reinterpret_cast<void*
>(argument(3)));
398 POSIX_CASE(POSIX_SWAPON)
399 return posix_swapon(
reinterpret_cast<const char*
>(argument(0)),
400 static_cast<int>(argument(1)));
401 POSIX_CASE(POSIX_SWAPOFF)
402 return posix_swapoff(
reinterpret_cast<const char*
>(argument(0)));
403 POSIX_CASE(POSIX_SYSINFO)
404 return posix_sysinfo(
reinterpret_cast<void*
>(argument(0)));
405 POSIX_CASE(POSIX_PERSONALITY)
406 return posix_personality(
static_cast<unsigned long>(argument(0)));
407 POSIX_CASE(POSIX_PIVOT_ROOT)
408 return posix_pivot_root(
reinterpret_cast<const char*
>(argument(0)),
409 reinterpret_cast<const char*
>(argument(1)));
410 POSIX_CASE(POSIX_TRUNCATE)
411 return posix_truncate(
reinterpret_cast<const char*
>(argument(0)),
412 static_cast<off_t
>(argument(1)));
413 POSIX_CASE(POSIX_LCHOWN)
414 return posix_lchown(
reinterpret_cast<const char*
>(argument(0)),
415 static_cast<uid_t
>(argument(1)),
static_cast<gid_t
>(argument(2)));
416 POSIX_CASE(POSIX_UTIMENSAT)
417 return posix_utimensat(
418 static_cast<int>(argument(0)),
reinterpret_cast<const char*
>(argument(1)),
419 reinterpret_cast<const void*
>(argument(2)),
static_cast<int>(argument(3)));
420 POSIX_CASE(POSIX_STATX)
421 return posix_statx(
static_cast<int>(argument(0)),
reinterpret_cast<const char*
>(argument(1)),
422 static_cast<int>(argument(2)),
static_cast<unsigned>(argument(3)),
423 reinterpret_cast<void*
>(argument(4)));
424 POSIX_CASE(POSIX_FCHMODAT2)
425 return posix_fchmodat2(
static_cast<int>(argument(0)),
426 reinterpret_cast<const char*
>(argument(1)),
427 static_cast<mode_t
>(argument(2)),
static_cast<int>(argument(3)));
428 POSIX_CASE(POSIX_MKNODAT)
429 return posix_mknodat(
static_cast<int>(argument(0)),
430 reinterpret_cast<const char*
>(argument(1)),
431 static_cast<mode_t
>(argument(2)),
static_cast<dev_t
>(argument(3)));
432 POSIX_CASE(POSIX_WAITPID)
433 return posix_waitpid(argument(0),
reinterpret_cast<int*
>(argument(1)), argument(2),
434 linuxAbi ?
reinterpret_cast<LinuxRusage64*
>(argument(3)) : nullptr);
435 POSIX_CASE(POSIX_WAITID)
436 return posix_waitid(
static_cast<int>(argument(0)),
static_cast<int32_t
>(argument(1)),
437 reinterpret_cast<void*
>(argument(2)),
static_cast<int>(argument(3)),
439 POSIX_CASE(POSIX_PTRACE)
440 return posix_ptrace(argument(0),
static_cast<int32_t
>(argument(1)), argument(2), argument(3),
442 POSIX_CASE(POSIX_DELETE_MODULE)
443 return posix_delete_module(
reinterpret_cast<const char*
>(argument(0)),
444 static_cast<unsigned>(argument(1)));
445 POSIX_CASE(POSIX_ADJTIMEX)
446 return posix_adjtimex(
reinterpret_cast<void*
>(argument(0)));
447 POSIX_CASE(POSIX_CLOCK_ADJTIME)
448 return posix_clock_adjtime(
static_cast<int>(argument(0)),
449 reinterpret_cast<void*
>(argument(1)));
450 POSIX_CASE(POSIX_FDATASYNC)
451 return posix_fdatasync(
static_cast<int>(argument(0)));
452 POSIX_CASE(POSIX_SYNC)
454 POSIX_CASE(POSIX_GETSID)
455 return posix_getsid(argument(0));
456 POSIX_CASE(POSIX_FALLOCATE)
457 return posix_fallocate(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
458 static_cast<off_t
>(argument(2)),
static_cast<off_t
>(argument(3)));
459 POSIX_CASE(POSIX_RENAMEAT2)
460 return posix_renameat2(
461 static_cast<int>(argument(0)),
reinterpret_cast<const char*
>(argument(1)),
462 static_cast<int>(argument(2)),
reinterpret_cast<const char*
>(argument(3)),
463 static_cast<unsigned>(argument(4)));
464 POSIX_CASE(POSIX_RECVMMSG)
465 return posix_recvmmsg(
static_cast<int>(argument(0)),
467 static_cast<unsigned>(argument(2)),
static_cast<unsigned>(argument(3)),
469 POSIX_CASE(POSIX_SYNCFS)
470 return posix_syncfs(
static_cast<int>(argument(0)));
471 POSIX_CASE(POSIX_READAHEAD)
472 return posix_readahead(
static_cast<int>(argument(0)),
static_cast<off_t
>(argument(1)),
474 POSIX_CASE(POSIX_FADVISE64)
475 return posix_fadvise64(
static_cast<int>(argument(0)),
static_cast<off_t
>(argument(1)),
476 static_cast<off_t
>(argument(2)),
static_cast<int>(argument(3)));
477 POSIX_CASE(POSIX_SYNC_FILE_RANGE)
478 return posix_sync_file_range(
static_cast<int>(argument(0)),
static_cast<off_t
>(argument(1)),
479 static_cast<off_t
>(argument(2)),
480 static_cast<unsigned>(argument(3)));
481 POSIX_CASE(POSIX_EXIT) {
482 const uintptr_t p1 = argument(0);
483 NOTICE(
"POSIX exit request: pid="
489 const bool requested =
493 FATAL(
"POSIX thread exit was not dispatched.");
496 FATAL(
"POSIX process exit was not dispatched.");
500 POSIX_CASE(POSIX_EXIT_GROUP) {
501 const uintptr_t p1 = argument(0);
502 NOTICE(
"POSIX exit-group request: pid="
506 FATAL(
"POSIX process-group exit was not dispatched.");
510 case POSIX_PTHREAD_RETURN:
511 NOTICE(
"POSIX thread-return request: pid="
513 <<
" code=" << argument(0));
515 FATAL(
"POSIX pthread exit was not dispatched.");
518 case POSIX_TCGETATTR:
519 return posix_tcgetattr(argument(0),
reinterpret_cast<struct termios*
>(argument(1)));
520 case POSIX_TCSETATTR:
521 return posix_tcsetattr(argument(0), argument(1),
522 reinterpret_cast<struct termios*
>(argument(2)));
523 POSIX_CASE(POSIX_IOCTL) {
525 const size_t command = linuxAbi ?
static_cast<uint32_t
>(argument(1)) : argument(1);
526 const int result = posix_ioctl(argument(0), command,
reinterpret_cast<void*
>(argument(2)));
528 "ioctl(" <<
Dec << argument(0) <<
", " <<
Hex << command <<
") -> " <<
Dec << result
533 POSIX_CASE(POSIX_STAT)
534 return posix_stat(
reinterpret_cast<const char*
>(argument(0)),
535 reinterpret_cast<struct stat*
>(argument(1)));
536 POSIX_CASE(POSIX_FSTAT)
537 return posix_fstat(argument(0),
reinterpret_cast<struct stat*
>(argument(1)));
538 POSIX_CASE(POSIX_GETPID)
539 return posix_getpid();
540 POSIX_CASE(POSIX_CHDIR)
541 return posix_chdir(
reinterpret_cast<const char*
>(argument(0)));
542 POSIX_CASE(POSIX_SELECT)
543 return posix_select(
static_cast<int>(argument(0)),
reinterpret_cast<fd_set*
>(argument(1)),
544 reinterpret_cast<fd_set*
>(argument(2)),
545 reinterpret_cast<fd_set*
>(argument(3)),
546 reinterpret_cast<struct timeval*
>(argument(4)));
547 POSIX_CASE(POSIX_LSEEK)
548 return posix_lseek(
static_cast<int>(argument(0)),
static_cast<off_t
>(argument(1)),
549 static_cast<int>(argument(2)));
550 POSIX_CASE(POSIX_SOCKET)
551 return posix_socket(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
552 static_cast<int>(argument(2)));
553 POSIX_CASE(POSIX_CONNECT)
554 return posix_connect(
static_cast<int>(argument(0)),
555 reinterpret_cast<struct sockaddr_storage*
>(argument(1)), argument(2));
557 return posix_send(
static_cast<int>(argument(0)),
reinterpret_cast<void*
>(argument(1)),
558 argument(2),
static_cast<int>(argument(3)));
560 return posix_recv(
static_cast<int>(argument(0)),
reinterpret_cast<void*
>(argument(1)),
561 argument(2),
static_cast<int>(argument(3)));
562 POSIX_CASE(POSIX_BIND)
563 return posix_bind(
static_cast<int>(argument(0)),
564 reinterpret_cast<struct sockaddr_storage*
>(argument(1)), argument(2));
565 POSIX_CASE(POSIX_LISTEN)
566 return posix_listen(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)));
567 POSIX_CASE(POSIX_ACCEPT)
568 return posix_accept(
static_cast<int>(argument(0)),
569 reinterpret_cast<struct sockaddr_storage*
>(argument(1)),
570 reinterpret_cast<socklen_t*
>(argument(2)));
571 POSIX_CASE(POSIX_ACCEPT4)
572 return posix_accept4(
573 static_cast<int>(argument(0)),
reinterpret_cast<struct sockaddr_storage*
>(argument(1)),
574 reinterpret_cast<socklen_t*
>(argument(2)),
static_cast<int>(argument(3)));
575 POSIX_CASE(POSIX_RECVFROM)
576 return posix_recvfrom(
static_cast<int>(argument(0)),
reinterpret_cast<void*
>(argument(1)),
577 argument(2),
static_cast<int>(argument(3)),
578 reinterpret_cast<struct sockaddr_storage*
>(argument(4)),
579 reinterpret_cast<socklen_t*
>(argument(5)));
580 POSIX_CASE(POSIX_SENDTO)
581 return posix_sendto(
static_cast<int>(argument(0)),
reinterpret_cast<void*
>(argument(1)),
582 argument(2),
static_cast<int>(argument(3)),
583 reinterpret_cast<struct sockaddr_storage*
>(argument(4)),
584 static_cast<socklen_t
>(argument(5)));
585 POSIX_CASE(POSIX_GETTIMEOFDAY)
586 return posix_gettimeofday(
reinterpret_cast<struct timeval*
>(argument(0)),
587 reinterpret_cast<struct timezone*
>(argument(1)));
588 POSIX_CASE(POSIX_DUP)
589 return posix_dup(
static_cast<int>(argument(0)));
590 POSIX_CASE(POSIX_DUP2)
591 return posix_dup2(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)));
592 POSIX_CASE(POSIX_DUP3)
593 return posix_dup3(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
594 static_cast<int>(argument(2)));
595 POSIX_CASE(POSIX_LSTAT)
596 return posix_lstat(
reinterpret_cast<char*
>(argument(0)),
597 reinterpret_cast<struct stat*
>(argument(1)));
598 POSIX_CASE(POSIX_UNLINK)
599 return posix_unlink(
reinterpret_cast<char*
>(argument(0)));
600 POSIX_CASE(POSIX_SYMLINK)
601 return posix_symlink(
reinterpret_cast<char*
>(argument(0)),
602 reinterpret_cast<char*
>(argument(1)));
603 POSIX_CASE(POSIX_FCNTL)
604 return posix_fcntl(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
605 reinterpret_cast<void*
>(argument(2)));
606 POSIX_CASE(POSIX_PIPE)
607 return posix_pipe(
reinterpret_cast<int*
>(argument(0)));
608 POSIX_CASE(POSIX_PIPE2)
609 return posix_pipe2(
reinterpret_cast<int*
>(argument(0)),
static_cast<int>(argument(1)));
610 POSIX_CASE(POSIX_MKDIR)
611 return posix_mkdir(
reinterpret_cast<const char*
>(argument(0)),
static_cast<int>(argument(1)));
612 POSIX_CASE(POSIX_RMDIR)
613 return posix_rmdir(
reinterpret_cast<const char*
>(argument(0)));
615 return posix_getpwent(
reinterpret_cast<passwd*
>(argument(0)),
static_cast<int>(argument(1)),
616 reinterpret_cast<char*
>(argument(2)));
618 return posix_getpwnam(
reinterpret_cast<passwd*
>(argument(0)),
619 reinterpret_cast<const char*
>(argument(1)),
620 reinterpret_cast<char*
>(argument(2)));
621 POSIX_CASE(POSIX_GETUID)
622 return posix_getuid();
623 POSIX_CASE(POSIX_GETGID)
624 return posix_getgid();
625 POSIX_CASE(POSIX_SIGACTION)
628 if (argument(3) !=
sizeof(uint64_t)) {
629 SYSCALL_ERROR(InvalidArgument);
632 return posix_linux_armv7_sigaction(
633 static_cast<int>(argument(0)),
634 reinterpret_cast<const LinuxArmv7KernelSigaction*
>(argument(1)),
635 reinterpret_cast<LinuxArmv7KernelSigaction*
>(argument(2)));
640 if (argument(3) !=
sizeof(uint64_t)) {
641 SYSCALL_ERROR(InvalidArgument);
644 return posix_linux_amd64_sigaction(
645 static_cast<int>(argument(0)),
650 return posix_sigaction(
static_cast<int>(argument(0)),
651 reinterpret_cast<const struct sigaction*
>(argument(1)),
652 reinterpret_cast<struct sigaction*
>(argument(2)));
654 return posix_signal(
static_cast<int>(argument(0)),
reinterpret_cast<void*
>(argument(1)));
656 return posix_raise(
static_cast<int>(argument(0)));
657 POSIX_CASE(POSIX_KILL)
658 return posix_kill(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)));
659 POSIX_CASE(POSIX_TKILL)
660 return posix_tkill(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)), linuxAbi);
661 POSIX_CASE(POSIX_TGKILL)
662 return posix_tgkill(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
663 static_cast<int>(argument(2)), linuxAbi);
664 POSIX_CASE(POSIX_SIGPROCMASK)
665 return posix_sigprocmask(
static_cast<int>(argument(0)),
666 reinterpret_cast<const void*
>(argument(1)),
667 reinterpret_cast<void*
>(argument(2)), argument(3), linuxAbi);
668 POSIX_CASE(POSIX_RT_SIGSUSPEND)
669 return posix_rt_sigsuspend(
reinterpret_cast<const uint64_t*
>(argument(0)),
670 static_cast<size_t>(argument(1)));
671 POSIX_CASE(POSIX_ALARM)
672 return posix_alarm(argument(0));
674 return posix_sleep(argument(0));
675 POSIX_CASE(POSIX_POLL)
676 return posix_poll(
reinterpret_cast<pollfd*
>(argument(0)),
677 static_cast<unsigned int>(argument(1)),
static_cast<int>(argument(2)));
678 POSIX_CASE(POSIX_PPOLL)
680 reinterpret_cast<pollfd*
>(argument(0)),
static_cast<unsigned int>(argument(1)),
682 reinterpret_cast<const uint64_t*
>(argument(3)),
static_cast<size_t>(argument(4)));
683 POSIX_CASE(POSIX_PSELECT6)
684 return posix_pselect6(
static_cast<int>(argument(0)),
reinterpret_cast<fd_set*
>(argument(1)),
685 reinterpret_cast<fd_set*
>(argument(2)),
686 reinterpret_cast<fd_set*
>(argument(3)),
689 POSIX_CASE(POSIX_EPOLL_CREATE)
690 return posix_epoll_create(
static_cast<int>(argument(0)));
691 POSIX_CASE(POSIX_EPOLL_CREATE1)
692 return posix_epoll_create1(
static_cast<int>(argument(0)));
693 POSIX_CASE(POSIX_EPOLL_CTL)
694 return posix_epoll_ctl(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
695 static_cast<int>(argument(2)),
697 POSIX_CASE(POSIX_EPOLL_WAIT)
698 return posix_epoll_wait(
static_cast<int>(argument(0)),
700 static_cast<int>(argument(2)),
static_cast<int>(argument(3)));
701 POSIX_CASE(POSIX_EPOLL_PWAIT)
702 return posix_epoll_pwait(
703 static_cast<int>(argument(0)),
reinterpret_cast<LinuxEpollEvent*
>(argument(1)),
704 static_cast<int>(argument(2)),
static_cast<int>(argument(3)),
705 reinterpret_cast<const void*
>(argument(4)),
static_cast<size_t>(argument(5)));
706 POSIX_CASE(POSIX_EVENTFD)
707 return posix_eventfd(
static_cast<unsigned int>(argument(0)));
708 POSIX_CASE(POSIX_EVENTFD2)
709 return posix_eventfd2(
static_cast<unsigned int>(argument(0)),
static_cast<int>(argument(1)));
710 POSIX_CASE(POSIX_SHMGET)
711 return posix_shmget(
static_cast<int32_t
>(argument(0)), argument(1),
712 static_cast<int>(argument(2)));
713 POSIX_CASE(POSIX_SHMAT)
714 return reinterpret_cast<uintptr_t
>(posix_shmat(
static_cast<int>(argument(0)),
715 reinterpret_cast<const void*
>(argument(1)),
716 static_cast<int>(argument(2))));
717 POSIX_CASE(POSIX_SHMDT)
718 return posix_shmdt(
reinterpret_cast<const void*
>(argument(0)));
719 POSIX_CASE(POSIX_SHMCTL)
720 return posix_shmctl(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
721 reinterpret_cast<void*
>(argument(2)));
723 POSIX_CASE(POSIX_RT_SIGPENDING)
724 return posix_rt_sigpending(
reinterpret_cast<uint64_t*
>(argument(0)), argument(1));
725 POSIX_CASE(POSIX_RT_SIGTIMEDWAIT)
726 return posix_rt_sigtimedwait(
reinterpret_cast<const uint64_t*
>(argument(0)),
730 POSIX_CASE(POSIX_RT_SIGQUEUEINFO)
731 return posix_rt_sigqueueinfo(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
733 POSIX_CASE(POSIX_TIMER_CREATE)
734 return posix_timer_create(
static_cast<int>(argument(0)),
735 reinterpret_cast<const void*
>(argument(1)),
736 reinterpret_cast<int*
>(argument(2)));
737 POSIX_CASE(POSIX_TIMER_SETTIME)
738 return posix_timer_settime(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
739 reinterpret_cast<const void*
>(argument(2)),
740 reinterpret_cast<void*
>(argument(3)));
741 POSIX_CASE(POSIX_TIMER_GETTIME)
742 return posix_timer_gettime(
static_cast<int>(argument(0)),
743 reinterpret_cast<void*
>(argument(1)));
744 POSIX_CASE(POSIX_TIMER_GETOVERRUN)
745 return posix_timer_getoverrun(
static_cast<int>(argument(0)));
746 POSIX_CASE(POSIX_TIMER_DELETE)
747 return posix_timer_delete(
static_cast<int>(argument(0)));
748 POSIX_CASE(POSIX_CLOCK_SETTIME)
749 return posix_clock_settime(
static_cast<clockid_t
>(argument(0)),
751 POSIX_CASE(POSIX_SIGNALFD)
752 return posix_signalfd(
static_cast<int>(argument(0)),
753 reinterpret_cast<const uint64_t*
>(argument(1)), argument(2));
754 POSIX_CASE(POSIX_SIGNALFD4)
755 return posix_signalfd4(
static_cast<int>(argument(0)),
756 reinterpret_cast<const uint64_t*
>(argument(1)), argument(2),
757 static_cast<int>(argument(3)));
758 POSIX_CASE(POSIX_TIMERFD_CREATE)
759 return posix_timerfd_create(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)));
760 POSIX_CASE(POSIX_TIMERFD_SETTIME)
761 return posix_timerfd_settime(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
762 reinterpret_cast<const void*
>(argument(2)),
763 reinterpret_cast<void*
>(argument(3)));
764 POSIX_CASE(POSIX_TIMERFD_GETTIME)
765 return posix_timerfd_gettime(
static_cast<int>(argument(0)),
766 reinterpret_cast<void*
>(argument(1)));
768 POSIX_CASE(POSIX_SEMGET)
769 return posix_semget(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
770 static_cast<int>(argument(2)));
771 POSIX_CASE(POSIX_SEMOP)
772 return posix_semop(
static_cast<int>(argument(0)),
reinterpret_cast<const void*
>(argument(1)),
774 POSIX_CASE(POSIX_SEMCTL)
775 return posix_semctl(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
776 static_cast<int>(argument(2)), argument(3));
777 POSIX_CASE(POSIX_SEMTIMEDOP)
778 return posix_semtimedop(
static_cast<int>(argument(0)),
779 reinterpret_cast<const void*
>(argument(1)), argument(2),
780 reinterpret_cast<const void*
>(argument(3)));
781 POSIX_CASE(POSIX_MSGGET)
782 return posix_msgget(
static_cast<int32_t
>(argument(0)),
static_cast<int>(argument(1)));
783 POSIX_CASE(POSIX_MSGSND)
784 return posix_msgsnd(
static_cast<int>(argument(0)),
reinterpret_cast<const void*
>(argument(1)),
785 argument(2),
static_cast<int>(argument(3)));
786 POSIX_CASE(POSIX_MSGRCV)
787 return posix_msgrcv(
static_cast<int>(argument(0)),
reinterpret_cast<void*
>(argument(1)),
788 argument(2),
static_cast<int64_t
>(argument(3)),
789 static_cast<int>(argument(4)));
790 POSIX_CASE(POSIX_MSGCTL)
791 return posix_msgctl(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
792 reinterpret_cast<void*
>(argument(2)));
793 POSIX_CASE(POSIX_MQ_OPEN)
794 return posix_mq_open(
reinterpret_cast<const char*
>(argument(0)),
795 static_cast<int>(argument(1)),
static_cast<unsigned>(argument(2)),
796 reinterpret_cast<const LinuxMqAttr*
>(argument(3)));
797 POSIX_CASE(POSIX_MQ_UNLINK)
798 return posix_mq_unlink(
reinterpret_cast<const char*
>(argument(0)));
799 POSIX_CASE(POSIX_MQ_TIMEDSEND)
800 return posix_mq_timedsend(
static_cast<int>(argument(0)),
801 reinterpret_cast<const char*
>(argument(1)), argument(2),
802 static_cast<unsigned>(argument(3)),
804 POSIX_CASE(POSIX_MQ_TIMEDRECEIVE)
805 return posix_mq_timedreceive(
static_cast<int>(argument(0)),
806 reinterpret_cast<char*
>(argument(1)), argument(2),
807 reinterpret_cast<unsigned*
>(argument(3)),
809 POSIX_CASE(POSIX_MQ_NOTIFY)
810 return posix_mq_notify(
static_cast<int>(argument(0)),
812 POSIX_CASE(POSIX_MQ_GETSETATTR)
813 return posix_mq_getsetattr(
static_cast<int>(argument(0)),
817 POSIX_CASE(POSIX_INOTIFY_INIT)
818 return posix_inotify_init();
819 POSIX_CASE(POSIX_INOTIFY_INIT1)
820 return posix_inotify_init1(
static_cast<int>(argument(0)));
821 POSIX_CASE(POSIX_INOTIFY_ADD_WATCH)
822 return posix_inotify_add_watch(
static_cast<int>(argument(0)),
823 reinterpret_cast<const char*
>(argument(1)),
824 static_cast<uint32_t
>(argument(2)));
825 POSIX_CASE(POSIX_INOTIFY_RM_WATCH)
826 return posix_inotify_rm_watch(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)));
827 POSIX_CASE(POSIX_RENAME)
828 return posix_rename(
reinterpret_cast<const char*
>(argument(0)),
829 reinterpret_cast<const char*
>(argument(1)));
830 POSIX_CASE(POSIX_GETCWD)
831 return posix_getcwd(
reinterpret_cast<char*
>(argument(0)), argument(1));
832 POSIX_CASE(POSIX_READLINK)
833 return posix_readlink(
reinterpret_cast<const char*
>(argument(0)),
834 reinterpret_cast<char*
>(argument(1)),
835 static_cast<unsigned int>(argument(2)));
836 POSIX_CASE(POSIX_LINK)
837 return posix_link(
reinterpret_cast<char*
>(argument(0)),
reinterpret_cast<char*
>(argument(1)));
839 return posix_isatty(
static_cast<int>(argument(0)));
840 POSIX_CASE(POSIX_MMAP)
843 return reinterpret_cast<uintptr_t
>(posix_mmap(
844 reinterpret_cast<void*
>(argument(0)), argument(1),
static_cast<int>(argument(2)),
845 static_cast<int>(argument(3)),
static_cast<int>(argument(4)),
846 static_cast<off_t
>(uint64_t(argument(5)) * PAGE_SIZE)));
849 return reinterpret_cast<uintptr_t
>(
850 posix_mmap(
reinterpret_cast<void*
>(argument(0)), argument(1),
851 static_cast<int>(argument(2)),
static_cast<int>(argument(3)),
852 static_cast<int>(argument(4)),
static_cast<off_t
>(argument(5))));
853 POSIX_CASE(POSIX_MUNMAP)
854 return posix_munmap(
reinterpret_cast<void*
>(argument(0)), argument(1));
855 POSIX_CASE(POSIX_MREMAP)
856 return reinterpret_cast<uintptr_t
>(
857 posix_mremap(
reinterpret_cast<void*
>(argument(0)), argument(1), argument(2),
858 static_cast<int>(argument(3)),
reinterpret_cast<void*
>(argument(4))));
859 POSIX_CASE(POSIX_MINCORE)
860 return posix_mincore(
reinterpret_cast<void*
>(argument(0)), argument(1),
861 reinterpret_cast<unsigned char*
>(argument(2)));
862 POSIX_CASE(POSIX_MADVISE)
863 return posix_madvise(
reinterpret_cast<void*
>(argument(0)), argument(1),
864 static_cast<int>(argument(2)));
865 POSIX_CASE(POSIX_REMAP_FILE_PAGES)
866 return posix_remap_file_pages(
reinterpret_cast<void*
>(argument(0)), argument(1), argument(2),
867 argument(3), argument(4));
868 POSIX_CASE(POSIX_MLOCK)
869 return posix_mlock(
reinterpret_cast<const void*
>(argument(0)), argument(1), 0);
870 POSIX_CASE(POSIX_MLOCK2)
871 return posix_mlock(
reinterpret_cast<const void*
>(argument(0)), argument(1),
872 static_cast<unsigned int>(argument(2)));
873 POSIX_CASE(POSIX_MUNLOCK)
874 return posix_munlock(
reinterpret_cast<const void*
>(argument(0)), argument(1));
875 POSIX_CASE(POSIX_MLOCKALL)
876 return posix_mlockall(
static_cast<int>(argument(0)));
877 POSIX_CASE(POSIX_MUNLOCKALL)
878 return posix_munlockall();
879 POSIX_CASE(POSIX_MEMFD_CREATE)
880 return posix_memfd_create(
reinterpret_cast<const char*
>(argument(0)),
881 static_cast<unsigned int>(argument(1)));
882 POSIX_CASE(POSIX_SENDFILE)
883 return posix_sendfile(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
884 reinterpret_cast<int64_t*
>(argument(2)), argument(3));
885 POSIX_CASE(POSIX_COPY_FILE_RANGE)
886 return posix_copy_file_range(
887 static_cast<int>(argument(0)),
reinterpret_cast<int64_t*
>(argument(1)),
888 static_cast<int>(argument(2)),
reinterpret_cast<int64_t*
>(argument(3)), argument(4),
889 static_cast<unsigned int>(argument(5)));
890 POSIX_CASE(POSIX_SPLICE)
891 return posix_splice(
static_cast<int>(argument(0)),
reinterpret_cast<int64_t*
>(argument(1)),
892 static_cast<int>(argument(2)),
reinterpret_cast<int64_t*
>(argument(3)),
893 argument(4),
static_cast<unsigned int>(argument(5)));
894 POSIX_CASE(POSIX_TEE)
895 return posix_tee(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)), argument(2),
896 static_cast<unsigned int>(argument(3)));
897 POSIX_CASE(POSIX_VMSPLICE)
898 return posix_vmsplice(
static_cast<int>(argument(0)),
899 reinterpret_cast<const struct iovec*
>(argument(1)), argument(2),
900 static_cast<unsigned int>(argument(3)));
901 POSIX_CASE(POSIX_SHUTDOWN)
902 return posix_shutdown(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)));
903 POSIX_CASE(POSIX_ACCESS)
904 return posix_access(
reinterpret_cast<const char*
>(argument(0)),
905 static_cast<int>(argument(1)));
906 POSIX_CASE(POSIX_SETSID)
907 return posix_setsid();
908 POSIX_CASE(POSIX_SETPGID)
909 return posix_setpgid(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)));
910 POSIX_CASE(POSIX_GETPGID)
911 return posix_getpgid(
static_cast<int>(argument(0)));
912 POSIX_CASE(POSIX_GETPGRP)
913 return posix_getpgrp();
914 POSIX_CASE(POSIX_SIGALTSTACK)
915 return posix_sigaltstack(
reinterpret_cast<const stack_t*
>(argument(0)),
916 reinterpret_cast<stack_t*
>(argument(1)));
919 return posix_syslog(
reinterpret_cast<const char*
>(argument(0)),
920 static_cast<int>(argument(1)));
922 POSIX_CASE(POSIX_FTRUNCATE)
923 return posix_ftruncate(
static_cast<int>(argument(0)),
static_cast<off_t
>(argument(1)));
931 static char buf[128];
932 StringCopyN(buf,
reinterpret_cast<char*
>(argument(0)), 128);
933 WARNING(
"Using stubbed function '" << buf <<
"'");
937 POSIX_CASE(PEDIGREE_SIGRET)
940 LinuxAmd64Signal::sigreturn(state);
944 return pedigree_sigret();
945 case PEDIGREE_INIT_SIGRET:
946 WARNING(
"POSIX: The 'init sigret' system call is no longer valid.");
949 POSIX_CASE(POSIX_SCHED_YIELD)
953 POSIX_CASE(POSIX_NANOSLEEP)
954 return posix_nanosleep(
reinterpret_cast<struct timespec*
>(argument(0)),
955 reinterpret_cast<struct timespec*
>(argument(1)),
956 linuxAbi &&
sizeof(uintptr_t) ==
sizeof(uint32_t));
957 POSIX_CASE(POSIX_CLOCK_GETTIME)
958 return posix_clock_gettime(argument(0),
reinterpret_cast<struct timespec*
>(argument(1)));
959 POSIX_CASE(POSIX_CLOCK_GETRES)
961 return posix_clock_getres(argument(0),
reinterpret_cast<LinuxKernelTimespec*
>(argument(1)));
963 return posix_clock_getres_native(argument(0),
964 reinterpret_cast<struct timespec*
>(argument(1)));
965 POSIX_CASE(POSIX_CLOCK_NANOSLEEP)
966 return posix_clock_nanosleep(argument(0),
static_cast<int>(argument(1)),
970 POSIX_CASE(POSIX_GETEUID)
971 return posix_geteuid();
972 POSIX_CASE(POSIX_GETEGID)
973 return posix_getegid();
975 return posix_seteuid(
static_cast<uid_t
>(argument(0)));
977 return posix_setegid(
static_cast<gid_t
>(argument(0)));
978 POSIX_CASE(POSIX_SETUID)
979 return posix_setuid(
static_cast<uid_t
>(argument(0)));
980 POSIX_CASE(POSIX_SETGID)
981 return posix_setgid(
static_cast<gid_t
>(argument(0)));
983 POSIX_CASE(POSIX_CHOWN)
984 return posix_chown(
reinterpret_cast<const char*
>(argument(0)),
985 static_cast<uid_t
>(argument(1)),
static_cast<gid_t
>(argument(2)));
986 POSIX_CASE(POSIX_CHMOD)
987 return posix_chmod(
reinterpret_cast<const char*
>(argument(0)),
988 static_cast<mode_t
>(argument(1)));
989 POSIX_CASE(POSIX_FCHOWN)
990 return posix_fchown(
static_cast<int>(argument(0)),
static_cast<uid_t
>(argument(1)),
991 static_cast<gid_t
>(argument(2)));
992 POSIX_CASE(POSIX_FCHMOD)
993 return posix_fchmod(
static_cast<int>(argument(0)),
static_cast<mode_t
>(argument(1)));
994 POSIX_CASE(POSIX_FCHDIR)
995 return posix_fchdir(
static_cast<int>(argument(0)));
998 return posix_statvfs(
reinterpret_cast<const char*
>(argument(0)),
999 reinterpret_cast<struct statvfs*
>(argument(1)));
1000 case POSIX_FSTATVFS:
1001 return posix_fstatvfs(
static_cast<int>(argument(0)),
1002 reinterpret_cast<struct statvfs*
>(argument(1)));
1004 case PEDIGREE_UNWIND_SIGNAL:
1005 return pedigree_unwind_signal();
1007 POSIX_CASE(POSIX_MSYNC)
1008 return posix_msync(
reinterpret_cast<void*
>(argument(0)), argument(1),
1009 static_cast<int>(argument(2)));
1010 POSIX_CASE(POSIX_GETPEERNAME)
1011 return posix_getpeername(
static_cast<int>(argument(0)),
1012 reinterpret_cast<struct sockaddr_storage*
>(argument(1)),
1013 reinterpret_cast<socklen_t*
>(argument(2)));
1014 POSIX_CASE(POSIX_GETSOCKNAME)
1015 return posix_getsockname(
static_cast<int>(argument(0)),
1016 reinterpret_cast<struct sockaddr_storage*
>(argument(1)),
1017 reinterpret_cast<socklen_t*
>(argument(2)));
1018 POSIX_CASE(POSIX_FSYNC)
1019 return posix_fsync(
static_cast<int>(argument(0)));
1022 return console_ptsname(
static_cast<int>(argument(0)),
reinterpret_cast<char*
>(argument(1)));
1023 POSIX_CASE(POSIX_TTYNAME)
1024 return console_ttyname(
static_cast<int>(argument(0)),
reinterpret_cast<char*
>(argument(1)));
1025 case POSIX_TCGETPGRP:
1026 return posix_tcgetpgrp(
static_cast<int>(argument(0)));
1027 case POSIX_TCSETPGRP:
1028 return posix_tcsetpgrp(
static_cast<int>(argument(0)),
static_cast<pid_t
>(argument(1)));
1031 return posix_usleep(argument(0));
1033 POSIX_CASE(POSIX_MPROTECT)
1034 return posix_mprotect(
reinterpret_cast<void*
>(argument(0)), argument(1),
1035 static_cast<int>(argument(2)));
1037 case POSIX_REALPATH:
1038 return posix_realpath(
reinterpret_cast<const char*
>(argument(0)),
1039 reinterpret_cast<char*
>(argument(1)), argument(2));
1040 POSIX_CASE(POSIX_TIMES)
1041 return posix_times(
reinterpret_cast<struct tms*
>(argument(0)));
1042 POSIX_CASE(POSIX_GETRUSAGE)
1044 return posix_linux_getrusage(argument(0),
reinterpret_cast<LinuxRusage64*
>(argument(1)));
1046 return posix_getrusage(argument(0),
reinterpret_cast<struct rusage*
>(argument(1)));
1047 POSIX_CASE(POSIX_SETSOCKOPT)
1048 return posix_setsockopt(argument(0), argument(1), argument(2),
1049 reinterpret_cast<const void*
>(argument(3)), argument(4));
1050 POSIX_CASE(POSIX_GETSOCKOPT)
1051 return posix_getsockopt(argument(0), argument(1), argument(2),
1052 reinterpret_cast<void*
>(argument(3)),
1053 reinterpret_cast<socklen_t*
>(argument(4)));
1054 POSIX_CASE(POSIX_GETPPID)
1055 return posix_getppid();
1056 POSIX_CASE(POSIX_UTIME)
1057 return posix_utime(
reinterpret_cast<const char*
>(argument(0)),
1058 reinterpret_cast<const struct utimbuf*
>(argument(1)));
1059 POSIX_CASE(POSIX_UTIMES)
1060 return posix_utimes(
reinterpret_cast<const char*
>(argument(0)),
1061 reinterpret_cast<const struct timeval*
>(argument(1)));
1062 POSIX_CASE(POSIX_CHROOT)
1063 return posix_chroot(
reinterpret_cast<const char*
>(argument(0)));
1065 case POSIX_GETGRNAM:
1066 return posix_getgrnam(
reinterpret_cast<const char*
>(argument(0)),
1067 reinterpret_cast<struct group*
>(argument(1)));
1068 case POSIX_GETGRGID:
1069 return posix_getgrgid(
static_cast<gid_t
>(argument(0)),
1070 reinterpret_cast<struct group*
>(argument(1)));
1071 POSIX_CASE(POSIX_UMASK)
1072 return posix_umask(
static_cast<mode_t
>(argument(0)));
1073 POSIX_CASE(POSIX_WRITEV)
1074 return posix_writev(
static_cast<int>(argument(0)),
1075 reinterpret_cast<const struct iovec*
>(argument(1)), argument(2));
1076 POSIX_CASE(POSIX_READV)
1077 return posix_readv(
static_cast<int>(argument(0)),
1078 reinterpret_cast<const struct iovec*
>(argument(1)), argument(2));
1079 POSIX_CASE(POSIX_GETDENTS)
1080 return posix_getdents(
static_cast<int>(argument(0)),
1082 static_cast<int>(argument(2)));
1083 POSIX_CASE(POSIX_GETTID)
1084 return posix_gettid(linuxAbi);
1085 POSIX_CASE(POSIX_SET_TID_ADDRESS)
1086 return posix_set_tid_address(
reinterpret_cast<int*
>(argument(0)), linuxAbi);
1087 POSIX_CASE(POSIX_BRK)
1088 return posix_brk(argument(0));
1090 case POSIX_PEDIGREE_CREATE_WAITER:
1091 return reinterpret_cast<uintptr_t
>(posix_pedigree_create_waiter());
1092 case POSIX_PEDIGREE_DESTROY_WAITER:
1093 posix_pedigree_destroy_waiter(
reinterpret_cast<void*
>(argument(0)));
1095 case POSIX_PEDIGREE_THREAD_WAIT_FOR:
1096 return posix_pedigree_thread_wait_for(
reinterpret_cast<void*
>(argument(0)));
1097 case POSIX_PEDIGREE_THREAD_TRIGGER:
1098 return posix_pedigree_thread_trigger(
reinterpret_cast<void*
>(argument(0)));
1100 case POSIX_PEDIGREE_GET_INFO_BLOCK:
1103 POSIX_CASE(POSIX_SET_TLS_AREA) {
1104 const uintptr_t p1 = argument(0);
1106 SYSCALL_ERROR(BadAddress);
1111 auto metadata = state.getUserEntryMetadata();
1112 metadata.fsBase = p1;
1113 state.setUserEntryMetadata(metadata);
1118 POSIX_CASE(POSIX_FUTEX)
1119 return posix_futex(
reinterpret_cast<int*
>(argument(0)),
static_cast<int>(argument(1)),
1120 static_cast<int>(argument(2)), argument(3),
1121 reinterpret_cast<int*
>(argument(4)),
static_cast<int>(argument(5)));
1122 POSIX_CASE(POSIX_UNAME)
1123 return posix_uname(
reinterpret_cast<struct utsname*
>(argument(0)));
1124 POSIX_CASE(POSIX_ARCH_PRCTL) {
1125 const uintptr_t p1 = argument(0);
1126 const uintptr_t p2 = argument(1);
1127 const int result = posix_arch_prctl(p1, p2);
1129 if (!result && (
static_cast<int>(p1) == 0x1002 ||
static_cast<int>(p1) == 0x1001)) {
1131 auto metadata = state.getUserEntryMetadata();
1132 if (
static_cast<int>(p1) == 0x1002)
1133 metadata.fsBase = p2;
1135 metadata.gsBase = p2;
1136 state.setUserEntryMetadata(metadata);
1141 POSIX_CASE(POSIX_CLONE) {
1144 return posix_clone(state, argument(0),
reinterpret_cast<void*
>(argument(1)),
1145 reinterpret_cast<int*
>(argument(2)),
reinterpret_cast<int*
>(argument(4)),
1146 argument(3), linuxAbi);
1148 return posix_clone(state, argument(0),
reinterpret_cast<void*
>(argument(1)),
1149 reinterpret_cast<int*
>(argument(2)),
reinterpret_cast<int*
>(argument(3)),
1150 argument(4), linuxAbi);
1153 POSIX_CASE(POSIX_CLONE3)
1154 return posix_clone3(state,
reinterpret_cast<const LinuxCloneArgs*
>(argument(0)), argument(1));
1155 POSIX_CASE(POSIX_PAUSE)
1156 return posix_pause();
1157 POSIX_CASE(POSIX_GETDENTS64)
1158 return posix_getdents64(
static_cast<int>(argument(0)),
1159 reinterpret_cast<struct dirent*
>(argument(1)),
1160 static_cast<int>(argument(2)));
1161 POSIX_CASE(POSIX_L_SYSLOG)
1162 return posix_linux_syslog(argument(0),
reinterpret_cast<char*
>(argument(1)), argument(2));
1163 POSIX_CASE(POSIX_FLOCK)
1164 return posix_flock(argument(0), argument(1));
1165 POSIX_CASE(POSIX_OPENAT)
1166 return posix_openat(argument(0),
reinterpret_cast<const char*
>(argument(1)), argument(2),
1168 POSIX_CASE(POSIX_MKDIRAT)
1169 return posix_mkdirat(argument(0),
reinterpret_cast<const char*
>(argument(1)), argument(2));
1170 POSIX_CASE(POSIX_FCHOWNAT)
1171 return posix_fchownat(argument(0),
reinterpret_cast<const char*
>(argument(1)), argument(2),
1172 argument(3), argument(4));
1173 POSIX_CASE(POSIX_FUTIMESAT)
1174 return posix_futimesat(argument(0),
reinterpret_cast<const char*
>(argument(1)),
1175 reinterpret_cast<struct timeval*
>(argument(2)));
1176 POSIX_CASE(POSIX_UNLINKAT)
1177 return posix_unlinkat(argument(0),
reinterpret_cast<const char*
>(argument(1)), argument(2));
1178 POSIX_CASE(POSIX_RENAMEAT)
1179 return posix_renameat(argument(0),
reinterpret_cast<const char*
>(argument(1)), argument(2),
1180 reinterpret_cast<const char*
>(argument(3)));
1181 POSIX_CASE(POSIX_LINKAT)
1182 return posix_linkat(argument(0),
reinterpret_cast<const char*
>(argument(1)), argument(2),
1183 reinterpret_cast<const char*
>(argument(3)), argument(4));
1184 POSIX_CASE(POSIX_SYMLINKAT)
1185 return posix_symlinkat(
reinterpret_cast<const char*
>(argument(0)), argument(1),
1186 reinterpret_cast<const char*
>(argument(2)));
1187 POSIX_CASE(POSIX_READLINKAT)
1188 return posix_readlinkat(argument(0),
reinterpret_cast<const char*
>(argument(1)),
1189 reinterpret_cast<char*
>(argument(2)), argument(3));
1190 POSIX_CASE(POSIX_FCHMODAT)
1191 return posix_fchmodat(argument(0),
reinterpret_cast<const char*
>(argument(1)), argument(2),
1192 linuxAbi ? 0 : argument(3));
1193 POSIX_CASE(POSIX_FACCESSAT)
1194 return posix_faccessat(argument(0),
reinterpret_cast<const char*
>(argument(1)), argument(2),
1196 POSIX_CASE(POSIX_FACCESSAT2)
1197 return posix_faccessat(argument(0),
reinterpret_cast<const char*
>(argument(1)), argument(2),
1199 POSIX_CASE(POSIX_FSTATAT)
1200 return posix_fstatat(argument(0),
reinterpret_cast<const char*
>(argument(1)),
1201 reinterpret_cast<struct stat*
>(argument(2)), argument(3));
1202 POSIX_CASE(POSIX_SETGROUPS)
1203 return posix_setgroups(argument(0),
reinterpret_cast<const gid_t*
>(argument(1)));
1204 POSIX_CASE(POSIX_GETRLIMIT)
1205 return posix_getrlimit(argument(0),
reinterpret_cast<struct rlimit*
>(argument(1)));
1206 POSIX_CASE(POSIX_GETPRIORITY)
1207 return posix_getpriority(argument(0), argument(1), linuxAbi);
1208 POSIX_CASE(POSIX_SETPRIORITY)
1209 return posix_setpriority(argument(0), argument(1), argument(2));
1210 POSIX_CASE(POSIX_SETXATTR)
1211 return posix_setxattr(
reinterpret_cast<const char*
>(argument(0)),
1212 reinterpret_cast<const char*
>(argument(1)),
1213 reinterpret_cast<const void*
>(argument(2)), argument(3), argument(4));
1214 POSIX_CASE(POSIX_LSETXATTR)
1215 return posix_lsetxattr(
reinterpret_cast<const char*
>(argument(0)),
1216 reinterpret_cast<const char*
>(argument(1)),
1217 reinterpret_cast<const void*
>(argument(2)), argument(3), argument(4));
1218 POSIX_CASE(POSIX_FSETXATTR)
1219 return posix_fsetxattr(argument(0),
reinterpret_cast<const char*
>(argument(1)),
1220 reinterpret_cast<const void*
>(argument(2)), argument(3), argument(4));
1221 POSIX_CASE(POSIX_GETXATTR)
1222 return posix_getxattr(
reinterpret_cast<const char*
>(argument(0)),
1223 reinterpret_cast<const char*
>(argument(1)),
1224 reinterpret_cast<void*
>(argument(2)), argument(3));
1225 POSIX_CASE(POSIX_LGETXATTR)
1226 return posix_lgetxattr(
reinterpret_cast<const char*
>(argument(0)),
1227 reinterpret_cast<const char*
>(argument(1)),
1228 reinterpret_cast<void*
>(argument(2)), argument(3));
1229 POSIX_CASE(POSIX_FGETXATTR)
1230 return posix_fgetxattr(argument(0),
reinterpret_cast<const char*
>(argument(1)),
1231 reinterpret_cast<void*
>(argument(2)), argument(3));
1232 POSIX_CASE(POSIX_LISTXATTR)
1233 return posix_listxattr(
reinterpret_cast<const char*
>(argument(0)),
1234 reinterpret_cast<char*
>(argument(1)), argument(2));
1235 POSIX_CASE(POSIX_LLISTXATTR)
1236 return posix_llistxattr(
reinterpret_cast<const char*
>(argument(0)),
1237 reinterpret_cast<char*
>(argument(1)), argument(2));
1238 POSIX_CASE(POSIX_FLISTXATTR)
1239 return posix_flistxattr(argument(0),
reinterpret_cast<char*
>(argument(1)), argument(2));
1240 POSIX_CASE(POSIX_REMOVEXATTR)
1241 return posix_removexattr(
reinterpret_cast<const char*
>(argument(0)),
1242 reinterpret_cast<const char*
>(argument(1)));
1243 POSIX_CASE(POSIX_LREMOVEXATTR)
1244 return posix_lremovexattr(
reinterpret_cast<const char*
>(argument(0)),
1245 reinterpret_cast<const char*
>(argument(1)));
1246 POSIX_CASE(POSIX_FANOTIFY_INIT)
1247 return posix_fanotify_init(argument(0), argument(1));
1248 POSIX_CASE(POSIX_FANOTIFY_MARK)
1249 return posix_fanotify_mark(argument(0), argument(1), argument(2), argument(3),
1250 reinterpret_cast<const char*
>(argument(4)));
1251 POSIX_CASE(POSIX_NAME_TO_HANDLE_AT)
1252 return posix_name_to_handle_at(argument(0),
reinterpret_cast<const char*
>(argument(1)),
1253 reinterpret_cast<void*
>(argument(2)),
1254 reinterpret_cast<int*
>(argument(3)), argument(4));
1255 POSIX_CASE(POSIX_OPEN_BY_HANDLE_AT)
1256 return posix_open_by_handle_at(argument(0),
reinterpret_cast<const void*
>(argument(1)),
1258 POSIX_CASE(POSIX_SETFSUID)
1259 return posix_setfsuid(argument(0));
1260 POSIX_CASE(POSIX_SETFSGID)
1261 return posix_setfsgid(argument(0));
1262 POSIX_CASE(POSIX_PROCESS_VM_READV)
1263 return posix_process_vm_readv(argument(0),
reinterpret_cast<const iovec*
>(argument(1)),
1264 argument(2),
reinterpret_cast<const iovec*
>(argument(3)),
1265 argument(4), argument(5));
1266 POSIX_CASE(POSIX_PROCESS_VM_WRITEV)
1267 return posix_process_vm_writev(argument(0),
reinterpret_cast<const iovec*
>(argument(1)),
1268 argument(2),
reinterpret_cast<const iovec*
>(argument(3)),
1269 argument(4), argument(5));
1270 POSIX_CASE(POSIX_FREMOVEXATTR)
1271 return posix_fremovexattr(argument(0),
reinterpret_cast<const char*
>(argument(1)));
1272 POSIX_CASE(POSIX_MKNOD)
1273 return posix_mknod(
reinterpret_cast<const char*
>(argument(0)), argument(1), argument(2));
1274 POSIX_CASE(POSIX_SETREUID)
1275 return posix_setreuid(argument(0), argument(1));
1276 POSIX_CASE(POSIX_SETREGID)
1277 return posix_setregid(argument(0), argument(1));
1278 POSIX_CASE(POSIX_SETRESUID)
1279 return posix_setresuid(argument(0), argument(1), argument(2));
1280 POSIX_CASE(POSIX_SETRESGID)
1281 return posix_setresgid(argument(0), argument(1), argument(2));
1282 POSIX_CASE(POSIX_GETRESUID)
1283 return posix_getresuid(
reinterpret_cast<uid_t*
>(argument(0)),
1284 reinterpret_cast<uid_t*
>(argument(1)),
1285 reinterpret_cast<uid_t*
>(argument(2)));
1286 POSIX_CASE(POSIX_GETRESGID)
1287 return posix_getresgid(
reinterpret_cast<gid_t*
>(argument(0)),
1288 reinterpret_cast<gid_t*
>(argument(1)),
1289 reinterpret_cast<gid_t*
>(argument(2)));
1290 POSIX_CASE(POSIX_STATFS)
1291 return posix_statfs(
reinterpret_cast<const char*
>(argument(0)),
1292 reinterpret_cast<struct statfs*
>(argument(1)));
1293 POSIX_CASE(POSIX_FSTATFS)
1294 return posix_fstatfs(argument(0),
reinterpret_cast<struct statfs*
>(argument(1)));
1295 POSIX_CASE(POSIX_UNSHARE)
1296 return posix_unshare(argument(0));
1297 POSIX_CASE(POSIX_SETNS)
1298 return posix_setns(argument(0), argument(1));
1299 POSIX_CASE(POSIX_SETDOMAINNAME)
1300 return posix_setdomainname(
reinterpret_cast<const char*
>(argument(0)), argument(1));
1301 POSIX_CASE(POSIX_SCHED_SETPARAM)
1302 return posix_sched_setparam(argument(0),
reinterpret_cast<const void*
>(argument(1)));
1303 POSIX_CASE(POSIX_SCHED_GETPARAM)
1304 return posix_sched_getparam(argument(0),
reinterpret_cast<void*
>(argument(1)));
1305 POSIX_CASE(POSIX_SCHED_SETSCHEDULER)
1306 return posix_sched_setscheduler(argument(0), argument(1),
1307 reinterpret_cast<const void*
>(argument(2)));
1308 POSIX_CASE(POSIX_SCHED_GETSCHEDULER)
1309 return posix_sched_getscheduler(argument(0));
1310 POSIX_CASE(POSIX_SCHED_GET_PRIORITY_MAX)
1311 return posix_sched_get_priority_max(argument(0));
1312 POSIX_CASE(POSIX_SCHED_GET_PRIORITY_MIN)
1313 return posix_sched_get_priority_min(argument(0));
1314 POSIX_CASE(POSIX_SCHED_RR_GET_INTERVAL)
1315 return posix_sched_rr_get_interval(argument(0),
reinterpret_cast<void*
>(argument(1)));
1316 POSIX_CASE(POSIX_SCHED_SETAFFINITY)
1317 return posix_sched_setaffinity(argument(0), argument(1),
1318 reinterpret_cast<const void*
>(argument(2)));
1319 POSIX_CASE(POSIX_SCHED_GETAFFINITY)
1320 return posix_sched_getaffinity(argument(0), argument(1),
1321 reinterpret_cast<void*
>(argument(2)));
1322 POSIX_CASE(POSIX_GETCPU)
1323 return posix_getcpu(
reinterpret_cast<unsigned int*
>(argument(0)),
1324 reinterpret_cast<unsigned int*
>(argument(1)));
1325 POSIX_CASE(POSIX_SETHOSTNAME)
1326 return posix_sethostname(
reinterpret_cast<const char*
>(argument(0)), argument(1));
1327 POSIX_CASE(POSIX_IOPERM)
1328 return posix_ioperm(argument(0), argument(1), argument(2));
1329 POSIX_CASE(POSIX_IOPL)
1330 return posix_iopl(argument(0));
1331 POSIX_CASE(POSIX_CREAT)
1332 return posix_open(
reinterpret_cast<const char*
>(argument(0)), O_WRONLY | O_CREAT | O_TRUNC,
1334 POSIX_CASE(POSIX_SET_ROBUST_LIST)
1335 return posix_set_robust_list(
reinterpret_cast<struct robust_list_head*
>(argument(0)),
1336 argument(1), linuxAbi);
1337 POSIX_CASE(POSIX_GET_ROBUST_LIST)
1338 return posix_get_robust_list(argument(0),
1339 reinterpret_cast<struct robust_list_head**
>(argument(1)),
1340 reinterpret_cast<size_t*
>(argument(2)), linuxAbi);
1341 POSIX_CASE(POSIX_GETGROUPS)
1342 return posix_getgroups(argument(0),
reinterpret_cast<gid_t*
>(argument(1)));
1343 POSIX_CASE(POSIX_MOUNT) {
1344 return posix_mount(
reinterpret_cast<const char*
>(argument(0)),
1345 reinterpret_cast<const char*
>(argument(1)),
1346 reinterpret_cast<const char*
>(argument(2)), argument(3),
1347 reinterpret_cast<const void*
>(argument(4)));
1349 POSIX_CASE(POSIX_UMOUNT2)
1350 return posix_umount2(
reinterpret_cast<const char*
>(argument(0)),
1351 static_cast<int>(argument(1)));
1352 POSIX_CASE(POSIX_SETTIMEOFDAY)
1353 return posix_settimeofday(
reinterpret_cast<const struct timeval*
>(argument(0)),
1354 reinterpret_cast<const struct timezone*
>(argument(1)));
1355 POSIX_CASE(POSIX_SETRLIMIT)
1356 return posix_setrlimit(argument(0),
reinterpret_cast<const struct rlimit*
>(argument(1)));
1357 POSIX_CASE(POSIX_PRLIMIT64)
1358 return posix_prlimit64(
static_cast<int>(argument(0)),
static_cast<int>(argument(1)),
1361 POSIX_CASE(POSIX_MEMBARRIER)
1362 return posix_membarrier(
static_cast<int>(argument(0)),
static_cast<unsigned int>(argument(1)),
1363 static_cast<int>(argument(2)));
1364 POSIX_CASE(POSIX_TIME)
1365 return posix_time(
reinterpret_cast<time_t*
>(argument(0)));
1366 POSIX_CASE(POSIX_GETITIMER)
1367 return posix_getitimer(argument(0),
reinterpret_cast<struct itimerval*
>(argument(1)));
1368 POSIX_CASE(POSIX_SETITIMER)
1369 return posix_setitimer(argument(0),
reinterpret_cast<const struct itimerval*
>(argument(1)),
1370 reinterpret_cast<struct itimerval*
>(argument(2)));
1371 POSIX_CASE(POSIX_SOCKETPAIR)
1372 return posix_socketpair(argument(0), argument(1), argument(2),
1373 reinterpret_cast<int*
>(argument(3)));
1374 POSIX_CASE(POSIX_SENDMSG)
1375 return posix_sendmsg(argument(0),
reinterpret_cast<const struct msghdr*
>(argument(1)),
1377 POSIX_CASE(POSIX_RECVMSG)
1378 return posix_recvmsg(argument(0),
reinterpret_cast<struct msghdr*
>(argument(1)), argument(2));
1379 POSIX_CASE(POSIX_CAPGET)
1380 return posix_capget(
reinterpret_cast<void*
>(argument(0)),
1381 reinterpret_cast<void*
>(argument(1)));
1382 POSIX_CASE(POSIX_CAPSET)
1383 return posix_capset(
reinterpret_cast<void*
>(argument(0)),
1384 reinterpret_cast<const void*
>(argument(1)));
1385 POSIX_CASE(POSIX_PRCTL)
1386 return posix_prctl(argument(0), argument(1), argument(2), argument(3), argument(4));
1387 POSIX_CASE(POSIX_REBOOT)
1388 return linuxAbi ? posix_reboot(argument(0), argument(1), argument(2)) : pedigree_reboot();
1389 POSIX_CASE(POSIX_GETRANDOM)
1390 return posix_getrandom(
reinterpret_cast<void*
>(argument(0)),
static_cast<size_t>(argument(1)),
1391 static_cast<unsigned int>(argument(2)));
1394 ERROR(
"PosixSyscallManager: invalid syscall received: " <<
Dec << syscallNumber <<
Hex);
1395 SYSCALL_ERROR(Unimplemented);
static bool copyToUser(void *destination, const void *source, size_t count, size_t elementSize=1)
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)
virtual uintptr_t syscall(SyscallState &state)
virtual ~PosixSyscallManager()
static ProcessorInformation & information()
static Scheduler & instance()
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
virtual bool registerSyscallHandler(Service_t Service, SyscallHandler *pHandler, Registration ®istration, FastEntry entry=nullptr)=0
static EXPORTED_PUBLIC SyscallManager & instance()
EXPORTED_PUBLIC bool requestThreadExit()
void setErrno(size_t err)
Process * getParent() const
virtual uintptr_t getGlobalInfoBlock() const
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()