write on x64
write to a file descriptor
sys_write(unsigned int fd, const char *buf, size_t count)
| number | 1 (0x1) |
|---|---|
| abi | common |
| entry point | sys_write |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | write(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 1, the syscall number |
rdi | unsigned int fd |
rsi | const char *buf |
rdx | size_t count |
rax | the return value |
Then run syscall to enter the kernel.
The syscall instruction clobbers rcx (the return address lands in rcx) and r11 (the flags land in r11).
Since Linux 5.14 the kernel reads the syscall number from eax and ignores the upper 32 bits of rax. Older kernels fail with ENOSYS when those bits are not zero, and mov eax, N clears them, so it works on both.
Same syscall on other architectures
- x86 4
- arm64 64
- arm 4
- riscv64 64
- ia32 4
- x32 1073741825
- loongarch64 64
- ppc64 4
- ppc 4
- s390x 4
- mips64 5001
- mipsn32 6001
- mipso32 4004
- alpha 4
- arc 64
- blackfin 4, removed in 4.17
- cris 4, removed in 4.17
- csky 64
- frv 4, removed in 4.17
- hexagon 64
- ia64 1027, removed in 6.7
- m32r 4, removed in 4.17
- m68k 4
- metag 64, removed in 4.17
- microblaze 4
- mn10300 4, removed in 4.17
- nds32 64, removed in 5.18
- nios2 64
- openrisc 64
- parisc 4
- score 64, removed in 4.17
- sh 4
- sparc 4
- sparc64 4
- tilegx 64, removed in 4.17
- tilepro 64, removed in 4.17
- xtensa 13
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/write