--- /dev/null
+#include <sys/mman.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+void *Map(const char *path, size_t *size, bool ro) {
+ int fd;
+ _syscall(fd = open(path, ro ? O_RDONLY : O_RDWR));
+
+ struct stat stat;
+ _syscall(fstat(fd, &stat));
+
+ if (size != NULL)
+ *size = stat.st_size;
+
+ void *base;
+ _syscall(base = mmap(0, stat.st_size, ro ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
+
+ _syscall(close(fd));
+ return base;
+}
--- /dev/null
+#define _assert(expr) \
+ do if (!(expr)) { \
+ fprintf(stderr, "_assert(%s)\n", #expr); \
+ exit(1); \
+ } while (false)
+
+#define _syscall(expr) \
+ do if ((long) (expr) != -1) \
+ break; \
+ else switch (errno) { \
+ case EINTR: \
+ continue; \
+ default: \
+ _assert(false); \
+ } while (true)
+
+#define _forever \
+ for (;;)
+
+#define _trace() \
+ printf("_trace(%s:%u)\n", __FILE__, __LINE__)
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdint.h>