setsockopt on x64
get and set options on sockets
sys_setsockopt(int fd, int level, int optname, char *optval, int optlen)
| number | 54 (0x36) |
|---|---|
| abi | 64 |
| entry point | sys_setsockopt |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | setsockopt(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 54, the syscall number |
rdi | int fd |
rsi | int level |
rdx | int optname |
r10 | char *optval |
r8 | int optlen |
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 366
- arm64 208
- arm 294
- riscv64 208
- ia32 366
- x32 1073741878, 1073742365
- loongarch64 208
- ppc64 339
- ppc 339
- s390x 366
- mips64 5053
- mipsn32 6053
- mipso32 4181
- alpha 105
- arc 208
- blackfin 327, removed in 4.17
- csky 208
- hexagon 208
- ia64 1203, removed in 6.7
- m68k 363
- metag 208, removed in 4.17
- microblaze 357
- nds32 208, removed in 5.18
- nios2 208
- openrisc 208
- parisc 181
- score 208, removed in 4.17
- sh 353
- sparc 355
- sparc64 355
- tilegx 208, removed in 4.17
- tilepro 208, removed in 4.17
- xtensa 97
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/setsockopt