commit 499401cd6eb6d8c133f8927664feec11516e6c96
parent 1ea7b524e3456d244f74b38cca4c05fcfc573caf
Author: anon <anon@example.com>
Date: Tue, 13 Oct 2026 03:25:42 +0000
Run AO WinMain in the Rust and browser runtimes
Diffstat:
1 file changed, 47 insertions(+), 3 deletions(-)
diff --git a/docs/browser-porting.md b/docs/browser-porting.md
@@ -508,9 +508,53 @@ contract.
The observed executable initializer path reaches ACE's Winsock startup
before WinMain. Its `ws2_32.dll` import by ordinal 115 is `WSAStartup`, as
confirmed against the Windows PE export table. In the pinned ACE image,
-the call continues at RVA `0x58b3d`. Native and WASM runs currently stop
-there; DLL initialization is complete, but Winsock initialization and the
-browser's transport to the local server remain unresolved.
+the call continues at RVA `0x58b3d`; the preceding instruction requests
+version `0x0002` (2.0), not `0x0202` (2.2). The output is the x86 WSADATA
+layout: 400 bytes, with version WORDs at offsets 0 and 2, description at 4,
+system status at 261, legacy socket limits at 390/392, and vendor pointer
+at 396. A 64-bit host's structure layout must not be used for this buffer.
+See Microsoft's [WSAStartup contract](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastartup)
+and [WSADATA fields](https://learn.microsoft.com/en-us/windows/win32/api/winsock/ns-winsock-wsadata).
+Passing this initialization does not establish any socket transport support.
+
+ACE's subsequent initialization formats `%lx%d` and creates a semaphore.
+MSVCRT's x86 `va_list` points into guest argument memory; integer arguments,
+including `long`, occupy four bytes. `vsprintf` writes a trailing NUL and
+returns the length without that terminator. See Microsoft's
+[CRT formatting contract](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/vsprintf-vsprintf-l-vswprintf-vswprintf-l-vswprintf-l?view=msvc-170).
+Semaphores are counted objects: a successful wait consumes one count,
+release increases it without exceeding the maximum, and separately opened
+handles to an existing named semaphore share its state. Returning a dummy
+handle or unconditional wait success changes this startup behavior. See
+[ReleaseSemaphore](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-releasesemaphore)
+and [WaitForSingleObject](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject).
+
+The ACE allocator's virtual calls also matter for code discovery. Its exported
+`??_7ACE_New_Allocator@@6B@` table is at RVA `0xac600`, with 16 method slots.
+The startup call at RVA `0x746a5` uses slot 1, the exported
+`?malloc@ACE_New_Allocator@@UAEPAXI@Z` at RVA `0x9a40`. Ordinary import
+reachability does not discover this method; a missing translated target here
+is not a missing Windows allocation API.
+
+Native and browser execution subsequently reach Clientr's WinMain. Its call
+at RVA `0x1112` registers the guest exception filter at RVA `0x22b0` through
+`SetUnhandledExceptionFilter`; the continuation is RVA `0x1118`. Registration
+returns the previous filter pointer and is separate from implementing guest
+exception dispatch and unwinding.
+WinMain subsequently selects CRT error mode 1 (stderr), registers SIGABRT
+22 with its handler at RVA `0x2230`, deletes `stderr.txt`, and reopens
+`_iob + 64` with `freopen("stderr.txt", "w", stderr)`. The latter call is at
+RVA `0x118d`, continuation `0x1193`. It saves the returned stream pointer
+before continuing initialization. This is a real FILE/descriptor contract,
+not just a logging callback. The data at RVA `0x9274` also contains `out.dat`.
+The current runs emit three null-page access diagnostics before this point;
+their origins remain unresolved.
+
+For Theseus diagnostics, a fast `call_builtin` places its synthetic return
+sentinel `0xfffffffe` on the guest stack. `eip_context` is set by this fast
+path, but can retain a previous call's value for indirect host calls. Confirm
+a reported location against the generated call site, native backtrace, and
+original PE instructions before treating it as the exact guest caller.
Floating-point CRT returns use x87 ST(0). For example, LLR's `floor` call
at RVA `0x2bb8` passes an eight-byte double on the stack, immediately uses