https://bugs.winehq.org/show_bug.cgi?id=47970
--- Comment #3 from David Torok dt@zeroitlab.com --- (In reply to Zebediah Figura from comment #2)
Nice work, David. I assume this on top of current Staging is enough?
Thank you Zebediah! Current staging should be good enough. (I was testing with staging-git)
Regarding #1 - I'm not yet sure about the root cause, but I was receiving an i386 context in 64 bit mode. So the check is in place to allow a full i386 context when handling an x86_64 signal. I may need to track down the root cause, because this may or may not be desirable for wine. I have not checked how windows handles this.
Regarding #2 - I have an alternative version of this patch, which clones the syscall argument's from the parent frame, like wine currently does for 32 bit. That fix originally came from Andrew Wesie - and he mentioned that approach could cause a segmentation fault if the arguments are sufficiently close to the end of the stack memory allocation. So I figured, I might try an approach that does not involve growing the stack further. I guess it is best I explain the intent with the dispatcher version I posted: The initial sub instruction changes the thunk's return address to point into the first return of the thunk, this is crucial, and needed by the software to function. Then the thunk's return and the thunk's caller's return are saved into unused space in the TEB and later restored. That is how this version solves the problem of the syscall arguments having to be a specific distance away on the stack. (aka, only having space for one return address) You may recognize, I also left the original code path, in case the TEB was not available for some reason. I'm not sure if this could happen at all.
Regarding #3 - 64 bit linux signal contexts do not have DS: https://github.com/torvalds/linux/blob/6f0d349d922ba44e4348a17a78ea51b713596... Hence Wine cannot and will not capture DS and therefore DS_sig() does not exist for x86_64. My understanding is that DS and SS should always be the same on Windows, hence the manual set in the context structure.