x86-64 syscalls

The ones to start with

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.

write

rax = 1

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.

rax
1
rdi
file descriptor
rsi
buffer (read by the kernel)
rdx
byte count
Waits
This call can wait for the outside world.

read

rax = 0

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.

rax
0
rdi
file descriptor
rsi
buffer (written by the kernel)
rdx
byte count
Waits
This call can wait for the outside world.

exit

rax = 60

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.

rax
60
rdi
status

exit_group

rax = 231

Ends every thread of the program with the status in rdi. For a program with one thread it is exit.

rax
231
rdi
status

open

rax = 2

Opens the path at rdi with the flags in rsi and, when creating, the mode in rdx. Returns a file descriptor.

rax
2
rdi
path
rsi
open flags
rdx
mode
Waits
This call can wait for the outside world.

close

rax = 3

Closes the file descriptor in rdi.

rax
3
rdi
file descriptor
Waits
This call can wait for the outside world.

lseek

rax = 8

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.

rax
8
rdi
file descriptor
rsi
offset
rdx
whence

fstat

rax = 5

Fills the structure at rsi with what is known about the descriptor in rdi, including its size.

rax
5
rdi
file descriptor
rsi
o_stat

brk

rax = 12

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.

rax
12
rdi
value

mmap

rax = 9

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.

rax
9
rdi
pointer
rsi
size
rdx
protection flags
r10
mapping flags
r8
file descriptor
r9
offset

munmap

rax = 11

Unmaps the mapping of rsi bytes at the address in rdi.

rax
11
rdi
pointer
rsi
size

nanosleep

rax = 35

Sleeps for the interval at rdi, a pair of seconds and nanoseconds.

rax
35
rdi
i_time
rsi
o_time
Waits
This call can wait for the outside world.

clock_gettime

rax = 228

Writes the time of the clock named in rdi into the structure at rsi.

rax
228
rdi
clock
rsi
timespec

getpid

rax = 39

Returns the process id.

rax
39

Everything this emulator implements

Those syscalls are what the emulator implements, anything missing returns -ENOSYS.

stat

rax = 4
rax
4
rdi
path
rsi
o_stat

lstat

rax = 6
rax
6
rdi
path
rsi
o_stat

poll

rax = 7
rax
7
rdi
value
rsi
value
rdx
value

mprotect

rax = 10
rax
10
rdi
pointer
rsi
size
rdx
protection flags

rt_sigaction

rax = 13
rax
13
rdi
signal
rsi
i_hand
rdx
o_hand
r10
byte count

rt_sigprocmask

rax = 14
rax
14
rdi
sighow
rsi
i_sigset
rdx
o_sigset
r10
byte count

ioctl

rax = 16

Asks a device the descriptor in rdi refers to for something outside the ordinary read and write interface, chosen by the request in rsi.

rax
16
rdi
value
rsi
value
rdx
value

pread

rax = 17
rax
17
rdi
file descriptor
rsi
buffer (written by the kernel)
rdx
byte count
r10
offset
Waits
This call can wait for the outside world.

pwrite

rax = 18
rax
18
rdi
file descriptor
rsi
buffer (read by the kernel)
rdx
byte count
r10
offset
Waits
This call can wait for the outside world.

readv

rax = 19
rax
19
rdi
file descriptor
rsi
iovec array (written)
rdx
byte count
Waits
This call can wait for the outside world.

writev

rax = 20
rax
20
rdi
file descriptor
rsi
iovec array (read)
rdx
byte count
Waits
This call can wait for the outside world.

access

rax = 21
rax
21
rdi
path
rsi
accmode

pipe

rax = 22
rax
22
rdi
o_pfds

select

rax = 23
rax
23
rdi
int
rsi
io_fdset
rdx
io_fdset
r10
io_fdset
r8
io_timev

sched_yield

rax = 24
rax
24

mremap

rax = 25
rax
25
rdi
value
rsi
value
rdx
value
r10
value
r8
value

msync

rax = 26
rax
26
rdi
value
rsi
value
rdx
value

madvise

rax = 28
rax
28
rdi
value
rsi
value
rdx
value

dup

rax = 32
rax
32
rdi
file descriptor

dup2

rax = 33
rax
33
rdi
file descriptor
rsi
int

pause

rax = 34
rax
34
Waits
This call can wait for the outside world.

getitimer

rax = 36
rax
36
rdi
value
rsi
value

alarm

rax = 37
rax
37
rdi
int

setitimer

