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

68
tool/build/lib/buffer.c Normal file
View file

@ -0,0 +1,68 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/calls/calls.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/mem.h"
#include "libc/str/tpencode.h"
#include "tool/build/lib/buffer.h"
void AppendChar(struct Buffer *b, char c) {
APPEND(&b->p, &b->i, &b->n, &c);
}
void AppendData(struct Buffer *b, char *data, size_t len) {
CONCAT(&b->p, &b->i, &b->n, data, len);
}
void AppendStr(struct Buffer *b, const char *s) {
AppendData(b, s, strlen(s));
}
void AppendWide(struct Buffer *b, wint_t wc) {
char cbuf[8];
AppendData(b, cbuf, tpencode(cbuf, 8, wc, false));
}
void AppendFmt(struct Buffer *b, const char *fmt, ...) {
int size;
char *tmp;
va_list va;
tmp = NULL;
va_start(va, fmt);
size = vasprintf(&tmp, fmt, va);
va_end(va);
if (size != -1) AppendData(b, tmp, size);
free(tmp);
}
/**
* Writes buffer until completion, interrupt, or error occurs.
*/
ssize_t WriteBuffer(struct Buffer *b, int fd) {
size_t i;
ssize_t rc;
for (i = 0; i < b->i; i += rc) {
if ((rc = write(fd, b->p + i, b->i - i)) == -1) {
return -1;
}
}
return i;
}