dup on x64
duplicate a file descriptor
sys_dup(unsigned int fildes)
| number | 32 (0x20) |
|---|---|
| abi | common |
| entry point | sys_dup |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | dup(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 32, the syscall number |
rdi | unsigned int fildes |
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 41
- arm64 23
- arm 41
- riscv64 23
- ia32 41
- x32 1073741856
- loongarch64 23
- ppc64 41
- ppc 41
- s390x 41
- mips64 5031
- mipsn32 6031
- mipso32 4041
- alpha 41
- arc 23
- blackfin 41, removed in 4.17
- cris 41, removed in 4.17
- csky 23
- frv 41, removed in 4.17
- hexagon 23
- ia64 1057, removed in 6.7
- m32r 41, removed in 4.17
- m68k 41
- metag 23, removed in 4.17
- microblaze 41
- mn10300 41, removed in 4.17
- nds32 23, removed in 5.18
- nios2 23
- openrisc 23
- parisc 41
- score 23, removed in 4.17
- sh 41
- sparc 41
- sparc64 41
- tilegx 23, removed in 4.17
- tilepro 23, removed in 4.17
- xtensa 10
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/dup