Crate memory_pages
source ·Expand description
memory_pages
is a small crate providing a cross-platform API to request pages from kernel with certain permission modes
set(read,write,execute). It provides an very safe API to aid in many use cases, mainly:
- Speeds up operating on large data sets:
PagedVec
provides allocation speed advantages over standardVec
for large data. types. - Page alignment guarantee. Since the API returns memory pages, the first address inside
Pages
must be aligned to a page boundary. This means, that with a bit of careful selection of type sizes(powers of 2), a substantial speedup can be occurred(structures can be guaranteed to always reside entirely within 1 page). Those sorts of guarantees are not normally given by allocators. - Simplifies dealing with page permissions and allows for additional levels of safety: Pages with
DenyWrite
cannot be written into without their permissions being changed, which allows for certain kinds of bugs to cause segfaults insted of overwriting data. - Simplifies JITs - while dealing with memory pages is simple compared to difficulty of the task, which is writing a Just-In-Time compiler, this crate abstracts the platform specific differences away and adds additional measures to prevent some security issues, allowing you to focus on writing the compiler itself, without worrying about those low-level details.
Features
allow_exec
- this feature allows access to everything related to executing code inside allocated pages. Off by default.
deny_xw
- default feature that prevents allowing both eXecution
and Write
permissions on a page. This is an additional security feature that prevents accidental misuse of the API-s locked behind allow_exec
feature. Does noting without it, but is really usefull when allow_exec
enabled.
Structs
- Marks
Pages
as allowing execution. WARNING do NOT set this permission if not necessary! - Marks
Pages
as allowing to be read from. - Marks
Pages
as allowing to be modified. - Prevents data inside
Pages
from being executed. Do NOT change from this value if not 100% sure what you are doing. - Marks
Pages
as forbidding all reads(causing SIGSEGV if read attempted). - Marks
Pages
as forbidding all writes(causing SIGSEGV if write attempted). - A reference to a function inside
Pages
. It enforces that it may never outlive thePages
it is contained in, preventing lifetime related errors. Additionally, it enforces that ifPages
permissions are changes, allFnRef
referencing it will be invalidated, preventing exploits related to page permissions.