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

@@ -44,7 +44,7 @@
* @param clockid can be CLOCK_REALTIME, CLOCK_MONOTONIC, etc. noting
* that on Linux CLOCK_MONOTONIC is redefined to use the monotonic
* clock that's actually monotonic lool
* @param out_ts is where the nanoseconds are stored
* @param out_ts is where the nanoseconds are stored if non-NULL
* @return 0 on success or -1 w/ errno on error
* @error ENOSYS if clockid isn't available; in which case this function
* guarantees an ordinary timestamp is still stored to out_ts; and
@@ -56,21 +56,28 @@ int clock_gettime(int clockid, struct timespec *out_ts) {
/* TODO(jart): Just ignore O/S for MONOTONIC and measure RDTSC on start */
if (!IsWindows()) {
if (!IsXnu()) {
out_ts->tv_sec = 0;
out_ts->tv_nsec = 0;
if (out_ts) {
out_ts->tv_sec = 0;
out_ts->tv_nsec = 0;
}
return clock_gettime$sysv(clockid, out_ts);
} else {
int rc;
static_assert(sizeof(struct timeval) == sizeof(struct timespec));
out_ts->tv_sec = 0;
out_ts->tv_nsec = 0;
int rc = gettimeofday$sysv((struct timeval *)out_ts, NULL);
out_ts->tv_nsec *= 1000;
if (out_ts) {
out_ts->tv_sec = 0;
out_ts->tv_nsec = 0;
}
rc = gettimeofday$sysv((struct timeval *)out_ts, NULL);
if (out_ts) {
out_ts->tv_nsec *= 1000;
}
return rc;
}
} else {
struct NtFileTime ft;
GetSystemTimeAsFileTime(&ft);
filetimetotimespec(out_ts, ft);
*out_ts = filetimetotimespec(ft);
return 0;
}
}