dup3 on x64
duplicate a file descriptor
sys_dup3(unsigned int oldfd, unsigned int newfd, int flags)
| number | 292 (0x124) |
|---|---|
| abi | common |
| entry point | sys_dup3 |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | dup3(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 292, the syscall number |
rdi | unsigned int oldfd |
rsi | unsigned int newfd |
rdx | int flags |
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 330
- arm64 24
- arm 358
- riscv64 24
- ia32 330
- x32 1073742116
- loongarch64 24
- ppc64 316
- ppc 316
- s390x 326
- mips64 5286
- mipsn32 6290
- mipso32 4327
- alpha 487
- arc 24
- blackfin 363, removed in 4.17
- cris 330, removed in 4.17
- csky 24
- frv 330, removed in 4.17
- hexagon 24
- ia64 1316, removed in 6.7
- m68k 326
- metag 24, removed in 4.17
- microblaze 342
- mn10300 331, removed in 4.17
- nds32 24, removed in 5.18
- nios2 24
- openrisc 24
- parisc 312
- score 24, removed in 4.17
- sh 330
- sparc 320
- sparc64 320
- tilegx 24, removed in 4.17
- tilepro 24, removed in 4.17
- xtensa 310
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/dup3