Atharva
Atharva

Reputation: 43

Alternatives to mprotect()

The mprotect syscall protects the memory area within page boundary:

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

Here len should be multiple of pagesize.

Is there any way to protect only a few consecutive addresses, which are not aligned to page boundary i.e. len < pagesize ?

Upvotes: 4

Views: 1309

Answers (3)

SimonZC
SimonZC

Reputation: 59

I think the below link is what U would expect, but U have to wait for it to release.

https://software.intel.com/en-us/blogs/2013/07/22/intel-memory-protection-extensions-intel-mpx-support-in-the-gnu-toolchain

"MPX —— Intel® Memory Protection Extensions" is what all C++ programmers want. I am very looking forward to it.

Upvotes: 0

unwind
unwind

Reputation: 399949

I wouldn't think so, no. The limitation is because the MMU has hardware limits on how fine a granularity it can control. There are tables that hold the access restrictions and you can't have a table slot for each byte; the table itself would use all your RAM. So instead it's made more coarse, with table entries for each page.

You might be able to do something using Valgrind, if you're on Linux.

Upvotes: 5

Greg Hewgill
Greg Hewgill

Reputation: 993881

No, there isn't. The virtual memory system of your OS only operates on the page level, nothing smaller than that.

Upvotes: 1

Related Questions