memprotect
| Number | 0x37 |
|---|---|
| Signature | (addr, size, prot) -> 0 or -err |
| Group | memory |
| Since | 1.0 |
Change the protection of an existing mapping. Unlike memunmap, this is a true range
operation: it takes an address and a length, and works at page granularity rather than
requiring a whole region.
The kernel ORs in VM_PROT_USER itself. Passing that bit explicitly is rejected.
Pitfalls
W^X is enforced here as well as at memmap, so a region cannot be made writable and
executable by mapping it one way and reprotecting it another.
The underlying reprotect returns only success or failure, so every reason a range may be
refused — pinned or guard regions, spanning more than one region, changing a device mapping —
arrives as a single ERR_BADARG. The code does not distinguish them.
Arguments
| Register | Name | Description |
|---|---|---|
r0 | addr | Base of the range. Must be page-aligned and in user space |
r1 | size | Length in bytes. Non-zero and a multiple of `PAGE_SIZE` |
r2 | prot | `VM_PROT_READ` / `VM_PROT_WRITE` / `VM_PROT_EXEC` only. W^X enforced |
Returns
0 on success.
Errors
| Code | Condition |
|---|---|
ERR_BADARG | Size of 0 or not a page multiple; range not valid user memory; W+X requested; or the range could not be reprotected |
ERR_NOPERM | `prot` contains bits outside READ/WRITE/EXEC, including `VM_PROT_USER` |