VC6 string compatibility on the Linux host
client/runtime/guest_msvcp.c implements the char-string methods imported
by lr.dll, plus size and capacity accessors. It uses guest addresses and
guest_heap; it never loads a Windows DLL. Unknown exports remain unresolved.
Out-of-range, length and allocation errors abort with an explicit diagnostic
until guest C++ exception construction is supported. This is a focused
replacement, not a complete MSVCP60 implementation.
Target and evidence
The reference is anarchy-runtime-14.9.1/MSVCP60.DLL, x86 PE, SHA-256
2b6b93c2d66969eb00258e2b5ad6172decebada096e3b1b077a3380c80e4a072.
REA used Ghidra 12.1.4, ephemeral immutable-source analysis. The AO import
inventory is local/client/game-14.9.1/inventory.json.
The char string occupies 16 guest bytes: allocator byte at offset 0,
buffer pointer at 4, length at 8, capacity at 12. The buffer's preceding byte
is a reference count: 0 means unique, 1..254 counts additional owners,
255 means frozen and ineligible for sharing. Capacity rounds up with size | 31.
The allocation includes the reference byte and terminal null.
| Behavior | Binary entry | REA evidence |
|---|---|---|
| Allocator constructor | 0x780c740e |
ev_385fc3c0ee9b2f96c5af14acee5b1a81e1142e9403c9230941999daa07bae56a |
_Tidy decrements or frees, clears pointer/size/capacity |
0x780c1a60 |
ev_d59aec142e0ee50323ea6222bf04b40d09836120bb76905aac8d3c723553a757 |
_Copy allocation and preserved prefix |
0x780c1b2f |
ev_10573dfcd5e912157765a01e2fe9562b5fa56ab390a5cbdcff87c4f88b3e7ce1 |
_Grow base and split tail |
0x780c1ad3, 0x780c8844 |
ev_110c1335134e26a496652b8e1d5f1501f1fd9302a1fd780364cafb79e8957ca9, ev_6712a878f335496362123b11f47ae34e430f280b2a31f91ed83896bb1dd31226 |
| String assignment, sharing and self-assignment | 0x780c7714 |
ev_60d5c8c23efde925620ed2e39fd3409cbc0c45a8f98e9aaece9f316634c8d3a0 |
| Byte assignment | 0x780c1a9e |
ev_f85db7822d6b43ad9eeed46d077c31833fc71f2fb2461670c56b21b303af83fa |
| Erase | 0x780c7acd |
ev_78952aa241c0c345a25ab1f73b5296f8b48217934fb5995dc06ff815fd2b586f |
| Copy constructor | 0x780c7426 |
ev_d3a8a93487b8c0858318b1d6a65e69f63a974ba87042616bb641048a96dec650 |
_Split detaches through strlen and assignment |
0x780c88cc |
ev_0d5dc418c931c72d32939e93241d751d50097792fefd03cbc869b6aa01fcc186 |
_Freeze detaches and marks reference byte 255 |
0x780c880e |
ev_9a6c9862ae57352ad0a31c2c4a265304ebbbedcf5a247310aee5a288cc52be30 |
_Eos writes length and terminator |
0x780c87fd |
ev_5eb4cb9e48d6d91a15b46664c2db4d5c36f029b045389a70061ceee09ab95381 |
Ghidra initially omitted the terminal-jump target of _Grow; assembly of
0x780c8844 supplies the missing path. Treating the truncated pseudocode as
complete would have missed shared/frozen and zero-length behavior.
_Split deliberately preserves the reference implementation's surprising
strlen behavior: an embedded null can shorten a shared string when detached
by erase. This is covered by a direct native differential test.
Validation
Run from the repository root on Windows:
& 'python3' tools/client/test_msvcp_strings.py
The runner verifies the vendor SHA, builds a 32-bit reference with
toolchains/llvm-mingw-20261006-ucrt-x86_64/bin/i686-w64-mingw32-clang.exe,
and invokes actual vendor exports with x86 thiscall/cdecl. It then compiles
the same test using GCC under Ubuntu-26.04 WSL with RECOMP_PORTABLE, linking
only the handwritten adapters, guest heap/memory, and register state.
There is no game code or vendor DLL dependency in the Linux executable.
Observed result:
Windows MSVCP60 == Linux x86-64: VC6 strings: 8200 snapshots, digest 8d3d3d76
The 1024 deterministic trials and focused edge cases compare allocator bytes,
buffer presence, length, capacity, reference count, contents and terminator.
They exercise assignment, copy sharing, freeze, erase, self-assignment,
growth, trimming, direct copy and _Eos, including saturation at 254 shared
references and embedded-null detachment. Less-than results are included in
the digest. The Linux side additionally asserts stack cleanup and all four
x86 callee-saved registers. Exported npos/null data and max_size are checked.
This does not establish every input's equivalence. Exceptions, invalid pointers, allocation failure and very large allocations are not equivalent yet; they fail explicitly. No cross-thread reference-count equivalence is claimed.
Iostream startup boundary
aar.dll's sub_20001DC0 tail-calls ios_base::Init::Init with object
0x20015cd1. This constructor must not be implemented as a success stub.
On first initialization it builds three filebuf objects from the _iob array,
then cin, cout, cerr and clog; it ties cin/cerr/clog to cout and sets cerr's
unitbuf flag. A locked reference count controls initialization. Final Init
destruction flushes cout, cerr and clog.
Observed static evidence:
- Constructor
0x780c1703:ev_b3c80a89bbff85178a963d58cf1d115dc154b26b658fa8b5856e332e1c9f6da6. - Destructor
0x780c2d45:ev_49794dfd2879f80844e6226274a1d8a449a1e22b05e00c28738fee8e0169e1cc. _Lockit0x780c1589:ev_6c53ebdbff029ee7495cf75577e8040500ce02d05ced570956a6cf9862bf57f8.- Lock release
0x780c15fb:ev_eeed2ae57e57960097e178adff0f4010c3536fba70b9b20b3567e535476e170b. - Filebuf constructor
0x780c1892:ev_c366a038edb6f4c0c2514c9399799c589b571313f82d9deea96b8e7dc1fc61a2. - Filebuf
_Init0x780c1c27:ev_f226ccbe7c48df4dc6884357f90c0498a502ee1b777e12cefac6cadd3ef85297. - Ostream flush
0x780c298c:ev_2c3fdbba91b0139b612f8c036336c73bf906cfb37b2f851a653c04bdf97d0659.
The lock path needs InterlockedExchange, InitializeCriticalSection,
EnterCriticalSection, LeaveCriticalSection, Sleep and exit-callback registration;
cleanup also needs DeleteCriticalSection. Filebuf construction initializes
locale objects and streambuf vtables before binding files. _iob is an array
of 32-byte guest MSVCRT _iobuf structures. Filebuf stores pointers directly
to their _ptr (offset 0), _cnt (4) and _base (8) fields. An opaque native
FILE handle alone is insufficient: the facade must preserve guest FILE fields
and synchronize buffer pointer/count behavior. Flush dispatches through the
streambuf vtable and propagates failure into stream state.
The vendor import inventory also identifies localeconv, setlocale, locale/ctype data, conversion helpers, allocation, stdio, math and exception imports. This is a static inventory, not proof that every import is reached during init. AO additionally imports streams, filebuf, stringstream, locale and vtables. Mechanically translating the vendor C++ implementation is preferable to hand-writing that whole ABI. The tested string implementation remains a concrete example of substituting focused handwritten source while preserving the guest ABI. No iostream methods are implemented by this adapter.