mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
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:
parent
467504308a
commit
f4f4caab0e
1052 changed files with 65667 additions and 7825 deletions
|
@ -17,6 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/elf/def.h"
|
||||
#include "libc/elf/elf.h"
|
||||
#include "tool/decode/lib/elfidnames.h"
|
||||
|
||||
|
|
|
@ -17,17 +17,12 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/arraylist.h"
|
||||
#include "libc/alg/arraylist2.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "tool/decode/lib/flagger.h"
|
||||
|
||||
struct FlagNameBuf {
|
||||
size_t i, n;
|
||||
char *p;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats numeric flags integer as symbolic code.
|
||||
*
|
||||
|
@ -35,28 +30,32 @@ struct FlagNameBuf {
|
|||
* @param id is the flags
|
||||
* @return NUL-terminated string that needs free()
|
||||
*/
|
||||
nodiscard char *recreateflags(const struct IdName *names, unsigned long id) {
|
||||
struct FlagNameBuf buf = {};
|
||||
char extrabuf[20];
|
||||
nodiscard char *RecreateFlags(const struct IdName *names, unsigned long id) {
|
||||
bool first;
|
||||
size_t bufi, bufn;
|
||||
char *bufp, extrabuf[20];
|
||||
bufi = 0;
|
||||
bufn = 0;
|
||||
bufp = NULL;
|
||||
first = true;
|
||||
for (; names->name; names++) {
|
||||
if ((id == 0 && names->id == 0) ||
|
||||
(id != 0 && names->id != 0 && (id & names->id) == names->id)) {
|
||||
id &= ~names->id;
|
||||
if (!first) {
|
||||
append(&buf, "|");
|
||||
APPEND(&bufp, &bufi, &bufn, "|");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
concat(&buf, names->name, strlen(names->name));
|
||||
CONCAT(&bufp, &bufi, &bufn, names->name, strlen(names->name));
|
||||
}
|
||||
}
|
||||
if (id) {
|
||||
if (buf.i) append(&buf, "|");
|
||||
concat(&buf, extrabuf, snprintf(extrabuf, sizeof(extrabuf), "%#x", id));
|
||||
} else if (!buf.i) {
|
||||
append(&buf, "0");
|
||||
if (bufi) APPEND(&bufp, &bufi, &bufn, "|");
|
||||
CONCAT(&bufp, &bufi, &bufn, extrabuf,
|
||||
snprintf(extrabuf, sizeof(extrabuf), "%#x", id));
|
||||
} else if (!bufi) {
|
||||
APPEND(&bufp, &bufi, &bufn, "0");
|
||||
}
|
||||
return buf.p;
|
||||
return bufp;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
char *recreateflags(const struct IdName *, unsigned long) nodiscard;
|
||||
char *RecreateFlags(const struct IdName *, unsigned long) nodiscard;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -49,7 +49,7 @@ kPollNamesRo:
|
|||
.previous
|
||||
|
||||
/ Mapping of poll() flags to their string names.
|
||||
/ @see recreateflags()
|
||||
/ @see RecreateFlags()
|
||||
.initbss 301,_init_kPollNames
|
||||
kPollNames:
|
||||
.rept .Lrows
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "third_party/xed/x86.h"
|
||||
#include "tool/decode/lib/idname.h"
|
||||
|
||||
const struct IdName kXedErrorNames[] = {
|
||||
const struct IdName kXedErrorIdNames[] = {
|
||||
{XED_ERROR_NONE, "NONE"},
|
||||
{XED_ERROR_BUFFER_TOO_SHORT, "BUFFER_TOO_SHORT"},
|
||||
{XED_ERROR_GENERAL_ERROR, "GENERAL_ERROR"},
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern const struct IdName kXedErrorNames[];
|
||||
extern const struct IdName kXedErrorIdNames[];
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue