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§
- Allow
Exec - Marks
Pages
as allowing execution. WARNING do NOT set this permission if not necessary! - Allow
Read - Marks
Pages
as allowing to be read from. - Allow
Write - Marks
Pages
as allowing to be modified. - Deny
Exec - Prevents data inside
Pages
from being executed. Do NOT change from this value if not 100% sure what you are doing. - Deny
Read - Marks
Pages
as forbidding all reads(causing SIGSEGV if read attempted). - Deny
Write - Marks
Pages
as forbidding all writes(causing SIGSEGV if write attempted). - FnRef
- 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. - Paged
Vec - A
Vec
-like type located in memory pages acquired directly from the kernel. For big lengths a faster to allocate/deallocate than a normalVec
, but considerably slower for small sizes. Intended to be used for very large data sets, with a rough estimate of capacity known ahead of time. - Pages
Pages
represents a collection of pages acquired from the kernel. Those pages share a common set of permissions and are laid out contiguously in the memory. The permissions on givenPages
may be changed at runtime.
Traits§
- Exec
Premision Marker - Marks if native CPU instructions stored inside
Pages
can jumped to and executed. - Read
Premision Marker - Marks if a
Pages
can be read from. - Unsafe
Callable - Trait representing an unsafe function that may be called.
- Write
Premision Marker - Marks if a
Pages
can be written into.