lseek on x64
reposition read/write file offset
sys_lseek(unsigned int fd, off_t offset, unsigned int whence)
| number | 8 (0x8) |
|---|---|
| abi | common |
| entry point | sys_lseek |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | lseek(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 8, the syscall number |
rdi | unsigned int fd |
rsi | off_t offset |
rdx | unsigned int whence |
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 19
- arm64 62
- arm 19
- riscv64 62
- ia32 19
- x32 1073741832
- loongarch64 62
- ppc64 19
- ppc 19
- s390x 19
- mips64 5008
- mipsn32 6008
- mipso32 4019
- alpha 19
- blackfin 19, removed in 4.17
- cris 19, removed in 4.17
- frv 19, removed in 4.17
- ia64 1040, removed in 6.7
- m32r 19, removed in 4.17
- m68k 19
- microblaze 19
- mn10300 19, removed in 4.17
- parisc 19
- score 1057, removed in 4.17
- sh 19
- sparc 19
- sparc64 19
- tilegx 62, removed in 4.17
- xtensa 15
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/lseek