user3475234
user3475234

Reputation: 1573

C - Is it possible to mprotect something less than a page

And I'm really looking for any solution to this - my goal is to set an area smaller than the system's page size to PROT_READ, PROT_WRITE, PROT_EXEC or PROT_NONE. Is this possible? It seems mprotect just protects a multiple of the page size...

If it's not possible, what's the reason for this design choice?

Upvotes: 3

Views: 1854

Answers (1)

This is generally not possible.

The protection attribute is set in the page tables of the CPU, so this is a CPU design decision.

If you just need this sub-page protection for one particular area, I believe there are ways to set up a hardware memory access break-point, which will trigger if that area is accessed.

Upvotes: 5

Related Questions