x86-64 syscalls
A program here runs as a Linux program, so everything outside its own memory happens through syscall. Put the call number in rax, the arguments in rdi, rsi, rdx, r10, r8 and r9, and read the result from rax. A result between -1 and -4095 is
an error code. rcx and r11 do not survive the call.
The ones to start with
1 - write waits
Writes rdx bytes from the buffer at rsi to the file descriptor in rdi, and returns how many it wrote. Descriptor 1 is standard output and 2 is standard error, so this is how a program prints.
0 - read waits
Reads up to rdx bytes from the file descriptor in rdi into the buffer at rsi, and returns how many it read. Descriptor 0 is standard input, so this is how a program reads what was typed. A return of 0 means end of input.
60 - exit
Ends the program with the status in rdi. It never returns, and a program that reaches the end of its code without calling it runs into whatever bytes follow.
231 - exit_group
Ends every thread of the program with the status in rdi. For a program with one thread it is exit.
2 - open waits
Opens the path at rdi with the flags in rsi and, when creating, the mode in rdx. Returns a file descriptor.
3 - close waits
Closes the file descriptor in rdi.
8 - lseek
Moves the read and write position of the descriptor in rdi to the offset in rsi, interpreted according to rdx, and returns the new position.
5 - fstat
Fills the structure at rsi with what is known about the descriptor in rdi, including its size.
12 - brk
Moves the end of the data segment to the address in rdi, which is the oldest way to ask for more memory. Called with 0 it returns where the segment currently ends.
9 - mmap
Maps memory: the length in rsi, the protection in rdx, the flags in r10. An anonymous private mapping is how a program asks for a block of memory it can write to.
11 - munmap
Unmaps the mapping of rsi bytes at the address in rdi.
35 - nanosleep waits
Sleeps for the interval at rdi, a pair of seconds and nanoseconds.
228 - clock_gettime
Writes the time of the clock named in rdi into the structure at rsi.
39 - getpid
Returns the process id.
Everything this emulator implements
Those syscalls are what the emulator implements, anything missing returns -ENOSYS.
| rax | Call | Arguments |
|---|---|---|
| 4 | stat | rdi pathrsi o_stat |
| 6 | lstat | rdi pathrsi o_stat |
| 7 | poll | rdi valuersi valuerdx value |
| 10 | mprotect | rdi pointerrsi sizerdx protection flags |
| 13 | rt_sigaction | rdi signalrsi i_handrdx o_handr10 byte count |
| 14 | rt_sigprocmask | rdi sighowrsi i_sigsetrdx o_sigsetr10 byte count |
| 16 | ioctl | rdi valuersi valuerdx value |
| 17 | pread | rdi file descriptorrsi buffer (written by the kernel)rdx byte countr10 offset |
| 18 | pwrite | rdi file descriptorrsi buffer (read by the kernel)rdx byte countr10 offset |
| 19 | readv | rdi file descriptorrsi iovec array (written)rdx byte count |
| 20 | writev | rdi file descriptorrsi iovec array (read)rdx byte count |
| 21 | access | rdi pathrsi accmode |
| 22 | pipe | rdi o_pfds |
| 23 | select | rdi intrsi io_fdsetrdx io_fdsetr10 io_fdsetr8 io_timev |
| 24 | sched_yield | |
| 25 | mremap | rdi valuersi valuerdx valuer10 valuer8 value |
| 26 | msync | rdi valuersi valuerdx value |
| 28 | madvise | rdi valuersi valuerdx value |
| 32 | dup | rdi file descriptor |
| 33 | dup2 | rdi file descriptorrsi int |
| 34 | pause | |
| 36 | getitimer | rdi valuersi value |
| 37 | alarm | rdi int |
| 38 | setitimer | rdi valuersi valuerdx value |
| 40 | sendfile | rdi valuersi valuerdx valuer10 value |
| 41 | socket | rdi familyrsi socktyperdx int |
| 42 | connect | rdi file descriptorrsi i_addrrdx addrlen |
| 43 | accept | rdi file descriptorrsi o_addrrdx long |
| 44 | sendto | rdi file descriptorrsi buffer (read by the kernel)rdx sizer10 intr8 i_addrr9 addrlen |
| 45 | recvfrom | rdi file descriptorrsi buffer (written by the kernel)rdx sizer10 intr8 o_addrr9 long |
| 46 | sendmsg | rdi valuersi valuerdx value |
| 47 | recvmsg | rdi valuersi valuerdx value |
| 48 | shutdown | rdi valuersi value |
| 49 | bind | rdi file descriptorrsi i_addrrdx addrlen |
| 50 | listen | rdi file descriptorrsi un |
| 51 | getsockname | rdi file descriptorrsi o_addrrdx long |
| 52 | getpeername | rdi file descriptorrsi o_addrrdx long |
| 53 | socketpair | rdi familyrsi socktyperdx intr10 o_pfds |
| 54 | setsockopt | rdi valuersi valuerdx valuer10 valuer8 value |
| 55 | getsockopt | rdi valuersi valuerdx valuer10 valuer8 value |
| 56 | clone | rdi cloneflagsrsi pointerrdx pointerr10 pointerr8 pointerr9 pointer |
| 57 | fork | |
| 58 | vfork | |
| 59 | execve | rdi valuersi valuerdx value |
| 61 | wait4 | rdi process idrsi o_wstatusrdx waitflagsr10 o_rusage |
| 62 | kill | rdi process idrsi signal |
| 63 | uname | rdi value |
| 72 | fcntl | rdi file descriptorrsi wat_fcntlrdx un |
| 73 | flock | rdi valuersi value |
| 74 | fsync | rdi file descriptor |
| 75 | fdatasync | rdi file descriptor |
| 76 | truncate | rdi stringrsi offset |
| 77 | ftruncate | rdi file descriptorrsi offset |
| 79 | getcwd | rdi buffer (written by the kernel)rsi byte count |
| 80 | chdir | rdi path |
| 81 | fchdir | rdi file descriptor |
| 82 | rename | rdi pathrsi path |
| 83 | mkdir | rdi pathrsi mode |
| 84 | rmdir | rdi path |
| 85 | creat | rdi pathrsi mode |
| 86 | link | rdi pathrsi path |
| 87 | unlink | rdi path |
| 88 | symlink | rdi pathrsi path |
| 89 | readlink | rdi pathrsi buffer (written by the kernel)rdx byte count |
| 90 | chmod | rdi pathrsi mode |
| 91 | fchmod | rdi file descriptorrsi uid |
| 92 | chown | rdi pathrsi uidrdx gid |
| 93 | fchown | rdi file descriptorrsi uidrdx gid |
| 94 | lchown | rdi pathrsi uidrdx gid |
| 95 | umask | rdi mode |
| 96 | gettimeofday | rdi valuersi value |
| 97 | getrlimit | rdi resourcersi o_rlimit |
| 98 | getrusage | rdi valuersi value |
| 99 | sysinfo | rdi value |
| 100 | times | rdi value |
| 102 | getuid | |
| 104 | getgid | |
| 105 | setuid | rdi uid |
| 106 | setgid | rdi gid |
| 107 | geteuid | |
| 108 | getegid | |
| 109 | setpgid | rdi valuersi value |
| 110 | getppid | |
| 111 | getpgrp | |
| 112 | setsid | |
| 113 | setreuid | rdi uidrsi uid |
| 114 | setregid | rdi gidrsi gid |
| 115 | getgroups | rdi valuersi value |
| 116 | setgroups | rdi valuersi value |
| 117 | setresuid | rdi uidrsi uidrdx uid |
| 118 | getresuid | rdi valuersi valuerdx value |
| 119 | setresgid | rdi gidrsi gidrdx gid |
| 120 | getresgid | rdi valuersi valuerdx value |
| 121 | getpgid | rdi process id |
| 124 | getsid | rdi value |
| 127 | rt_sigpending | rdi value |
| 130 | rt_sigsuspend | rdi i_sigsetrsi byte count |
| 131 | sigaltstack | rdi valuersi value |
| 132 | utime | rdi valuersi value |
| 133 | mknod | rdi valuersi valuerdx value |
| 137 | statfs | rdi valuersi value |
| 138 | fstatfs | rdi valuersi value |
| 140 | getpriority | rdi valuersi value |
| 141 | setpriority | rdi valuersi valuerdx value |
| 142 | sched_set_param | rdi valuersi value |
| 143 | sched_get_param | rdi valuersi value |
| 144 | sched_set_scheduler | rdi valuersi valuerdx value |
| 145 | sched_get_scheduler | rdi value |
| 146 | sched_get_priority_max | rdi value |
| 147 | sched_get_priority_min | rdi value |
| 157 | prctl | rdi valuersi valuerdx valuer10 valuer8 value |
| 158 | arch_prctl | rdi valuersi value |
| 160 | setrlimit | rdi resourcersi i_rlimit |
| 161 | chroot | rdi path |
| 162 | sync | |
| 165 | mount | rdi stringrsi stringrdx msflagsr10 pointerr8 un |
| 186 | gettid | |
| 200 | tkill | rdi process idrsi signal |
| 202 | futex | rdi valuersi valuerdx valuer10 valuer8 valuer9 value |
| 203 | sched_set_affinity | rdi valuersi valuerdx value |
| 204 | sched_get_affinity | rdi valuersi valuerdx value |
| 213 | epoll_create | rdi value |
| 217 | getdents | rdi valuersi valuerdx value |
| 218 | set_tid_address | rdi value |
| 221 | fadvise | rdi valuersi valuerdx valuer10 value |
| 227 | clock_settime | rdi valuersi value |
| 229 | clock_getres | rdi valuersi value |
| 230 | clock_nanosleep | rdi clockrsi intrdx i_timer10 o_time |
| 232 | epoll_wait | rdi valuersi valuerdx valuer10 value |
| 233 | epoll_ctl | rdi valuersi valuerdx valuer10 value |
| 234 | tgkill | rdi valuersi valuerdx value |
| 235 | utimes | rdi valuersi value |
| 257 | openat | rdi directory descriptorrsi stringrdx open flagsr10 mode |
| 258 | mkdirat | rdi directory descriptorrsi pathrdx mode |
| 259 | mknodat | rdi valuersi valuerdx valuer10 value |
| 260 | fchownat | rdi directory descriptorrsi pathrdx uidr10 gidr8 atflags |
| 261 | futimesat | rdi valuersi valuerdx value |
| 262 | fstatat | rdi directory descriptorrsi pathrdx o_statr10 atflags |
| 263 | unlinkat | rdi directory descriptorrsi pathrdx atflags |
| 264 | renameat | rdi directory descriptorrsi pathrdx directory descriptorr10 path |
| 265 | linkat | rdi directory descriptorrsi pathrdx directory descriptorr10 pathr8 atflags |
| 266 | symlinkat | rdi pathrsi directory descriptorrdx path |
| 267 | readlinkat | rdi directory descriptorrsi stringrdx buffer (written by the kernel)r10 byte count |
| 268 | fchmodat | rdi directory descriptorrsi pathrdx mode |
| 269 | faccessat | rdi directory descriptorrsi pathrdx accmode |
| 270 | pselect6 | rdi valuersi valuerdx valuer10 valuer8 valuer9 value |
| 271 | ppoll | rdi valuersi valuerdx valuer10 valuer8 value |
| 273 | set_robust_list | rdi valuersi value |
| 274 | get_robust_list | rdi valuersi valuerdx value |
| 280 | utimensat | rdi directory descriptorrsi pathrdx o_time2r10 atflags |
| 281 | epoll_pwait | rdi valuersi valuerdx valuer10 valuer8 valuer9 value |
| 288 | accept4 | rdi file descriptorrsi o_addrrdx longr10 sockflags |
| 291 | epoll_create1 | rdi value |
| 292 | dup3 | rdi file descriptorrsi intrdx open flags |
| 293 | pipe2 | rdi o_pfdsrsi open flags |
| 295 | preadv | rdi file descriptorrsi iovec array (written)rdx byte countr10 offset |
| 296 | pwritev | rdi file descriptorrsi iovec array (read)rdx byte countr10 offset |
| 299 | recvmmsg | rdi valuersi valuerdx valuer10 valuer8 value |
| 302 | prlimit | rdi process idrsi resourcerdx i_rlimitr10 o_rlimit |
| 307 | sendmmsg | rdi valuersi valuerdx valuer10 value |
| 316 | renameat2 | rdi directory descriptorrsi pathrdx directory descriptorr10 pathr8 atflags |
| 318 | getrandom | rdi buffer (written by the kernel)rsi byte countrdx int |
| 327 | preadv2 | rdi file descriptorrsi iovec array (written)rdx byte countr10 offsetr8 int |
| 328 | pwritev2 | rdi file descriptorrsi iovec array (read)rdx byte countr10 offsetr8 int |
| 436 | close_range | rdi valuersi valuerdx value |
| 439 | faccessat2 | rdi directory descriptorrsi pathrdx accmoder10 atflags |
| 441 | epoll_pwait2 | rdi valuersi valuerdx valuer10 valuer8 valuer9 value |