mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 13:59:56 -04:00
SendSyncRequest looked the session up with kern_handle_get, which holds the kernel lock only for the lookup, and then dispatched to the handler with no reference. A CloseHandle of the session's last handle on another thread meanwhile reached ipc_handle_closed, which ran the close callback and freed the session while the handler still used it; for the audio renderer, renderer_close joins the render thread and frees the renderer a RequestUpdate is reading. OpenAudioRenderer read the transfer memory the same way, and a CloseHandle frees that object at once. kernel.c gains kern_handle_hold, which runs a hold callback under the kernel lock after the lookup (handle_close clears the slot under that lock before it calls ipc_handle_closed, so a close either comes first and the lookup fails, or comes after and finds the extra reference), and kern_handle_copy, which copies an object under the lock. ipc_svc takes the session with kern_handle_hold and drops the request's reference through ipc_handle_closed after the answer, so the close callback runs on whichever thread drops the last reference; the request thread holds no service lock by then. audren.c copies the transfer memory into a local IpcTransferMemory. Domain sub-objects are not freed yet (IpcSession.objects), so their lookups are left for the domain object change. Not reproduced before the change in a game run (no log shows a renderer closed during play). tests/ipc_session_check.py builds ipc.c with kernel.c linked: a request whose handler blocks while another thread closes the session's only handle must leave the close callback until the handler returns, and a closed transfer memory handle must copy nothing. Against the previous ipc.c it fails with the close callback run while the handler was blocked. system_event_check, sync_wake_check and the compile check of every runtime file pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""Build and run tests/ipc_session_check.c: runtime/ipc.c with runtime/kernel.c linked, checking that a CloseHandle racing
|
|
a request leaves the session (and its close callback) to the request's end and that a closed transfer memory handle is
|
|
not read; with the platform layer linked and the rest of the runtime stubbed. No game files: the module layout the
|
|
runtime includes is a stand-in written to the test's build folder.
|
|
|
|
Usage: ipc_session_check.py
|
|
"""
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
MSYS_BIN = Path(r'C:\msys64\ucrt64\bin')
|
|
|
|
|
|
def compiler():
|
|
if os.environ.get('CC'):
|
|
return os.environ['CC']
|
|
if os.name == 'nt' and (MSYS_BIN / 'clang.exe').exists():
|
|
return str(MSYS_BIN / 'clang.exe')
|
|
return shutil.which('clang') or 'clang'
|
|
|
|
LAYOUT = '''// A stand-in for the generated layout.h (tests/ipc_session_check.py).
|
|
#pragma once
|
|
#define MOD_MAIN_BASE 0x7000000000ull
|
|
#define MOD_MAIN_SIZE 0x4ea0000ull
|
|
'''
|
|
|
|
|
|
def main():
|
|
work = ROOT / 'build' / 'test' / 'ipc_session'
|
|
work.mkdir(parents=True, exist_ok=True)
|
|
(work / 'layout.h').write_text(LAYOUT)
|
|
win = os.name == 'nt'
|
|
exe = work / ('ipc_session_check.exe' if win else 'ipc_session_check')
|
|
env = dict(os.environ)
|
|
if win and MSYS_BIN.exists():
|
|
env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '')
|
|
rt = ROOT / 'runtime'
|
|
plat = [rt / 'platform' / ('win32.c' if win else 'linux.c'), rt / 'platform' / 'common.c']
|
|
libs = ['-lbcrypt', '-lws2_32', '-lpsapi', '-lwinmm', '-ldbghelp', '-lshell32', '-lole32', '-luser32', '-ladvapi32'] if win \
|
|
else ['-lpthread']
|
|
subprocess.check_call([compiler(), '-O1', '-g', '-Wall', '-Wno-unused-function', '-fno-strict-aliasing',
|
|
'-march=x86-64-v3', '-I', str(rt), '-I', str(work),
|
|
str(ROOT / 'tests' / 'ipc_session_check.c'), str(rt / 'kernel.c'), *map(str, plat),
|
|
'-o', str(exe), '-lm', *libs],
|
|
env=env)
|
|
return subprocess.run([str(exe)], env=env, timeout=300).returncode
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|