在 2026-9-24 17:15, Pali Rohár 写道:
      if (is_fastfail_available())
          __fastfail(FAST_FAIL_INVALID_ARG);
+ CONTEXT context; /* do not initialize context (to zeros) to prevent using registers and clobbering their content. */

According to this comment, the context should probably captured before 
`is_fastfail_available()`?


+        /* If SEH unwind data table is not available then just fix RIP/RSP/RBP.
+         * Current stack frame returned by __builtin_frame_address(0) contains
+         * values of caller function: rdi, rbp, rip. Therefore rsp of called
+         * function is address of stack frame plus size of those 3 registers 
and
+         * rbp of called function is dereferenced second value (indexed from 
1).
+         * Note that msvc _AddressOfReturnAddress() is address of the rip value
+         * which should be &(((uintptr_t *)__builtin_frame_address(0))[2]) and
+         * therefore below code for context.Rsp should match the msvc behavior.
+         */
+        context.Rip = 
(uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0)); /* msvc 
uses _ReturnAddress() */
+        context.Rsp = (uintptr_t)__builtin_frame_address(0) + 
3*sizeof(uintptr_t); /* msvc uses _AddressOfReturnAddress()+8 */
+        context.Rbp = ((uintptr_t *)__builtin_frame_address(0))[1]; /* not 
filled by msvc */

This doesn't look correct. As you use `__builtin_frame_address(0)`, the compiler will not (I suppose) omit the frame pointer, so `__builtin_frame_address(0)` points to the saved RBP, and it's adding TWO pointers that yields the caller stack pointer (aka. CFA).



--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to