MPROTECT(2)

πŸ’… MPROTECT(2) β€” it's giving "system calls manual" ✨

okay bestie, welcome to mprotect β€” the System Calls Manual page that lets you change what your memory is allowed to do. protection? we're controlling it. periodt.


πŸŽ€ NAME πŸŽ€

mprotect β€” control the protection of pages


πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc)


✨ SYNOPSIS ✨

#include <sys/mman.h>

int
mprotect(void *addr, size_t len, int prot);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like. the mprotect() system call changes the specified pages so they have protection prot. that's the whole vibe. πŸ”₯

ngl tho, not every implementation is gonna guarantee protection on a page basis β€” the granularity of protection changes can be as large as an entire region. and a region? it's the virtual address space defined by the start and end addresses of a struct vm_map_entry. iykyk.

currently these protection bits are known, and you can combine them, OR'd together:

  • PROT_NONE β€” No permissions at all. literally none. πŸ™ˆ
  • PROT_READ β€” The pages can be read.
  • PROT_WRITE β€” The pages can be written.
  • PROT_EXEC β€” The pages can be executed.

πŸ’– RETURN VALUES πŸ’–

the mprotect() function returns the value 0 if successful β€” slay. otherwise the value -1 is returned and the global variable errno is set to indicate the error. not slay. 😭


πŸ’€ ERRORS πŸ’€

the mprotect() system call will fail if:

  • [EACCES] β€” The calling process was not allowed to change the protection to the value specified by the prot argument. bestie you do NOT have permission πŸ’…
  • [EINVAL] β€” The virtual address range specified by the addr and len arguments is not valid.

🌈 SEE ALSO 🌈

madvise(2), mincore(2), msync(2), munmap(2)


πŸ‘‘ HISTORY πŸ‘‘

the mprotect() system call first appeared in 4.4BSD. iconic behavior, honestly. ⭐


🫢 and that's the whole page, bestie!! this one's from Debian, dated August 3, 2016 β€” go protect some pages, main character energy only. πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from