subpage_prot(2)
π subpage_prot(2) β the girlies' guide to subpage protection π
okay so bestie, this one lives in the System Calls Manual section 2, and it's genuinely one of the most niche-but-iconic syscalls out there. it's subpage_prot(2) and it's giving PowerPC main character energy. let's get into it π¦
β¨ NAME β¨
subpage_prot β define a subpage protection for an address range
π LIBRARY π
Standard C library (libc, -lc)
πΈ SYNOPSIS πΈ
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
int syscall(SYS_subpage_prot, unsigned long addr, unsigned long size,
uint32_t *map);
heads up bestie: glibc provides no wrapper forsubpage_prot(), so you literally have no choice but to go throughsyscall(2). no shortcuts, no cozy little libc hug. it's giving raw-dogging the syscall interface π
π DESCRIPTION π
The PowerPC-specific subpage_prot() system call is the girl that lets you control access permissions on individual 4 kB subpages β but only on systems configured with a page size of 64 kB. so like, tiny granularity on top of chunky pages. obsessed.
The protection map gets applied to the memory pages in the region starting at addr and continuing for size bytes. and no cap, both of these arguments must be aligned to a 64-kB boundary. non-negotiable.
The protection map itself is specified in the buffer pointed to by map. here's the tea:
- the map has 2 bits per 4 kB subpage
- so each 32-bit word specifies the protections of 16 4 kB subpages inside a 64 kB page (which means the number of 32-bit words pointed to by
mapshould equate to the number of 64-kB pages specified bysize) - each 2-bit field in the protection map is:
0to allow any access1to prevent writes2or3to prevent all accesses
like, two bits doing all that work?? underrated fr fr π«Ά
π₯ RETURN VALUE π₯
On success, subpage_prot() returns 0. Otherwise, one of the error codes specified below is returned. slay when it works, π when it doesn't.
π ERRORS π
EFAULTβ The buffer referred to bymapis not accessible. (she's not there bestie, the pointer is reaching into the void π)EINVALβ Theaddrorsizearguments are incorrect. Both of these arguments must be aligned to a multiple of the system page size, and they must not refer to a region outside of the address space of the process or to a region that consists of huge pages.ENOMEMβ Out of memory. the classic. the eternal. β¨
π STANDARDS π
Linux.
π HISTORY π
Linux 2.6.25 (PowerPC).
The system call is provided only if the kernel is configured with CONFIG_PPC_64K_PAGES. so if your kernel didn't opt in, this call literally does not exist for you. vibe check failed, sorry babe π
π§ NOTES π§
Normal page protections (at the 64-kB page level) also apply. the subpage protection mechanism is an additional constraint, not an override. so putting 0 in a 2-bit field won't allow writes to a page that is otherwise write-protected.
important!! do not read that as "0 means anything goes". it means "this layer says yes, but the layer above might still say no". stacking rules, bestie. permissions are an intersection, not a replacement π
π¦ Rationale π¦
This system call is provided to assist writing emulators that operate using 64-kB pages on PowerPC systems. when emulating systems such as x86, which uses a smaller page size, the emulator can no longer use the memory-management unit (MMU) and normal system calls for controlling page protections. (the emulator could emulate the MMU by checking and possibly remapping the address for each memory access in software, but that is slow. like, painfully slow. not the move. π)
So the idea is that the emulator supplies an array of protection masks to apply to a specified range of virtual addresses. These masks are applied at the level where hardware page-table entries (PTEs) are inserted into the hardware page table based on the Linux PTEs β so the Linux PTEs are not affected. β¨
Implicit in this is that the regions of the address space that are protected are switched to use 4-kB hardware pages rather than 64-kB hardware pages (on machines with hardware 64-kB page support). the girl is literally shapeshifting the page size behind the scenes, and honestly? iconic. π₯
π SEE ALSO π
mprotect(2)syscall(2)Documentation/admin-guide/mm/hugetlbpage.rstin the Linux kernel source tree
aaaand that's the whole page bestie!! this one came from Linux man-pages 6.20, dated 2026-02-08, and it's the subpage_prot(2) entry, periodt. go forth and protect your subpages responsibly, ily π«Άπβ¨
π¦ 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 2010, 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