kcmp on x64
compare two processes to determine if they share a kernel resource
sys_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2)
| number | 312 (0x138) |
|---|---|
| abi | common |
| kconfig | CONFIG_KCMP |
| entry point | sys_kcmp |
| since | Linux 3.5 |
| man page | kcmp(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 312, the syscall number |
rdi | pid_t pid1 |
rsi | pid_t pid2 |
rdx | int type |
r10 | unsigned long idx1 |
r8 | unsigned long idx2 |
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 349
- arm64 272
- arm 378
- riscv64 272
- ia32 349
- x32 1073742136
- loongarch64 272
- ppc64 354
- ppc 354
- s390x 343
- mips64 5306
- mipsn32 6311
- mipso32 4347
- alpha 506
- arc 272
- blackfin 383, removed in 4.17
- cris 350, removed in 4.17
- csky 272
- hexagon 272
- ia64 1345, removed in 6.7
- m68k 347
- metag 272, removed in 4.17
- microblaze 379
- nds32 272, removed in 5.18
- nios2 272
- openrisc 272
- parisc 332
- score 272, removed in 4.17
- sh 367
- sparc 341
- sparc64 341
- tilegx 272, removed in 4.17
- tilepro 272, removed in 4.17
- xtensa 331
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/kcmp