Get life.com in MODE=tiny back down to 12kb

This commit is contained in:
Justine Tunney 2022-03-23 08:09:01 -07:00
parent 23b72eb617
commit b90fa996b4
14 changed files with 199 additions and 72 deletions

View file

@ -33,9 +33,14 @@
* @noreturn
*/
wontreturn void exit(int exitcode) {
const uintptr_t *p;
STRACE("exit(%d)", exitcode);
if (weaken(__cxa_finalize)) {
weaken(__cxa_finalize)(NULL);
}
quick_exit(exitcode);
for (p = __fini_array_end; p > __fini_array_start;) {
((void (*)(void))(*--p))();
}
__restorewintty();
_Exit(exitcode);
}

View file

@ -160,19 +160,16 @@ textwindows void WinMainForked(void) {
ReadAll(reader, &mapcount, sizeof(_mmi.i));
ReadAll(reader, &mapcapacity, sizeof(_mmi.n));
specialz = ROUNDUP(mapcapacity * sizeof(_mmi.p[0]), kMemtrackGran);
MapViewOfFileExNuma(CreateFileMappingNuma(
-1, &kNtIsInheritable, kNtPageReadwrite,
specialz >> 32, specialz, 0, kNtNumaNoPreferredNode),
kNtFileMapWrite, 0, 0, specialz, maps,
kNtNumaNoPreferredNode);
MapViewOfFileEx(CreateFileMapping(-1, &kNtIsInheritable, kNtPageReadwrite,
specialz >> 32, specialz, 0),
kNtFileMapWrite, 0, 0, specialz, maps);
ReadAll(reader, maps, mapcount * sizeof(_mmi.p[0]));
if (IsAsan()) {
shad = (char *)(((intptr_t)maps >> 3) + 0x7fff8000);
size = ROUNDUP(specialz >> 3, FRAMESIZE);
MapViewOfFileExNuma(
CreateFileMappingNuma(-1, &kNtIsInheritable, kNtPageReadwrite,
size >> 32, size, 0, kNtNumaNoPreferredNode),
kNtFileMapWrite, 0, 0, size, maps, kNtNumaNoPreferredNode);
MapViewOfFileEx(CreateFileMapping(-1, &kNtIsInheritable, kNtPageReadwrite,
size >> 32, size, 0),
kNtFileMapWrite, 0, 0, size, maps);
#if 0
ReadAll(reader, shad, (mapcount * sizeof(_mmi.p[0])) >> 3);
#endif
@ -191,21 +188,20 @@ textwindows void WinMainForked(void) {
STRACE("fork() child CloseHandle(%ld) ~~~FAILED~~~ %m", maps[i].h);
}
upsize = ROUNDUP(size, FRAMESIZE);
maps[i].h = CreateFileMappingNuma(-1, &kNtIsInheritable,
kNtPageExecuteReadwrite, upsize >> 32,
upsize, NULL, kNtNumaNoPreferredNode);
MapViewOfFileExNuma(maps[i].h, kNtFileMapWrite | kNtFileMapExecute, 0, 0,
upsize, addr, kNtNumaNoPreferredNode);
maps[i].h =
CreateFileMapping(-1, &kNtIsInheritable, kNtPageExecuteReadwrite,
upsize >> 32, upsize, NULL);
MapViewOfFileEx(maps[i].h, kNtFileMapWrite | kNtFileMapExecute, 0, 0,
upsize, addr);
ReadAll(reader, addr, size);
} else {
STRACE("fork() child %p %'zu mapping shared hand:%ld offset:%'lu", addr,
size, maps[i].h, maps[i].offset);
MapViewOfFileExNuma(maps[i].h,
(maps[i].prot & PROT_WRITE)
? kNtFileMapWrite | kNtFileMapExecute
: kNtFileMapRead | kNtFileMapExecute,
maps[i].offset >> 32, maps[i].offset, size, addr,
kNtNumaNoPreferredNode);
MapViewOfFileEx(maps[i].h,
(maps[i].prot & PROT_WRITE)
? kNtFileMapWrite | kNtFileMapExecute
: kNtFileMapRead | kNtFileMapExecute,
maps[i].offset >> 32, maps[i].offset, size, addr);
}
}

View file

@ -50,6 +50,13 @@
#include "libc/str/tpenc.h"
#include "libc/str/utf16.h"
#if IsTiny()
extern typeof(CreateFileMapping) *const __imp_CreateFileMappingW __msabi;
extern typeof(MapViewOfFileEx) *const __imp_MapViewOfFileEx __msabi;
#define CreateFileMapping __imp_CreateFileMappingW
#define MapViewOfFileEx __imp_MapViewOfFileEx
#endif
#define AT_EXECFN 31L
#define MAP_ANONYMOUS 32
#define MAP_PRIVATE 2
@ -121,7 +128,6 @@ static noasan textwindows wontreturn noinstrument void WinMainNew(
STRACE("SetConsoleCP(kNtCpUtf8) → %hhhd", rc);
rc = SetConsoleOutputCP(kNtCpUtf8);
STRACE("SetConsoleOutputCP(kNtCpUtf8) → %hhhd", rc);
SetEnvironmentVariable(u"TERM", u"xterm-truecolor");
for (i = 0; i < 2; ++i) {
hand = GetStdHandle(kConsoleHandles[i]);
rc = GetConsoleMode(hand, __ntconsolemode + i);
@ -139,12 +145,11 @@ static noasan textwindows wontreturn noinstrument void WinMainNew(
allocaddr = stackaddr - argsize;
STRACE("WinMainNew() mapping %'zu byte arg block + stack at %p", allocsize,
allocaddr);
MapViewOfFileExNuma(
(_mmi.p[0].h = CreateFileMappingNuma(
-1, &kNtIsInheritable, kNtPageExecuteReadwrite, allocsize >> 32,
allocsize, NULL, kNtNumaNoPreferredNode)),
kNtFileMapWrite | kNtFileMapExecute, 0, 0, allocsize, (void *)allocaddr,
kNtNumaNoPreferredNode);
MapViewOfFileEx(
(_mmi.p[0].h =
CreateFileMapping(-1, &kNtIsInheritable, kNtPageExecuteReadwrite,
allocsize >> 32, allocsize, NULL)),
kNtFileMapWrite | kNtFileMapExecute, 0, 0, allocsize, (void *)allocaddr);
_mmi.p[0].x = allocaddr >> 16;
_mmi.p[0].y = (allocaddr >> 16) + ((allocsize >> 16) - 1);
_mmi.p[0].prot = PROT_READ | PROT_WRITE | PROT_EXEC;