ftruncate on x64
truncate a file to a specified length
sys_ftruncate(unsigned int fd, off_t length)
| number | 77 (0x4d) |
|---|---|
| abi | common |
| entry point | sys_ftruncate |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | ftruncate(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 77, the syscall number |
rdi | unsigned int fd |
rsi | off_t length |
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 93
- arm64 46
- arm 93
- riscv64 46
- ia32 93
- x32 1073741901
- loongarch64 46
- ppc64 93
- ppc 93
- s390x 93
- mips64 5075
- mipsn32 6075
- mipso32 4093
- alpha 130
- blackfin 93, removed in 4.17
- cris 93, removed in 4.17
- frv 93, removed in 4.17
- ia64 1098, removed in 6.7
- m32r 93, removed in 4.17
- m68k 93
- microblaze 93
- mn10300 93, removed in 4.17
- parisc 93
- score 1047, removed in 4.17
- sh 93
- sparc 130
- sparc64 130
- tilegx 46, removed in 4.17
- xtensa 23
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/ftruncate