delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/10/26/06:11:40

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 59QABeGs3957659
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 59QABeGs3957659
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=PqS9nVW5
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 28D383857C6E
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1761473498;
bh=f5MSEFt3UqzKHfs7w/PzoyJayE0QFPXb+UfM3DxNlXg=;
h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=PqS9nVW5as9qNcWrXn/1dHP5vpXgsNRyNozwH+aEkeHNuNSUQqhHKQBTfboVP5fB1
pQ6Hz4Nk1j3/jJJ7PdZTzXRsKrgLk9Ay4apAMlLhLoi02TihTOQIRXydScnWdjs4Ac
dkqIkeHgF9ypLkUTAaS/Gq4+SNXlrodkFhYXgcIY=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D2E9F3858D26
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D2E9F3858D26
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761473441; cv=none;
b=R2/jUrzUGXaT2ThtiyYbF442GPZgNpF5cNWAjwN9gpySReFPwzCmjdUBOqFFdKm5MJjSDO9AKwCBwTuEcpHoH+m1nkb6eS15gvWiSpE6B2bdUdgJ21JKQZa/C2ZUrQ7S4jpW6g3X7ky0EcP55FSEf5nLxIQLIJpfxOTkxPuCpwo=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1761473441; c=relaxed/simple;
bh=Ohr/gCsa2Ukv+uCmUiBIKMG2J48NsMWPbNkl2xMPHCo=;
h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version;
b=IlQzOkjN1FapkWBDNi4KvhseEulYWFNwb2Uv8TCnRmY1MOESRadneCFTV/7CNm9QNRmtEM8HA9MdchBzgqape22PaJV0f8FKs/Fwc256MWYEFxlZzCD/2miSboucHrBUN/hxUwtv+rkCLNm/3fmhuaZeVqhFlslsPDUNVPH0DjY=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2E9F3858D26
Date: Sun, 26 Oct 2025 10:10:32 +0000
To: cygwin AT cygwin DOT com
Subject: Re: XSAVE-related segfaults observed under wine
Message-ID: <871pmqotzu.fsf@protonmail.com>
In-Reply-To: <87bjq9457k.fsf@protonmail.com>
References: <87bjq9457k DOT fsf AT protonmail DOT com>
Feedback-ID: 112775352:user:proton
X-Pm-Message-ID: 89180aa801c4d8c48fc7a7baf58f928a44bd0f2c
MIME-Version: 1.0
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Pip Cet via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Pip Cet <pipcet AT protonmail DOT com>
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>

Pip Cet <pipcet AT protonmail DOT 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 AT protonmail DOT 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 AT protonmail DOT 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)
-- 
2.51.1


-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019