Experimental memfd_create
ELF execution prototype in vlang
memfd_create() creates an anonymous file and returns a file descriptor that refers to it. The file behaves like a regular file, and so can be modified, truncated, memory-mapped, and so on. However, unlike a regular file, it lives in RAM and has a volatile backing storage. Once all references to the file are dropped, it is automatically released. Anonymous memory is used for all backing pages of the file.
- memfd based ELF execution in v
- c module exporting
memfd_create
- c module exporting
- use
$embed_file
for files < 20Mb - self-extracting binary decompressing to
memfd
pointer
import lmangani.memfd
// Read binary ELF
data := os.read_file(filename) or {
panic('error reading elf $filename')
return
}
// Allocate a memfd MFD_CLOEXEC and write ELF
fd_id := memfd.vmemfd_new('myapp')
os.fd_write(fd_id, data)
// Execute w/ arguments from memfd
pointer := '/proc/self/fd/$fd_id'
os.execve(pointer, args, []) or {
panic('error executing $pointer')
return
}
Compile an ELF binary expecting args (or bring your own)
v -o app -prod app.v
Load and execute ELF using memdfd
v run vload.v test me