XSAVE-related segfaults observed under wine

Brian Inglis Brian.Inglis@SystematicSW.ab.ca
Sun Oct 26 15:13:54 GMT 2025


On 2025-10-26 04:10, Pip Cet via Cygwin wrote:
> Pip Cet <pipcet@protonmail.com> writes:
> 
>> This is about a bug which was observed when running msys2 binaries in
>> Wine under recent Linux kernels on new Intel/AMD CPUs that support the
>> PKU/PKRU feature, but it appears to be a bug in Cygwin; specifically,
>> in:
> 
> I don't think this was ever merged, but I'm not aware of any remaining
> objections. Rebased patch follows:
> 
>  From 7ed7da412248ec0b2d27157980d4c2f6fe63398c Mon Sep 17 00:00:00 2001
> From: Pip Cet <pipcet@protonmail.com>
> Date: Sun, 26 Oct 2025 10:01:33 +0000
> Subject: [PATCH] Cygwin: Fix segfault when XSAVE area sizes are unaligned
> 
> On recent AMD and Intel CPUs, the PKU/PKRU feature reports an XSAVE
> storage area of just 8 bytes. This is exposed to Cygwin code when we
> run in Wine under Linux.
> 
> The xsave64 instruction requires a memory area aligned to 64 bytes; in
> the setting above, we would no longer meet that requirement, causing
> segfaults and abnormal program termination.
> 
> This fix aligns the size of the structure we allocate on the stack
> before performing an xsave64 to the next 64-byte multiple; the old
> code already guarantees that structures of such size are aligned
> properly for xsave64. This fixes the issue on Linux and hopefully
> avoid it on future Windows systems which expose such features.
> 
> Signed-off-by: Pip Cet <pipcet@protonmail.com>
> ---
>   winsup/cygwin/scripts/gendef | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/winsup/cygwin/scripts/gendef b/winsup/cygwin/scripts/gendef
> index d60d45431..2dc9bce53 100755
> --- a/winsup/cygwin/scripts/gendef
> +++ b/winsup/cygwin/scripts/gendef
> @@ -243,6 +243,8 @@ sigdelayed:
>   	xorl	%ecx,%ecx
>   	cpuid	# get necessary space for xsave
>   	movq	%rbx,%rcx
> +	addq	\$63, %rbx
> +	andq	\$-64, %rbx # align to next 64-byte multiple
>   	addq	\$0x48,%rbx # 0x18 for alignment, 0x30 for additional space
>   	subq	%rbx,%rsp
>   	movl	%ebx,0x24(%rsp)

Wonder if it might be clearer ;^> to orq \$63,%rbx; incq %rbx?

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                 -- Antoine de Saint-Exupéry


More information about the Cygwin mailing list