rax = 38
rax
38
rdi
value
rsi
value
rdx
value

sendfile

rax = 40
rax
40
rdi
value
rsi
value
rdx
value
r10
value

socket

rax = 41
rax
41
rdi
family
rsi
socktype
rdx
int

connect

rax = 42
rax
42
rdi
file descriptor
rsi
i_addr
rdx
addrlen

accept

rax = 43
rax
43
rdi
file descriptor
rsi
o_addr
rdx
long
Waits
This call can wait for the outside world.

sendto

rax = 44
rax
44
rdi
file descriptor
rsi
buffer (read by the kernel)
rdx
size
r10
int
r8
i_addr
r9
addrlen

recvfrom

rax = 45
rax
45
rdi
file descriptor
rsi
buffer (written by the kernel)
rdx
size
r10
int
r8
o_addr
r9
long
Waits
This call can wait for the outside world.

sendmsg

rax = 46
rax
46
rdi
value
rsi
value
rdx
value

recvmsg

rax = 47
rax
47
rdi
value
rsi
value
rdx
value

shutdown

rax = 48
rax
48
rdi
value
rsi
value

bind

rax = 49
rax
49
rdi
file descriptor
rsi
i_addr
rdx
addrlen

listen

rax = 50
rax
50
rdi
file descriptor
rsi
un

getsockname

rax = 51
rax
51
rdi
file descriptor
rsi
o_addr
rdx
long

getpeername

rax = 52
rax
52
rdi
file descriptor
rsi
o_addr
rdx
long

socketpair

rax = 53
rax
53
rdi
family
rsi
socktype
rdx
int
r10
o_pfds

setsockopt

rax = 54
rax
54
rdi
value
rsi
value
rdx
value
r10
value
r8
value

getsockopt

rax = 55
rax
55
rdi
value
rsi
value
rdx
value
r10
value
r8
value

clone

rax = 56
rax
56
rdi
cloneflags
rsi
pointer
rdx
pointer
r10
pointer
r8
pointer
r9
pointer

fork

rax = 57
rax
57

vfork

rax = 58
rax
58

execve

rax = 59
rax
59
rdi
value
rsi
value
rdx
value

wait4

rax = 61
rax
61
rdi
process id
rsi
o_wstatus
rdx
waitflags
r10
o_rusage
Waits
This call can wait for the outside world.

kill

rax = 62
rax
62
rdi
process id
rsi
signal

uname

rax = 63
rax
63
rdi
value

fcntl

rax = 72
rax
72
rdi
file descriptor
rsi
wat_fcntl
rdx
un
Waits
This call can wait for the outside world.

flock

rax = 73
rax
73
rdi
value
rsi
value

fsync

rax = 74
rax
74
rdi
file descriptor
Waits
This call can wait for the outside world.

fdatasync

rax = 75
rax
75
rdi
file descriptor
Waits
This call can wait for the outside world.

truncate

rax = 76
rax
76
rdi
string
rsi
offset
Waits
This call can wait for the outside world.

ftruncate

rax = 77
rax
77
rdi
file descriptor
rsi
offset
Waits
This call can wait for the outside world.

getcwd

rax = 79
rax
79
rdi
buffer (written by the kernel)
rsi
byte count

chdir

rax = 80
rax
80
rdi
path

fchdir

rax = 81
rax
81
rdi
file descriptor

rename

rax = 82
rax
82
rdi
path
rsi
path

mkdir

rax = 83
rax
83
rdi
path
rsi
mode

rmdir

rax = 84
rax
84
rdi
path

creat

rax = 85
rax
85
rdi
path
rsi
mode
Waits
This call can wait for the outside world.

link

rax = 86
rax
86
rdi
path
rsi
path

unlink

rax = 87
rax
87
rdi
path

symlink

rax = 88
rax
88
rdi
path
rsi
path

readlink

rax = 89
rax
89
rdi
path
rsi
buffer (written by the kernel)
rdx
byte count

chmod

rax = 90
rax
90
rdi
path
rsi
mode

fchmod

rax = 91
rax
91
rdi
file descriptor
rsi
uid

chown

rax = 92
rax
92
rdi
path
rsi
uid
rdx
gid

fchown

rax = 93
rax
93
rdi
file descriptor
rsi
uid
rdx
gid

lchown

rax = 94
rax
94
rdi
path
rsi
uid
rdx
gid

umask

rax = 95
rax
95
rdi
mode

gettimeofday

