arch_prctl(2)
πΈ arch_prctl(2) β the vibe-coded deep lore of architecture-specific thread state πΈ
okay bestie, pull up a chair π«Ά this one lives in the System Calls Manual, and it's giving seriously x86-flavored main character energy. It's arch_prctl, and it's the little syscall that handles your architecture-specific process/thread state. Buckle up, it's a niche icon but a legend π
β¨ NAME β¨
arch_prctl β set architecture-specific thread state
π LIBRARY π
Standard C library (libc, -lc)
π SYNOPSIS π
#include <asm/prctl.h> /* Definition of ARCH_* constants */
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
int syscall(SYS_arch_prctl, int op, unsigned long addr);
int syscall(SYS_arch_prctl, int op, unsigned long *addr);
not me having to say this but: glibc provides no wrapper forarch_prctl(), so you gotta go throughsyscall(2). no shortcut bestie, that's just how it is π
π DESCRIPTION π
arch_prctl() sets architecture-specific process or thread state. The op argument picks which operation you want, and it passes addr along to it. And here's the twist: addr gets interpreted two different ways β as an unsigned long for the "set" operations, or as an unsigned long * for the "get" operations. iykyk π
π Subfunctions for both x86 and x86-64 π
ARCH_SET_CPUID(since Linux 4.12) β Enable (addr != 0) or disable (addr == 0) thecpuidinstruction for the calling thread. It's enabled by default, obviously, she's born ready. But if you disable it, any execution of acpuidinstruction will instead generate aSIGSEGVsignal π (yes, really, that's the vibe check failing HARD). This feature can be used to emulatecpuidresults that differ from what the underlying hardware would have produced β like, say, in a paravirtualization setting. Iconic use case fr fr.
The ARCH_SET_CPUID setting is preserved across fork(2) and clone(2), but gets reset to the default (i.e., cpuid enabled) on execve(2). So it survives the split but not the glow-up, periodt.
ARCH_GET_CPUID(since Linux 4.12) β Returns the setting of the flag thatARCH_SET_CPUIDmanipulates, as the result of the system call (1for enabled,0for disabled). Andaddr? ignored. completely, don't even worry about it π
π¦ Subfunctions for x86-64 only π¦
ARCH_SET_FSβ Set the 64-bit base for theFSregister toaddr.ARCH_GET_FSβ Return the 64-bit base value for theFSregister of the calling thread, written into theunsigned longpointed to byaddr.ARCH_SET_GSβ Set the 64-bit base for theGSregister toaddr.ARCH_GET_GSβ Return the 64-bit base value for theGSregister of the calling thread, written into theunsigned longpointed to byaddr.
β RETURN VALUE β
On success, arch_prctl() returns 0. On error, -1 is returned, and errno is set to indicate the error. simple as that bestie πΈ
π ERRORS π
EFAULTβaddrpoints to an unmapped address or is outside the process address space. lost in the void, no address, no vibes πEINVALβopis not a valid operation. wrong op, we don't know her πENODEVβARCH_SET_CPUIDwas requested, but the underlying hardware does not support CPUID faulting. the hardware said "not today" π«EPERMβaddris outside the process address space. permission denied, she's not on the guest list β
π STANDARDS π
Linux/x86-64. That's the whole mood board, no more, no less π
π§ NOTES π§
arch_prctl()is supported only on Linux/x86-64 for 64-bit programs currently. yeah. that's the whole guest list right now bestie.- The 64-bit base changes when a new 32-bit segment selector is loaded.
ARCH_SET_GSis disabled in some kernels. so... check before you yeet, okay?- Context switches for 64-bit segment bases are rather expensive. As an optimization, if a 32-bit TLS base address is used,
arch_prctl()may use a real TLS entry as ifset_thread_area(2)had been called, instead of manipulating the segment base register directly. And heads up: memory in the first2 GBof address space can be allocated by usingmmap(2)with theMAP_32BITflag. slay for memory management π - Because of that whole optimization situation, using
arch_prctl()andset_thread_area(2)in the same thread is dangerous, as they may overwrite each other's TLS entries. not them fighting for the same spotlight π FSmay already be used by the threading library. Programs that useARCH_SET_FSdirectly are very likely to crash. like, catastrophic flop energy. don't do it unless you're truly built different.
π SEE ALSO π
AMD X86-64 Programmer's manual π
and that's the whole manpage bestie, go forth and set some architecture-specific thread state responsibly πβ¨ remember: this was brought to you by Linux man-pages 6.20, dated 2026-02-08, for arch_prctl(2). love her, respect her, don't crash your process with ARCH_SET_FS ππ¦π
π¦ 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 2003, Andi Kleen <andi@firstfloor.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms