PR_SET_SPECULATION_CTRL(2const)

✨ PR_SET_SPECULATION_CTRL ✨

okay bestie, so this one is PR_SET_SPECULATION_CTRL from the (2const) girlies β€” it lives in the land of prctl(2) constants, and it's literally the "set the state of a speculation misfeature for the calling thread" page. yes, per-thread. yes, that matters. πŸ’…


🌸 LIBRARY 🌸

Standard C library (libc, -lc). the classic. the icon. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <linux/prctl.h>  /* Definition of PR_* constants */
#include <sys/prctl.h>

int prctl(PR_SET_SPECULATION_CTRL, long misfeature, long val, 0L, 0L);

note how those last two args are just 0L and 0L, they're not doing anything, they're just there for the vibe. okay not for the vibe, for the API. whatever. ✨


πŸ’– DESCRIPTION πŸ’–

So what it does: it sets the state of the speculation misfeature that you name in misfeature. And the important lil detail β€” these speculation-misfeature settings are per-thread attributes. not global. not per-process. per. thread. okay? periodt. πŸ‘‘

Right now, misfeature has to be one of these two besties:

  • PR_SPEC_STORE_BYPASS β€” sets the state of the speculative store bypass misfeature.
  • PR_SPEC_INDIRECT_BRANCH (since Linux 4.20) β€” sets the state of the indirect branch speculation misfeature.

Then there's the val argument, which is where you hand in the actual control value. and val is one of these:

  • PR_SPEC_ENABLE β€” the speculation feature is enabled, mitigation is disabled. (living dangerously, we love a bold choice 🫢)
  • PR_SPEC_DISABLE β€” the speculation feature is disabled, mitigation is enabled. (safe queen behavior πŸ’…)
  • PR_SPEC_FORCE_DISABLE β€” same as PR_SPEC_DISABLE, but it cannot be undone. no takebacks. no regrets. it's giving irreversible. πŸ’€
  • PR_SPEC_DISABLE_NOEXEC (since Linux 5.1) β€” same as PR_SPEC_DISABLE, but the state will be cleared on execve(2). And heads up β€” this one is currently only supported for PR_SPEC_STORE_BYPASS.

Alsooo, the speculation feature can also be controlled by the spec_store_bypass_disable boot parameter. And plot twist: this parameter may enforce a read-only policy, which will result in the prctl() call failing with the error ENXIO. For further details, see the kernel source file Documentation/admin-guide/kernel-parameters.rst.


🌈 RETURN VALUE 🌈

Slay: on success, 0 is returned. On error, -1 is returned, and errno is set to indicate the error. that's the whole story bestie. 😌


πŸ’œ ERRORS πŸ’œ

  • ENODEV β€” the kernel or CPU does not support the requested speculation misfeature. (they simply don't have it in them πŸ™ˆ)
  • ENXIO β€” the control of the selected speculation misfeature is not possible. See PR_GET_SPECULATION_CTRL for the bit fields to determine which option is available. πŸ‘€
  • EPERM β€” the speculation was disabled with PR_SPEC_FORCE_DISABLE and the caller tried to enable it again. yeah… that's the irreversible thing from earlier. told you. πŸ’€
  • ERANGE β€” misfeature is not a valid value.

⭐ STANDARDS ⭐

Linux. that's it, that's the standard. 🐧


πŸŽ€ HISTORY πŸŽ€

Linux 4.17.


🧚 SEE ALSO 🧚


okay that's the whole page bestie, you ate that 🫢 stay speculative, stay per-thread, and remember: PR_SPEC_FORCE_DISABLE is forever. mwah. πŸ’–

this has been a Linux man-pages 6.20 moment, dated 2026-02-08, brought to you by the PR_SET_SPECULATION_CTRL(2const) girlies. no cap. ✨
πŸ“¦ 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