memprotect

Number0x37
Signature(addr, size, prot) -> 0 or -err
Groupmemory
Since1.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

RegisterNameDescription
r0addrBase of the range. Must be page-aligned and in user space
r1sizeLength in bytes. Non-zero and a multiple of `PAGE_SIZE`
r2prot`VM_PROT_READ` / `VM_PROT_WRITE` / `VM_PROT_EXEC` only. W^X enforced

Returns

0 on success.

Errors

CodeCondition
ERR_BADARGSize 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`

See also