rax = 96
rax
96
rdi
value
rsi
value

getrlimit

rax = 97
rax
97
rdi
resource
rsi
o_rlimit

getrusage

rax = 98
rax
98
rdi
value
rsi
value

sysinfo

rax = 99
rax
99
rdi
value

times

rax = 100
rax
100
rdi
value

getuid

rax = 102
rax
102

getgid

rax = 104
rax
104

setuid

rax = 105
rax
105
rdi
uid

setgid

rax = 106
rax
106
rdi
gid

geteuid

rax = 107
rax
107

getegid

rax = 108
rax
108

setpgid

rax = 109
rax
109
rdi
value
rsi
value

getppid

rax = 110
rax
110

getpgrp

rax = 111
rax
111

setsid

rax = 112
rax
112

setreuid

rax = 113
rax
113
rdi
uid
rsi
uid

setregid

rax = 114
rax
114
rdi
gid
rsi
gid

getgroups

rax = 115
rax
115
rdi
value
rsi
value

setgroups

rax = 116
rax
116
rdi
value
rsi
value

setresuid

rax = 117
rax
117
rdi
uid
rsi
uid
rdx
uid

getresuid

rax = 118
rax
118
rdi
value
rsi
value
rdx
value

setresgid

rax = 119
rax
119
rdi
gid
rsi
gid
rdx
gid

getresgid

rax = 120
rax
120
rdi
value
rsi
value
rdx
value

getpgid

rax = 121
rax
121
rdi
process id

getsid

rax = 124
rax
124
rdi
value

rt_sigpending

rax = 127
rax
127
rdi
value

rt_sigsuspend

rax = 130
rax
130
rdi
i_sigset
rsi
byte count
Waits
This call can wait for the outside world.

sigaltstack

rax = 131
rax
131
rdi
value
rsi
value

utime

rax = 132
rax
132
rdi
value
rsi
value

mknod

rax = 133
rax
133
rdi
value
rsi
value
rdx
value

statfs

rax = 137
rax
137
rdi
value
rsi
value

fstatfs

rax = 138
rax
138
rdi
value
rsi
value

getpriority

rax = 140
rax
140
rdi
value
rsi
value

setpriority

rax = 141
rax
141
rdi
value
rsi
value
rdx
value

sched_set_param

rax = 142
rax
142
rdi
value
rsi
value

sched_get_param

rax = 143
rax
143
rdi
value
rsi
value

sched_set_scheduler

rax = 144
rax
144
rdi
value
rsi
value
rdx
value

sched_get_scheduler

rax = 145
rax
145
rdi
value

sched_get_priority_max

rax = 146
rax
146
rdi
value

sched_get_priority_min

rax = 147
rax
147
rdi
value

prctl

rax = 157
rax
157
rdi
value
rsi
value
rdx
value
r10
value
r8
value

arch_prctl

rax = 158
rax
158
rdi
value
rsi
value

setrlimit

rax = 160
rax
160
rdi
resource
rsi
i_rlimit

chroot

rax = 161
rax
161
rdi
path

sync

rax = 162
rax
162
Waits
This call can wait for the outside world.

mount

rax = 165
rax
165
rdi
string
rsi
string
rdx
msflags
r10
pointer
r8
un

gettid

rax = 186
rax
186

tkill

rax = 200
rax
200
rdi
process id
rsi
signal

futex

rax = 202
rax
202
rdi
value
rsi
value
rdx
value
r10
value
r8
value
r9
value
Waits
This call can wait for the outside world.

sched_set_affinity

rax = 203
rax
203
rdi
value
rsi
value
rdx
value

sched_get_affinity

rax = 204
rax
204
rdi
value
rsi
value
rdx
value

epoll_create

rax = 213
rax
213
rdi
value

getdents

rax = 217
rax
217
rdi
value
rsi
value
rdx
value

set_tid_address

rax = 218
rax
218
rdi
value

fadvise

rax = 221
rax
221
rdi
value
rsi
value
rdx
value
r10
value

clock_settime

rax = 227
rax
227
rdi
value
rsi
value

clock_getres

rax = 229
rax
229
rdi
value
rsi
value

clock_nanosleep

rax = 230
rax
230
rdi
clock
rsi
int
rdx
i_time
r10
o_time
Waits
This call can wait for the outside world.

epoll_wait

rax = 232
rax
232
rdi
value
rsi
value
rdx
value
r10
value

epoll_ctl

rax = 233
rax
233
rdi
value
rsi
value
rdx
value
r10
value

