On Wednesday 30 September 2026 10:51:37 Martin Storsjö wrote: > On Wed, 30 Sep 2026, LIU Hao wrote: > > > 在 2026-9-27 03:29, Pali Rohár 写道: > > > Hello, in the attachment I'm sending setjmp/longjmp fixes. > > > > > > It fixes mingw-w64 _setjmp/_setjmp3/longjmp/_longjmpex implementations > > > for various CRT builds. And add new tests for verification. > > > diff --git a/mingw-w64-crt/misc/longjmp.S b/mingw-w64-crt/misc/longjmp.S > > > index a7f04d529b7f..5de492583376 100644 > > > --- a/mingw-w64-crt/misc/longjmp.S > > > +++ b/mingw-w64-crt/misc/longjmp.S > > > @@ -27,6 +27,30 @@ __MINGW_USYMBOL(longjmp): > > > movq %rdx,%rax /* retval */ > > > cmpq $1,%rax /* check that retval is non-zero */ > > > adcq $0,%rax /* if not then increase by one > > > via CF */ > > > + cmpq $0,(%rcx) /* jmp_buf->Frame */ > > > + je .Llongjmp_skip_seh > > > + /* Logic of SEH longjmp implementation based on x86_64 wine > > > longjmp code from: > > > + > > > https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/msvcrt/except_x86_64.c#L94-110 > > > + */ > > > + pushq %rcx > > > + pushq %rdx > > > + subq $192,(%rsp) /* allocate > > > roundup16(32+sizeof(EXCEPTION_RECORD)) */ > > > + movl $0x80000026,0x20(%rsp) /* > > > EXCEPTION_RECORD.ExceptionCode = STATUS_LONGJUMP */ > > > + movl $0,0x24(%rsp) /* > > > EXCEPTION_RECORD.ExceptionFlags = 0 */ > > > + movq $0,0x28(%rsp) /* > > > EXCEPTION_RECORD.ExceptionRecord = NULL */ > > > + movq $0,0x30(%rsp) /* > > > EXCEPTION_RECORD.ExceptionAddress = NULL */ > > > + movl $1,0x38(%rsp) /* > > > EXCEPTION_RECORD.NumberParameters = 1 */ > > > + movq %rcx,0x40(%rsp) /* > > > EXCEPTION_RECORD.ExceptionInformation[0] = jmp_buf */ > > > + movq 0x50(%rcx),%rdx /* TargetIp = jmp_buf->Rip */ > > > + movq (%rcx),%rcx /* TargetFrame = jmp_buf->Frame > > > */ > > > + leaq 0x20(%rsp),%r8 /* ExceptionRecord = > > > &EXCEPTION_RECORD */ > > > + movq %rax,%r9 /* ReturnValue = retval */ > > > + callq *__MINGW_USYMBOL(__MINGW_IMP_SYMBOL(RtlUnwind))(%rip) > > I haven't reviewed this patchset in detail, but this seems like moving > things in the wrong direction IMO. > > Yes, it would be nice if every polyfill would work exactly like the thing > we're emulating. > > But for these setjmp/longjmp functions, we just want the basic, SEH-less > straightforward back up/restore of all registers. In particular, users can > define __USE_MINGW_SETJMP_NON_SEH if they want a non-SEH based setjmp. > > > After spending a little more time looking at this, it looks like > __USE_MINGW_SETJMP_NON_SEH uses a different version of them, from > misc/mingw_longjmp.S, which I hope remains untouched.
I have touched misc/mingw_longjmp.S only in the change [PATCH 08/12] crt: Fix mingw-w64 longjmp() implementation when calling with value 0 which fixes longjmp(buf, 0) to return 1 (as needed by ISO C). There is no other change for misc/mingw_longjmp.S. > So perhaps it's ok to make these match their original counterparts closer, > but it looks quite surprising to me. > > // Martin _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
