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:
Justine Tunney 2020-08-25 04:23:25 -07:00
parent 467504308a
commit f4f4caab0e
1052 changed files with 65667 additions and 7825 deletions

View file

@ -30,11 +30,12 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/ezmap.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/mappings.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/knuthmultiplicativehash.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/madv.h"
#include "libc/sysv/consts/map.h"
@ -53,7 +54,7 @@
* 50k+ lines of make code in ~80ms using one core and a meg of ram.
*/
static const char *const kSourceExts[] = {".s", ".S", ".c", ".cc", ".cpp"};
static const char kSourceExts[][5] = {".s", ".S", ".c", ".cc", ".cpp"};
static alignas(16) const char kIncludePrefix[] = "include \"";
static const char *const kModelessPackages[] = {
@ -141,7 +142,9 @@ void Rehash(void) {
uint32_t GetSourceId(const char *name, size_t len) {
size_t i, step;
uint32_t hash = Hash(name, len);
uint32_t hash;
i = 0;
hash = Hash(name, len);
if (sources.n) {
step = 0;
do {
@ -162,7 +165,7 @@ uint32_t GetSourceId(const char *name, size_t len) {
} while (sources.p[i].hash);
}
sources.p[i].hash = hash;
sources.p[i].name = concat(&strings, name, len);
sources.p[i].name = CONCAT(&strings.p, &strings.i, &strings.n, name, len);
strings.p[strings.i++] = '\0';
return (sources.p[i].id = g_sourceid++);
}
@ -248,7 +251,7 @@ const char *StripExt(const char *s) {
__cxa_atexit(free_s, &p, NULL);
}
i = 0;
CONCAT(&p, &i, &n, s, strlen(s));
CONCAT(&p, &i, &n, s, strlen(s) + 1);
dot = strrchr(p, '.');
if (dot) *dot = '\0';
return p;