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:
PagedVecprovides allocation speed advantages over standardVecfor large data. types. - Page alignment guarantee. Since the API returns memory pages, the first address inside
Pagesmust 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
DenyWritecannot 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
Pagesas allowing execution. WARNING do NOT set this permission if not necessary! - Allow
Read - Marks
Pagesas allowing to be read from. - Allow
Write - Marks
Pagesas allowing to be modified. - Deny
Exec - Prevents data inside
Pagesfrom being executed. Do NOT change from this value if not 100% sure what you are doing. - Deny
Read - Marks
Pagesas forbidding all reads(causing SIGSEGV if read attempted). - Deny
Write - Marks
Pagesas forbidding all writes(causing SIGSEGV if write attempted). - FnRef
- A reference to a function inside
Pages. It enforces that it may never outlive thePagesit is contained in, preventing lifetime related errors. Additionally, it enforces that ifPagespermissions are changes, allFnRefreferencing 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
Pagesrepresents 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 givenPagesmay be changed at runtime.
Traits§
- Exec
Premision Marker - Marks if native CPU instructions stored inside
Pagescan jumped to and executed. - Read
Premision Marker - Marks if a
Pagescan be read from. - Unsafe
Callable - Trait representing an unsafe function that may be called.
- Write
Premision Marker - Marks if a
Pagescan be written into.