Polish greenbean example a bit more

Windows support for this example is still a work in progress. It's
encountering some unusual crashes. Thank you Chris Wellons for the cool
synchronization code too!
This commit is contained in:
Justine Tunney 2022-05-15 09:14:48 -07:00
parent e5e141d9b5
commit 91ee2b19d4
4 changed files with 145 additions and 81 deletions

View file

@ -121,6 +121,16 @@ forceinline void MakeLongDoubleLongAgain(void) {
asm volatile("fldcw\t%0" : /* no outputs */ : "m"(x87cw));
}
// https://nullprogram.com/blog/2022/02/18/
static inline char16_t *MyCommandLine(void) {
void *cmd;
asm("mov\t%%gs:(0x60),%0\n"
"mov\t0x20(%0),%0\n"
"mov\t0x78(%0),%0\n"
: "=r"(cmd));
return cmd;
}
static inline size_t StrLen16(const char16_t *s) {
size_t n;
for (n = 0;; ++n) {
@ -271,7 +281,7 @@ __msabi textwindows int64_t WinMain(int64_t hInstance, int64_t hPrevInstance,
#if !IsTiny()
__wincrashearly = AddVectoredExceptionHandler(1, (void *)OnEarlyWinCrash);
#endif
cmdline = GetCommandLine();
cmdline = MyCommandLine();
#ifdef SYSDEBUG
/* sloppy flag-only check for early initialization */
if (__strstr16(cmdline, u"--strace")) ++__strace;