sethostname on x64
get/set hostname
sys_sethostname(char *name, int len)
| number | 170 (0xaa) |
|---|---|
| abi | common |
| entry point | sys_sethostname |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | sethostname(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 170, the syscall number |
rdi | char *name |
rsi | int len |
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 74
- arm64 161
- arm 74
- riscv64 161
- ia32 74
- x32 1073741994
- loongarch64 161
- ppc64 74
- ppc 74
- s390x 74
- mips64 5165
- mipsn32 6165
- mipso32 4074
- alpha 88
- arc 161
- blackfin 74, removed in 4.17
- cris 74, removed in 4.17
- csky 161
- frv 74, removed in 4.17
- hexagon 161
- ia64 1083, removed in 6.7
- m32r 74, removed in 4.17
- m68k 74
- metag 161, removed in 4.17
- microblaze 74
- mn10300 74, removed in 4.17
- nds32 161, removed in 5.18
- nios2 161
- openrisc 161
- parisc 74
- score 161, removed in 4.17
- sh 74
- sparc 88
- sparc64 88
- tilegx 161, removed in 4.17
- tilepro 161, removed in 4.17
- xtensa 198
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/sethostname