Add x86_64-linux-gnu emulator
I wanted a tiny scriptable meltdown proof way to run userspace programs and visualize how program execution impacts memory. It helps to explain how things like Actually Portable Executable works. It can show you how the GCC generated code is going about manipulating matrices and more. I didn't feel fully comfortable with Qemu and Bochs because I'm not smart enough to understand them. I wanted something like gVisor but with much stronger levels of assurances. I wanted a single binary that'll run, on all major operating systems with an embedded GPL barrier ZIP filesystem that is tiny enough to transpile to JavaScript and run in browsers too. https://justine.storage.googleapis.com/emulator625.mp4
This commit is contained in:
@@ -33,17 +33,16 @@
|
||||
╠──────────────────────────────────────────────────────▌▀▄─▐──▀▄─▐▄─▐▄▐▄─▐▄─▐▄─│
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § post-initialization read-only │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
||||
#define getaddr(section) ((intptr_t)weakaddr(section))
|
||||
|
||||
static textstartup void __piro_protect(intptr_t start, intptr_t end, int prot) {
|
||||
static textstartup void _piro_protect(intptr_t start, intptr_t end, int prot) {
|
||||
ssize_t len = end - start;
|
||||
if (len > 0 && start && start % PAGESIZE == 0 && len % PAGESIZE == 0) {
|
||||
if (mprotect((void *)(unsigned long)start, len, prot) == -1) abort();
|
||||
@@ -62,10 +61,10 @@ static textstartup void __piro_protect(intptr_t start, intptr_t end, int prot) {
|
||||
* @see ape/ape.lds
|
||||
* @see libc/_start.S
|
||||
*/
|
||||
textstartup void __piro(int prot) {
|
||||
textstartup void _piro(int prot) {
|
||||
if (getaddr("main") < getaddr("__test_start")) {
|
||||
__piro_protect(getaddr("__test_start"), getaddr("__test_end"), PROT_NONE);
|
||||
_piro_protect(getaddr("__test_start"), getaddr("__test_end"), PROT_NONE);
|
||||
}
|
||||
__piro_protect(getaddr("__ro"), getaddr("_etext"), PROT_READ);
|
||||
__piro_protect(getaddr("__piro_start"), getaddr("__piro_end"), prot);
|
||||
_piro_protect(getaddr("__ro"), getaddr("_etext"), PROT_READ);
|
||||
_piro_protect(getaddr("__piro_start"), getaddr("__piro_end"), prot);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user