memfd_exec
This is a very simple crate that allows execution of in-memory only programs. Simply
put, if you have the contents of a Linux executable in a Vec<u8>, you can use
memfd_exec to execute the program without it ever touching your hard disk. Use
cases for this may include:
- Bundling a static executable with another program (for example, my motivation to create this package is that I want to ship a statically built QEMU with cantrace)
- Sending executables over the network and running them, to reduce footprint and increase throughput
- Really hacky stuff that I haven't thought of, if you have a cool use case, feel free to make a PR to the README or add an example in examples
Using
Just include memfd-exec = "VERSION" in your Cargo.toml file.
Features
- Feature-parity API with
process::Command, the only difference is we don't execute anything from disk. - Only two dependencies
Example
The motivating example for this project is to bundle an executable along with a rust program and be able to run the executable straight from memory instead of going through the tedious and slow process of writing the executable file to disk and then invoking it as a command.
This example creates an executable with a bundled program that opens a socket, reads a bit of input, and then prints out the input. Of course, the logical extension of the idea would be to use a static netcat build or some such thing.
use ;
const EXECUTABLE_FILE: & = include_bytes!;