Skip to content

[SIGNAL] Set no_tf when resuming from a signal for Syringe.exe#3951

Merged
ptitSeb merged 2 commits into
ptitSeb:mainfrom
ksco:fix-notf-signal
Jun 15, 2026
Merged

[SIGNAL] Set no_tf when resuming from a signal for Syringe.exe#3951
ptitSeb merged 2 commits into
ptitSeb:mainfrom
ksco:fix-notf-signal

Conversation

@ksco

@ksco ksco commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Wine implements NtSetContextThread by send SIGUSR1 to child and resume it after -- where TF might be set, we need to skip the first SIGTRAP.

@ksco ksco force-pushed the fix-notf-signal branch from 951b869 to 3aac331 Compare June 15, 2026 10:57
@ksco ksco changed the title [SIGNAL] Set no_tf when resuming from a signal Syringe.exe [SIGNAL] Set no_tf when resuming from a signal for Syringe.exe Jun 15, 2026
Comment thread src/libtools/signals.c Outdated
if(db) {
// if signal was inside a dynablock, just mirror all the new regs in the right place to simple run native_next
mctx2emu(emu, &sigcontext->uc_mcontext);
if(ACCESS_FLAG(F_TF)) emu->flags.no_tf = 1;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work here, as it will resume execution in dynarec directly.
mctx2emu needs to be done before and TF tested to not resume in dynarec if it's set.

        #if defined(DYNAREC)
        if(db || emu->jmpbuf)
            mctx2emu(emu, &sigcontext->uc_mcontext);
        if(db && !ACCESS_FLAG(F_TF)) {
            // if signal was inside a dynablock, just mirror all the new regs in the right place to simple run native_next
            mctx2emu(emu, &sigcontext->uc_mcontext);
            copyEmu2USignalCTXreg(p, emu, native_next);
            printf_log((sig==10)?LOG_DEBUG:log_minimum, "Context has been changed in Sigactionhanlder, jumping to native_next from DynaBlock at %p, RSP=%p\n", (void*)R_RIP, (void*)R_RSP);
            return 1;
        }
        #endif
        if(emu->jmpbuf) {
            #ifndef DYNAREC
            mctx2emu(emu, &sigcontext->uc_mcontext);
            #endif
            if((skip==1) && (emu->ip.q[0]!=sigcontext->uc_mcontext.gregs[X64_RIP]) && !ACCESS_FLAG(F_TF))
                skip = 3;   // if it jumps elsewhere, it can resume with dynarec...
            printf_log((sig==10)?LOG_DEBUG:log_minimum, "Context has been changed in Sigactionhanlder, doing siglongjmp to resume emu at %p, RSP=%p (resume with %s)\n", (void*)R_RIP, (void*)R_RSP, (skip==3)?"Dynarec":"Interp");

something like that instead

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, indeed, need to force the interpreter…

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will you change this PR or do you prefer I merge this one as-is and push another PR to fix those cases?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll address this soon.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we do need if (ACCESS_FLAG(F_TF) && skip == 1) emu->flags.no_tf = 1;, right?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sure
my changes were just to make sure Interpreter was used

Wine implements NtSetContextThread by send SIGUSR1 to child and resume it after -- where TF might be set, we need to skip the first SIGTRAP.
@ksco ksco force-pushed the fix-notf-signal branch from 3aac331 to 67bd0d1 Compare June 15, 2026 13:08
Comment thread src/libtools/signals.c
if((skip==1) && (emu->ip.q[0]!=sigcontext->uc_mcontext.gregs[X64_RIP]))
if((skip==1) && (emu->ip.q[0]!=sigcontext->uc_mcontext.gregs[X64_RIP]) && !ACCESS_FLAG(F_TF))
skip = 3; // if it jumps elsewhere, it can resume with dynarec...
mctx2emu(emu, &sigcontext->uc_mcontext);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mctx2emu call for non-Dynarec code seems to be missing

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it should be moved before the if, as it contain update x64emu_t data

@ptitSeb ptitSeb merged commit 80bdf9b into ptitSeb:main Jun 15, 2026
28 checks passed
@ksco ksco deleted the fix-notf-signal branch June 16, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants