clock_gettime on x64
clock and time functions
sys_clock_gettime(clockid_t which_clock, struct __kernel_timespec *tp)
| number | 228 (0xe4) |
|---|---|
| abi | common |
| entry point | sys_clock_gettime |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | clock_gettime(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 228, the syscall number |
rdi | clockid_t which_clock |
rsi | struct __kernel_timespec *tp |
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 265
- arm64 113
- arm 263
- riscv64 113
- ia32 265
- x32 1073742052
- loongarch64 113
- ppc64 246
- ppc 246
- s390x 260
- mips64 5222
- mipsn32 6226
- mipso32 4263
- alpha 420
- arc 113
- blackfin 266, removed in 4.17
- cris 265, removed in 4.17
- csky 113
- frv 265, removed in 4.17
- hexagon 113
- ia64 1254, removed in 6.7
- m32r 265, removed in 4.17
- m68k 260
- metag 113, removed in 4.17
- microblaze 265
- mn10300 265, removed in 4.17
- nds32 113, removed in 5.18
- nios2 113
- openrisc 113
- parisc 256
- score 113, removed in 4.17
- sh 265
- sparc 257
- sparc64 257
- tilegx 113, removed in 4.17
- tilepro 113, removed in 4.17
- xtensa 245
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/clock_gettime