getrandom on x64
obtain a series of random bytes
sys_getrandom(char *buf, size_t count, unsigned int flags)
| number | 318 (0x13e) |
|---|---|
| abi | common |
| entry point | sys_getrandom |
| since | Linux 3.17 |
| man page | getrandom(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 318, the syscall number |
rdi | char *buf |
rsi | size_t count |
rdx | unsigned 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 355
- arm64 278
- arm 384
- riscv64 278
- ia32 355
- x32 1073742142
- loongarch64 278
- ppc64 359
- ppc 359
- s390x 349
- mips64 5313
- mipsn32 6317
- mipso32 4353
- alpha 511
- arc 278
- blackfin 389, removed in 4.17
- cris 356, removed in 4.17
- csky 278
- hexagon 278
- ia64 1339, removed in 6.7
- m68k 352
- metag 278, removed in 4.17
- microblaze 385
- nds32 278, removed in 5.18
- nios2 278
- openrisc 278
- parisc 339
- score 278, removed in 4.17
- sh 373
- sparc 347
- sparc64 347
- tilegx 278, removed in 4.17
- tilepro 278, removed in 4.17
- xtensa 338
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/getrandom