PR_GET_SPECULATION_CTRL(2const)
π PR_GET_SPECULATION_CTRL (2const) β¨
okay bestie, welcome to the girls' guide to asking your CPU "hey queen, what's the vibe with your speculation mitigations?" β it's giving very niche, very kernel-coded, but honestly? iconic.
Manual name: PR_GET_SPECULATION_CTRL β a Linux prctl() constant. yes, 2const means it lives in the constants corner of section 2. iykyk. π
πΈ NAME πΈ
PR_GET_SPECULATION_CTRL β get the state of a speculation misfeature for the calling thread
like, for this specific thread, not your whole process. main character energy but make it per-thread. π
π LIBRARY π
Standard C library β link it with -lc
β¨ SYNOPSIS β¨
#include <linux/prctl.h> /* Definition of PR_* constants */
#include <sys/prctl.h>
int prctl(PR_GET_SPECULATION_CTRL, long misfeature, 0L, 0L, 0L);
not me remembering the 0L, 0L, 0L every single time π it's literally always zeros here, bestie.
π¦ DESCRIPTION π¦
So basically, this returns the state of the speculation misfeature you named in misfeature.
Currently, misfeature has to be one of these two divas:
PR_SPEC_STORE_BYPASSβ get the state of the speculative store bypass misfeature. the classic. πPR_SPEC_INDIRECT_BRANCH(since Linux 4.20) β get the state of the indirect branch speculation misfeature. younger sister, joined in 4.20. πΈ
Now the return value? it's literally a bitfield using bits 0-4, and each bit is telling you a whole story:
PR_SPEC_PRCTLβ the mitigation can be controlled per thread byPR_SET_SPECULATION_CTRL(2const). you have agency, bestie. πPR_SPEC_ENABLEβ the speculation feature is enabled, mitigation is disabled. it's giving unbothered. πPR_SPEC_DISABLEβ the speculation feature is disabled, mitigation is enabled. locked down, protected, safe. π‘οΈPR_SPEC_FORCE_DISABLEβ same asPR_SPEC_DISABLEbut it cannot be undone. no take-backs. periodt. πPR_SPEC_DISABLE_NOEXEC(since Linux 5.1) β same asPR_SPEC_DISABLE, but the state gets cleared onexecve(2). so it resets itself when you exec. clean. β¨
If all bits are 0, then the CPU is not affected by the speculation misfeature. your CPU said "not my problem" and honestly we respect it. π
And listen, this part matters: if PR_SPEC_PRCTL is set, then per-thread control of the mitigation is available. if it is not set, then PR_SET_SPECULATION_CTRL(2const) for the speculation misfeature will fail. so like, vibe check the PR_SPEC_PRCTL bit before you go trying to set anything, fr fr. π«Ά
β RETURN VALUE β
On success, PR_GET_SPECULATION_CTRL returns the nonnegative value described above (the bitfield, bestie).
On error, -1 is returned, and errno is set to indicate the error. rude but standard. π
π₯ ERRORS π₯
ENODEVβ the kernel or CPU does not support the requested speculation misfeature. not every CPU is built for this life, and that's fine. π
π STANDARDS π
Linux.
just Linux. no POSIX girly here, this is a kernel-only situation. π§
π HISTORY π
Linux 4.17.
ancient in internet years (which is like, a decade-ish of discourse). π
π― SEE ALSO π―
the "set" version is the sister page β go read her too, they're a matching set. π
mwah, that's the whole page bestie π go forth and query your bits responsibly.
sending you off with love β this was Linux man-pages 6.20, dated 2026-02-08. slay, stay speculative, and always check errno π«Άβ¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2018, Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
- Copyright 2018, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms