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

@ -18,6 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/conv/conv.h"
#include "libc/dns/dns.h"
#include "libc/dns/hoststxt.h"
@ -25,12 +26,11 @@
#include "libc/mem/mem.h"
#include "libc/sock/sock.h"
#include "libc/str/str.h"
#include "libc/calls/calls.h"
#include "libc/sysv/errfuns.h"
#include "libc/sysv/consts/af.h"
#include "libc/sysv/consts/ai.h"
#include "libc/sysv/consts/eai.h"
#include "libc/sysv/consts/inaddr.h"
#include "libc/sysv/errfuns.h"
/**
* Resolves address for internet name.
@ -44,20 +44,15 @@
*/
int getaddrinfo(const char *name, const char *service,
const struct addrinfo *hints, struct addrinfo **res) {
int port = 0;
int rc, port;
const char *canon;
struct addrinfo *ai;
if ((!name && !service) || (service && (port = parseport(service)) == -1)) {
return EAI_NONAME;
}
if (!name && (hints->ai_flags & AI_CANONNAME) == AI_CANONNAME) {
return EAI_BADFLAGS;
}
if (!(ai = newaddrinfo(port))) {
return EAI_MEMORY;
}
if (service) {
ai->ai_addr4->sin_port = htons(port);
}
port = 0;
if (!name && !service) return EAI_NONAME;
if (service && (port = parseport(service)) == -1) return EAI_NONAME;
if (!name && (hints->ai_flags & AI_CANONNAME)) return EAI_BADFLAGS;
if (!(ai = newaddrinfo(port))) return EAI_MEMORY;
if (service) ai->ai_addr4->sin_port = htons(port);
if (hints) {
ai->ai_socktype = hints->ai_socktype;
ai->ai_protocol = hints->ai_protocol;
@ -69,7 +64,6 @@ int getaddrinfo(const char *name, const char *service,
: INADDR_LOOPBACK;
return 0;
}
const char *canon;
if (inet_pton(AF_INET, name, &ai->ai_addr4->sin_addr.s_addr) == 1) {
*res = ai;
return 0;
@ -82,8 +76,8 @@ int getaddrinfo(const char *name, const char *service,
*res = ai;
return 0;
} else {
int rc = resolvedns(getresolvconf(), AF_INET, name, ai->ai_addr,
sizeof(ai->ai_addr4));
rc = resolvedns(getresolvconf(), AF_INET, name, ai->ai_addr,
sizeof(ai->ai_addr4));
if (rc > 0) {
*res = ai;
return 0;