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 by PR_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 as PR_SPEC_DISABLE but it cannot be undone. no take-backs. periodt. πŸ’€
  • PR_SPEC_DISABLE_NOEXEC (since Linux 5.1) β€” same as PR_SPEC_DISABLE, but the state gets cleared on execve(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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms