mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 01:49:59 -04:00
Tell a crash on the RTSS thread as the game's own call of RivaTuner's library, and skip the restore there.
main.c foreign_hook matches "hook", so a crash in RTSSHooks64.dll got the line that the library is not part of the game and that a recording, overlay or capture program put it there, also when the game's own thread that sets the frame limit (rtss_limit.c's "rtss" worker) had loaded and called it. The one RTSS crash on record (issue #231) faulted in ntdll on that thread, where no note applied. And the crash handler then called rtss_limit_restore from that thread, whose own lock it holds (SRW locks are not recursive), so the restore's trylocks spent a second. The platform layer keeps the name a thread was made with in the thread itself (plat_thread_name, copied at its start: a detached thread's struct may go before it ends). main.c crash_module_note picks the note: on the "rtss" thread, whatever the module, the line says the fault is in the game's calls of RTSS's library or around them and that rtss = 0 keeps the game from calling it; on other threads RTSSHooks64.dll stays foreign, as it is RTSS's overlay there. The restore is skipped on the rtss thread. rtss_limit.c is unchanged: the thread is known by the name it is spawned with. Crash text only, besides the skipped restore. Not reproduced before the change. tests/foreign_hook_check.py checks the note's choice (RTSSHooks64.dll and ntdll on the RTSS thread: the RTSS note; RTSSHooks64.dll elsewhere: foreign; a driver: none), and tests/crash_stack_check.py that the crash report reads the faulting thread's name. They, thread_end_check, fatal_exit_check and the compile checks of every runtime file pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -109,8 +109,12 @@ static void alt_stack(void) {
|
||||
static __thread cpu_set_t cpu_rest;
|
||||
static __thread int cpu_rest_set;
|
||||
|
||||
static __thread char thread_name[16]; // plat_thread_name: copied at the start, as a detached thread's struct may go
|
||||
const char *plat_thread_name(void) { return thread_name[0] ? thread_name : NULL; }
|
||||
|
||||
static void *thread_main(void *p) {
|
||||
PlatThread *t = p;
|
||||
memcpy(thread_name, t->name, sizeof thread_name);
|
||||
alt_stack();
|
||||
__atomic_store_n(&t->tid, (int32_t)syscall(SYS_gettid), __ATOMIC_RELEASE);
|
||||
if (t->name[0]) pthread_setname_np(pthread_self(), t->name);
|
||||
|
||||
@@ -22,6 +22,9 @@ typedef void (*PlatThreadFn)(void *arg);
|
||||
#define PLAT_STACK_GUARANTEE 32768
|
||||
void plat_stack_guarantee(void);
|
||||
PlatThread *plat_thread_new(PlatThreadFn fn, void *arg, const char *name);
|
||||
// The name the calling thread was made with here (plat_thread_new, plat_thread_spawn), NULL for a thread made
|
||||
// elsewhere; kept in the thread itself, so the crash report can read it with any lock held.
|
||||
const char *plat_thread_name(void);
|
||||
// The same with the stack size given: stack bytes reserved for the thread (0: PLAT_STACK_DEFAULT). The default is the
|
||||
// same on every OS, so a thread that fits on Windows fits elsewhere.
|
||||
#define PLAT_STACK_DEFAULT (16u << 20)
|
||||
|
||||
@@ -34,8 +34,12 @@ struct PlatThread {
|
||||
PlatThreadFn fn;
|
||||
void *arg;
|
||||
volatile int32_t state; // 0 running and owned by its maker, 1 detached, 2 its function has returned
|
||||
char name[32];
|
||||
};
|
||||
|
||||
static __thread char thread_name[32]; // plat_thread_name: copied at the start, as a detached thread's struct may go
|
||||
const char *plat_thread_name(void) { return thread_name[0] ? thread_name : NULL; }
|
||||
|
||||
// What a thread made here keeps for itself is given back when its function returns: the handles below (the sleep
|
||||
// timer of plat_wait_ns, the events of plat_file_pread and plat_file_pwrite), what the other files keep per thread
|
||||
// (plat_thread_end_hook) and, for a detached thread, its PlatThread. The game makes and ends threads all through
|
||||
@@ -58,6 +62,7 @@ void plat_stack_guarantee(void) {
|
||||
static DWORD WINAPI thread_main(LPVOID p) {
|
||||
PlatThread *t = p;
|
||||
plat_stack_guarantee();
|
||||
memcpy(thread_name, t->name, sizeof thread_name);
|
||||
t->fn(t->arg);
|
||||
plat_thread_end_run();
|
||||
thread_handles_close();
|
||||
@@ -74,6 +79,7 @@ PlatThread *plat_thread_new_ex(PlatThreadFn fn, void *arg, const char *name, siz
|
||||
if (!t) return NULL;
|
||||
t->fn = fn;
|
||||
t->arg = arg;
|
||||
if (name) snprintf(t->name, sizeof t->name, "%s", name);
|
||||
t->h = CreateThread(NULL, stack ? stack : PLAT_STACK_DEFAULT, thread_main, t,
|
||||
CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION, NULL);
|
||||
if (!t->h) { free(t); return NULL; }
|
||||
|
||||
Reference in New Issue
Block a user