Crates.io | vonneumann |
lib.rs | vonneumann |
version | 1.0.2 |
source | src |
created_at | 2024-01-27 19:47:20.290289 |
updated_at | 2024-01-29 17:31:24.257042 |
description | executable memory for windows and unix |
homepage | |
repository | https://github.com/jyn514/Von-Neumann |
max_upload_size | |
id | 1116943 |
size | 17,839 |
executable memory for windows and unix ("von Neumann architecture")
use vonneumann::ExecutableMemory;
fn main() {
let mut memory = ExecutableMemory::new(6);
// https://www.felixcloutier.com/x86/
memory[0] = 0xb8;
memory[1] = 0xff;
memory[2] = 0xff;
memory[3] = 0xff;
memory[4] = 0xff;
memory[5] = 0xc3;
let f: fn() -> u32 = unsafe {
std::mem::transmute((&memory[0..6]).as_ptr())
};
assert_eq!(f(), 4294967295);
}
jit-allocator
this crate maps pages as RWX. this is somewhat insecure and makes it easier to escalate security vulns. jit-allocator
"dual maps" pages as RX and RW, avoiding this issue.
this crate always allocates full pages, which is inefficient for small allocations, and slow if you allocate frequently. jit-allocator
can return byte-level allocations instead.
this crate supports the Allocator
API when --features nightly
is enabled. as a result, it can be used with Vec
, and using it requires less unsafe (basically just the transmute to turn the data into a function pointer). jit-allocator inherently cannot do this because it uses dual-mapping.
memfd-exec
memfd-exec
serves a different purpose altogether: it executes whole processes. this crate is for executing individual functions that share your process state.
this crate automatically unmaps the memory for you on drop, and supports windows as well as unix.
unlike memmap2
you can have the memory be executable and writable at the same time :ferrisClueless:
yes! https://github.com/chellipse/bf-jit
yes!
no???? the man page literally says "MAP_JIT regions are never writeable and executable simultaneously" lol
if someone wants this i can imagine an api that forces you to call make_mut
and make_exec
separately though. i am not doing dual-mapping. no.
probably but i haven't tested 🤪
lol please do i want to watch your code burn
as a reminder THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED