Created
March 20, 2026 20:26
-
-
Save billywhizz/a36f1349972d5182af5ecd0cfda61c3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| clang -I. -c -o bundle.o bundle.c | |
| clang -c -o builtins.o builtins.S | |
| clang -static -s -O3 -o build/fire bundle.o builtins.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .global _init_start | |
| _init_start: | |
| .incbin "build/initrd.cpio" | |
| .global _init_end | |
| _init_end: | |
| .global _firecracker_start | |
| _firecracker_start: | |
| .incbin "build/firecracker" | |
| .global _firecracker_end | |
| _firecracker_end: | |
| .global _vmlinux_start | |
| _vmlinux_start: | |
| .incbin "build/vmlinux" | |
| .global _vmlinux_end | |
| _vmlinux_end: | |
| .global _config_start | |
| _config_start: | |
| .incbin "fire_mem.json" | |
| .global _config_end | |
| _config_end: | |
| .section .note.GNU-stack,"",@progbits |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define _GNU_SOURCE | |
| #define _POSIX_C_SOURCE 200809L | |
| #include <stdio.h> | |
| #include <sys/mman.h> | |
| #include <unistd.h> | |
| #include <sys/types.h> | |
| #include <linux/memfd.h> | |
| #include <stdlib.h> | |
| extern unsigned char _firecracker_start[]; | |
| extern unsigned char _firecracker_end[]; | |
| extern unsigned char _vmlinux_start[]; | |
| extern unsigned char _vmlinux_end[]; | |
| extern unsigned char _init_start[]; | |
| extern unsigned char _init_end[]; | |
| extern unsigned char _config_start[]; | |
| extern unsigned char _config_end[]; | |
| int main (int argc, char** argv) { | |
| unlink("./fire.sock"); | |
| unlink("./v.sock"); | |
| unsigned int _firecracker_len = _firecracker_end - _firecracker_start; | |
| unsigned char* out = _firecracker_start; | |
| int fc_fd = memfd_create("/memfd/firecracker", 0 | MFD_CLOEXEC); | |
| if (fc_fd <= 0) exit(1); | |
| int written = write(fc_fd, out, _firecracker_len); | |
| if (written < _firecracker_len) exit(2); | |
| unsigned int _vmlinux_len = _vmlinux_end - _vmlinux_start; | |
| out = _vmlinux_start; | |
| int vm_fd = memfd_create("/memfd/vmlinux", 0); | |
| if (vm_fd <= 0) exit(3); | |
| written = write(vm_fd, out, _vmlinux_len); | |
| if (written < _vmlinux_len) exit(4); | |
| unsigned int _init_len = _init_end - _init_start; | |
| out = _init_start; | |
| int init_fd = memfd_create("/memfd/init", 0); | |
| if (init_fd <= 0) exit(5); | |
| written = write(init_fd, out, _init_len); | |
| if (written < _init_len) exit(6); | |
| unsigned int _config_len = _config_end - _config_start; | |
| int config_fd = memfd_create("/memfd/config", 0); | |
| if (config_fd <= 0) exit(7); | |
| written = write(config_fd, _config_start, _config_len); | |
| if (written < _config_len) exit(8); | |
| char** args = (char**)calloc(10, 8); | |
| args[0] = "firecracker"; | |
| args[1] = "--config-file"; | |
| args[2] = "/proc/self/fd/6"; | |
| args[3] = "--boot-timer"; | |
| args[4] = "--level"; | |
| args[5] = "warn"; | |
| args[6] = "--api-sock"; | |
| args[7] = "./fire.sock"; | |
| args[8] = "--no-seccomp"; | |
| args[9] = 0; | |
| char *env[] = { NULL }; | |
| return fexecve(fc_fd, args, env); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "boot-source": { | |
| "kernel_image_path": "/proc/self/fd/4", | |
| "boot_args": "rw devtmpfs.mount=0 nohz=off i915.modeset=0 nouveau.modeset=0 clocksource=kvm-clock i8042.noaux i8042.nomux i8042.nopnp i8042.nokbd reboot=hard no_timer_check cryptomgr.notests tsc=reliable 8250.nr_uarts=1 iommu=off mitigations=off random.trust_cpu=on panic=-1 console=ttyS0,115200 rootfstype=ramfst quiet", | |
| "initrd_path": "/proc/self/fd/5" | |
| }, | |
| "machine-config": { | |
| "vcpu_count": 1, | |
| "mem_size_mib": 128, | |
| "track_dirty_pages": false, | |
| "huge_pages": "None" | |
| }, | |
| "drives": [{ | |
| "drive_id": "root", | |
| "path_on_host": "fire.ext4", | |
| "is_root_device": false, | |
| "is_read_only": false | |
| }], | |
| "network-interfaces": [{ | |
| "iface_id": "eth0", | |
| "guest_mac": "02:FC:00:00:00:05", | |
| "host_dev_name": "tap0" | |
| }], | |
| "vsock": { | |
| "guest_cid": 3, | |
| "uds_path": "./v.sock" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment