Does Rust work with RAM applications, if so, please show an example
What do you mean with "RAM applications"?
values in the app's memory
It is still not clear to me. Why would it not be supported to store values in the memory of a program?
In general, all Rust programs store almost all their values in RAM. (The main exception is that some values are temporarily stored in registers, but this only applies to a tiny fraction of the program's data at any point in time.)
Do you mean storing a another program in a Rust program's memory, and then running it from there?
You can use the
mprotect() function from the
nix crate to mark memory as executable on Linux. Windows will have a similar API, but I don't know it off the top of my head.
Keep in mind that this sort of behaviour isn't normally recommended when there are alternatives (e.g. saving the executable to a file on disk). Marking memory as executable can be a security risk and you may be blocked by antivirus software.
You'll need to write/use a custom loader that is capable of loading an executable from memory. (Unless it's a position independent payload without use of external libraries)
If you can take the performance hit you could compile your code to WASM. Then load that WASM into RAM and run it from your Rust application with WASMER: https://wasmer.io. Your own little sand box.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.