PR_SET_MM_START_CODE(2const)

πŸ’– PR_SET_MM_START_CODE πŸ’–

okay bestie, gather round, because we're doing a prctl(2) const page and it's genuinely so niche and so iconic. this is from the Linux man-pages, section 2const, and it's all about tweaking the kernel's memory map descriptor fields. yes, the actual memory map. main character energy fr fr 🫢


✨ NAME ✨

PR_SET_MM_START_CODE, PR_SET_MM_END_CODE β€” modify kernel memory map descriptor fields πŸ’…


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc) β€” she's the standard, she's the blueprint 🌸


πŸŽ€ SYNOPSIS πŸŽ€

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

int prctl(PR_SET_MM, PR_SET_MM_START_CODE, unsigned long addr, 0L, 0L);
int prctl(PR_SET_MM, PR_SET_MM_END_CODE, unsigned long addr, 0L, 0L);

not me including <linux/prctl.h> just to get the PR_* constants, and then <sys/prctl.h> for the actual call like the little two-step it is πŸ˜­πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

πŸ’« PR_SET_MM_START_CODE

sets the address above which the program text is allowed to run, periodt.

the memory area in question has got to be readable and executable, but not writable and not shareable β€” no exceptions, no wiggle room. see mprotect(2) and mmap(2) if you want the receipts on those perms πŸ‘‘

πŸ’« PR_SET_MM_END_CODE

same vibe, opposite direction: sets the address below which the program text is allowed to run.

and yeah, same rule applies β€” that memory area must be readable and executable, but not writable or shareable. the vibe check is mandatory, bestie πŸ”₯

ngl, "must be readable and executable but not writable or shareable" is doing a LOT of heavy lifting here, so don't skip it πŸ™ˆ

🌈 RETURN VALUE 🌈

slay on success: 0 is returned ✨

not slay on error: -1 is returned, and errno is set to tell you exactly what went wrong πŸ’€


πŸ’œ ERRORS πŸ’œ

  • EINVAL β€” addr is greater than TASK_SIZE (that's the limit on the size of the user address space for this architecture). overshooting the whole address space?? rude 😭
  • EINVAL β€” the permissions of the corresponding memory area are not as required. girl, we said readable and executable, not writable or shareable. read the room πŸŽ€

⭐ STANDARDS ⭐

Linux. that's it, that's the standard πŸ‘‘


πŸ•°οΈ HISTORY πŸ•°οΈ

Linux 3.3. she's been around since 2012 and she's still here, lowkey an elder stateswoman at this point πŸ‘‘


πŸ‘€ SEE ALSO πŸ‘€

  • prctl(2) β€” go read the parent page, it's giving the whole family tree 🌸

and that's the whole thing, bestie!! you ate. πŸ’…

this little cutie comes to you courtesy of Linux man-pages 6.20, dated 2026-02-08 β€” so you know it's fresh πŸ“πŸ¦‹ mwah, go forth and prctl responsibly 🫢✨

πŸ“¦ 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