tgkill

rax = 234
rax
234
rdi
value
rsi
value
rdx
value

utimes

rax = 235
rax
235
rdi
value
rsi
value

openat

rax = 257
rax
257
rdi
directory descriptor
rsi
string
rdx
open flags
r10
mode
Waits
This call can wait for the outside world.

mkdirat

rax = 258
rax
258
rdi
directory descriptor
rsi
path
rdx
mode

mknodat

rax = 259
rax
259
rdi
value
rsi
value
rdx
value
r10
value

fchownat

rax = 260
rax
260
rdi
directory descriptor
rsi
path
rdx
uid
r10
gid
r8
atflags

futimesat

rax = 261
rax
261
rdi
value
rsi
value
rdx
value

fstatat

rax = 262
rax
262
rdi
directory descriptor
rsi
path
rdx
o_stat
r10
atflags

unlinkat

rax = 263
rax
263
rdi
directory descriptor
rsi
path
rdx
atflags

renameat

rax = 264
rax
264
rdi
directory descriptor
rsi
path
rdx
directory descriptor
r10
path

linkat

rax = 265
rax
265
rdi
directory descriptor
rsi
path
rdx
directory descriptor
r10
path
r8
atflags

symlinkat

rax = 266
rax
266
rdi
path
rsi
directory descriptor
rdx
path

readlinkat

rax = 267
rax
267
rdi
directory descriptor
rsi
string
rdx
buffer (written by the kernel)
r10
byte count

fchmodat

rax = 268
rax
268
rdi
directory descriptor
rsi
path
rdx
mode

faccessat

rax = 269
rax
269
rdi
directory descriptor
rsi
path
rdx
accmode

pselect6

rax = 270
rax
270
rdi
value
rsi
value
rdx
value
r10
value
r8
value
r9
value

ppoll

rax = 271
rax
271
rdi
value
rsi
value
rdx
value
r10
value
r8
value

set_robust_list

rax = 273
rax
273
rdi
value
rsi
value

get_robust_list

rax = 274
rax
274
rdi
value
rsi
value
rdx
value

utimensat

rax = 280
rax
280
rdi
directory descriptor
rsi
path
rdx
o_time2
r10
atflags

epoll_pwait

rax = 281
rax
281
rdi
value
rsi
value
rdx
value
r10
value
r8
value
r9
value

accept4

rax = 288
rax
288
rdi
file descriptor
rsi
o_addr
rdx
long
r10
sockflags
Waits
This call can wait for the outside world.

epoll_create1

rax = 291
rax
291
rdi
value

dup3

rax = 292
rax
292
rdi
file descriptor
rsi
int
rdx
open flags

pipe2

rax = 293
rax
293
rdi
o_pfds
rsi
open flags

preadv

rax = 295
rax
295
rdi
file descriptor
rsi
iovec array (written)
rdx
byte count
r10
offset
Waits
This call can wait for the outside world.

pwritev

rax = 296
rax
296
rdi
file descriptor
rsi
iovec array (read)
rdx
byte count
r10
offset
Waits
This call can wait for the outside world.

recvmmsg

rax = 299
rax
299
rdi
value
rsi
value
rdx
value
r10
value
r8
value

prlimit

rax = 302
rax
302
rdi
process id
rsi
resource
rdx
i_rlimit
r10
o_rlimit

sendmmsg

rax = 307
rax
307
rdi
value
rsi
value
rdx
value
r10
value

renameat2

rax = 316
rax
316
rdi
directory descriptor
rsi
path
rdx
directory descriptor
r10
path
r8
atflags

getrandom

rax = 318
rax
318
rdi
buffer (written by the kernel)
rsi
byte count
rdx
int
Waits
This call can wait for the outside world.

preadv2

rax = 327
rax
327
rdi
file descriptor
rsi
iovec array (written)
rdx
byte count
r10
offset
r8
int
Waits
This call can wait for the outside world.

pwritev2

rax = 328
rax
328
rdi
file descriptor
rsi
iovec array (read)
rdx
byte count
r10
offset
r8
int
Waits
This call can wait for the outside world.

close_range

rax = 436
rax
436
rdi
value
rsi
value
rdx
value

faccessat2

rax = 439
rax
439
rdi
directory descriptor
rsi
path
rdx
accmode
r10
atflags

epoll_pwait2

rax = 441
rax
441
rdi
value
rsi
value
rdx
value
r10
value
r8
value
r9
value