aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


docs/linux-crt-exception.md (3985B)


Native exception objects

client/runtime/guest_exception.c implements the reached MSVCRT exception object boundary in portable C. Its 12-byte guest object contains a 32-bit guest vtable address, a 32-bit message address and a 32-bit ownership flag. The vtable contains dispatch identifiers 0xf1000000 and 0xf1000004, resolved by the Linux host to the deleting destructor and what. No host pointers or original machine code enter these objects.

The default, message and copy constructors return the guest object and preserve thiscall stack cleanup. Owned messages are copied into the guest heap; borrowed messages retain their aliases. A null message yields Unknown exception from what. The destructor restores the base vtable and frees owned message storage without clearing the message/ownership fields. Virtual destruction supports scalar objects and arrays with the preceding 32-bit element count, including the flag controlling whether the object allocation is freed.

Binary evidence

REA/Ghidra 12.1.4 inspected C:/Windows/SysWOW64/msvcrt.dll, SHA-256 23a918921c545140d189ce6dc68590bacdeb0ab2f3e3a9a2d722c5aff45ce64f. The following static observations establish layout and instruction-level behavior; they do not themselves establish runtime equivalence:

Procedure Address REA evidence
??0exception@@QAE@XZ 0x10039ad0 ev_723eb2135ae40eadab76795c45ec3c65082de0887fd402d1e3810b4a33b74009
??0exception@@QAE@ABQBD@Z 0x100399c0 ev_452d3f3d09772fd3b090cdaabea3de08c3d545a3c04ab57db741b780860ffce1
??0exception@@QAE@ABV0@@Z 0x10039a60 ev_e150177a02c15e9509cdc06029ef57d7e667095c2d90e7b20236ff50a9dc2c41
??1exception@@UAE@XZ 0x10039b30 ev_89dc66ed9015e32f924057d6c49074722e7a4555808464b5d204e6a0ff117339
?what@exception@@UBEPBDXZ 0x10039e80 ev_97107b020f4aefb19f0d3d1597768444c6407e90cc6025dc7af0e3e7e58ac8b1
Virtual deleting destructor 0x10039d00 ev_09ded587cfa7e135716a5506d8fde58d714d95cbb837d480e45c7bfaaf6d8268

The two vtable slots at 0x10001004 are established by ev_5ba8ddd0c8347ffe05a9149a146b290f85529bad58ce79cdb784b5451700fbf4; the fallback message by ev_098a74153f417dc32a523d760f840d822d887f88ed1c91acb6fe15e591ac4e28.

Verification and limits

From the repository root:

& 'python3' tools/client/test_portable_exception.py
wsl --cd /path/to/ao/client --exec make -f Makefile.linux -j8 all test

The same fixture invokes actual x86 MSVCRT exports on Windows and the production C adapters on Linux x86-64. Both pass 773 snapshots with digest 421cabd1: default/null messages, lengths 0 through 255, independent owned copies, borrowed aliases, canaries, virtual what, restoration of a derived vtable during base destruction, and all four scalar/array deletion flag combinations. Linux also checks stack balance and callee-saved registers on every call.

This does not implement RTTI: the synthetic vtable's preceding locator is zero, and __RTtypeid/dynamic casts remain unresolved. Assignment, allocation-failure equivalence, typed catches and exception-unwind destruction are not validated by this fixture. Direct/virtual object destruction is tested independently of throwing. The existing generated throw/catch fixture remains a separate test.

All twenty Linux test programs pass in local/client/linux-exception-build.log. Real client startup now passes exception construction and reaches ShellExecuteA in sub_2F009AA0. The debugger observes open, dxdiag.exe, DXDiagOutput.txt as its operation, file and parameters. Its call stack is sub_28001000 -> sub_2F0070F0 -> sub_2F009AA0. The missing call stops explicitly; no diagnostic program is launched. Evidence is in linux-startup-exception.log and linux-exception-shell-diagnostic.log under local/client. The existing client stderr log was restored after each run. There is still no Linux window, rendering or gameplay validation.