Files
WoW-Hybrid-gateway/tests/native_registration_trace_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

66 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""Owned Linux fixture for exact entry/return trace and signal cleanup.
Synthetic code/data only; does not invoke a game or claim engine compatibility.
"""
import ctypes as C
import json,os,signal,struct,sys,tempfile,time
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'ops'))
import native_registration_trace as trace
with tempfile.TemporaryDirectory(prefix='native-registration-') as folder:
temporary=Path(folder);(temporary/'runtime').mkdir()
readfd,writefd=os.pipe();pid=os.fork()
if pid==0:
try:
os.close(readfd)
libc=C.CDLL(None);libc.mmap.argtypes=[C.c_void_p,C.c_size_t,C.c_int,C.c_int,C.c_int,C.c_long];libc.mmap.restype=C.c_void_p
def page(address):
start=address&~4095
if libc.mmap(start,4096,3,0x100022,-1,0)!=start:raise RuntimeError('fixture mapping unavailable')
return start
for address in (trace.REGISTER,trace.CREATE,trace.READY):
start=page(address);C.memmove(address,b'\xc3',1)
if libc.mprotect(C.c_void_p(start),4096,5):raise RuntimeError('fixture protection failed')
page(trace.LUA_GLOBAL);C.c_ulonglong.from_address(trace.LUA_GLOBAL).value=0x12345000
name=0x144ddfcb0;page(name);C.memmove(name,b'C_Login\0',8)
# Calls have true Windows x64 RCX/RDX/R8 arguments and a return PC
# inside the pinned PE code range, while the child is otherwise Linux.
start=page(0x140002000);position=start;functions=[]
for target,rcx,rdx,r8 in ((trace.REGISTER,0x14575a130,29,name),(trace.CREATE,0x12345000,0,1),(trace.READY,0x12345000,0,0)):
code=b'\x48\xb9'+struct.pack('<Q',rcx)+b'\x48\xba'+struct.pack('<Q',rdx)+b'\x49\xb8'+struct.pack('<Q',r8)+b'\x48\xb8'+struct.pack('<Q',target)+b'\x48\x83\xec\x28\xff\xd0\x48\x83\xc4\x28\xc3'
C.memmove(position,code,len(code));functions.append(C.CFUNCTYPE(None)(position));position+=128
if libc.mprotect(C.c_void_p(start),4096,5):raise RuntimeError('fixture thunk protection failed')
# Same identity guard as actual Wine, confined to this own fixture.
libc.prctl(15,C.c_char_p(b'WowB.exe'),0,0,0)
os.write(writefd,b'ready');os.close(writefd)
end=time.monotonic()+3
while time.monotonic()<end:
functions[0]()
for _ in range(4):functions[1]()
functions[2]();time.sleep(.01)
os._exit(0)
except BaseException:os._exit(2)
os.close(writefd)
try:
assert os.read(readfd,5)==b'ready'
trace.ROOT=temporary
probe=trace.RegistrationTrace(pid,Path(sys.argv[1]) if len(sys.argv)>1 else ROOT/'build/native-ptrace-abi')
deadline=time.monotonic()+2
while not probe.done and time.monotonic()<deadline:probe.poll();time.sleep(.001)
assert probe.done and not probe.attached
report=json.loads((temporary/'runtime/native-registration-trace.json').read_text())
assert report['status']=='native-registration-and-allocator-observed'
creates=[e for e in report['events'] if e['kind']=='native-table-create']
assert len(creates)==4 and all(e.get('returned_normally') and e['global_lua_matches'] and e['entry_stack_alignment']==8 for e in creates)
assert any(e['kind']=='namespace' and e['name']=='C_Login' for e in report['events'])
assert any(e['kind']=='native-login-ready' and e['global_lua_matches'] for e in report['events'])
assert report['hardware_registers_restored'] and not report['lua_memory_modified']
got,status=os.waitpid(pid,0);assert got==pid and os.WIFEXITED(status) and os.WEXITSTATUS(status)==0
print('Observed registration, four exact table returns and ready callback in own fixture; no writes, leaked traps or stale debug registers.')
finally:
os.close(readfd)
try:os.kill(pid,signal.SIGTERM)
except ProcessLookupError:pass