Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lmangani/vmemfd
memfd_create elf execution in v
https://github.com/lmangani/vmemfd
elf memfd v vlang
Last synced: 11 days ago
JSON representation
memfd_create elf execution in v
- Host: GitHub
- URL: https://github.com/lmangani/vmemfd
- Owner: lmangani
- License: mit
- Created: 2022-09-13T10:55:03.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-07T13:16:15.000Z (about 2 years ago)
- Last Synced: 2024-10-04T13:22:01.181Z (about 1 month ago)
- Topics: elf, memfd, v, vlang
- Language: C
- Homepage:
- Size: 232 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vmemfd
Experimental [`memfd_create`](https://man7.org/linux/man-pages/man2/memfd_create.2.html) ELF execution prototype in [`vlang`](https://vlang.io)
#### [`memfd_create`](https://man7.org/linux/man-pages/man2/memfd_create.2.html)
> 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.## Goals
- [x] memfd based ELF execution in v
- [x] c module exporting [`memfd_create`](https://man7.org/linux/man-pages/man2/memfd_create.2.html)
- [ ] use `$embed_file` _for files < 20Mb_
- [ ] self-extracting binary decompressing to `memfd` pointer## Gist
```cimport 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
}
```## Test
Compile an ELF binary expecting args _(or bring your own)_
```bash
v -o app -prod app.v
```Load and execute ELF using `memdfd`
```bash
v run vload.v test me
```