From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 83F353858D32; Mon, 29 Aug 2022 13:21:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83F353858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661779283; bh=isnvh5znEZkLYUWI0CKmrhlzDEZIkDe4Na4ev44Gyo4=; h=From:To:Subject:Date:From; b=riJWdDF+H1bOUQptRnT1BjDB2NJMNRIPBybMGORMOTE+cz7E3kbfEU5VUBl42wV+p 9/WpZLMz+47sninfsQkBNPZhwR4Os5SRkTu6/szqg9OVCb93/GCOy4qLY33pcfepZS UdPGdGQ6WqV6zWKuI2aZ+g/6l/zK+GMOqRgSw1ak= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: cygtls: fix context alignment X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 717c36c0a4e387a73146c1181b7b89f091176e85 X-Git-Newrev: dcab768cb93e59712af5818736c4de783ae2c612 Message-Id: <20220829132123.83F353858D32@sourceware.org> Date: Mon, 29 Aug 2022 13:21:23 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Ddcab768cb93= e59712af5818736c4de783ae2c612 commit dcab768cb93e59712af5818736c4de783ae2c612 Author: Corinna Vinschen Date: Mon Aug 29 15:18:53 2022 +0200 Cygwin: cygtls: fix context alignment =20 A hang was encountered, apparently triggered by commit 63b503916d42, changing tls_pathbufs from malloc'ed to HeapAlloc'ed memory. After lengthy debugging it transpired that adding the heap handle to the tls_pathbuf struct added 8 bytes to the cygtls area, thus moving the "context" member by 8 bytes, too, so it was suddently unaligned. =20 Fix this for now by changing the alignment. =20 Fix this once and for all, by adding code to the gentls_offsets script to check if the alignment of the "context" member is 16 bytes. If not, print a matching error message, remove the just generated file, and exit with error. =20 FIXME: It would be really nice to find a way to auomate the correct alignment of the "context" member, but I don't see any way to use alignment attributes to get what we need here. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/local_includes/cygtls.h | 7 +++++-- winsup/cygwin/scripts/gentls_offsets | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/local_includes/cygtls.h b/winsup/cygwin/local_in= cludes/cygtls.h index 018a59946..61c4cbeef 100644 --- a/winsup/cygwin/local_includes/cygtls.h +++ b/winsup/cygwin/local_includes/cygtls.h @@ -178,11 +178,14 @@ public: /* Do NOT remove this public: line, it's a ma= rker for gentls_offsets. */ siginfo_t *sigwait_info; HANDLE signal_arrived; bool will_wait_for_signal; +#if 0 long __align; /* Needed to align context to 16 byte. */ +#endif /* context MUST be aligned to 16 byte, otherwise RtlCaptureContext fails. If you prepend cygtls members here, make sure context stays 16 byte - aligned. */ - ucontext_t context; + aligned. The gentls_offsets script checks for that now and fails + if the alignment is wrong. */ + ucontext_t __attribute__((__aligned__(__alignof__(long double)))) contex= t; DWORD thread_id; siginfo_t infodata; struct pthread *tid; diff --git a/winsup/cygwin/scripts/gentls_offsets b/winsup/cygwin/scripts/g= entls_offsets index 0adb702a3..040b5de6b 100755 --- a/winsup/cygwin/scripts/gentls_offsets +++ b/winsup/cygwin/scripts/gentls_offsets @@ -98,3 +98,12 @@ gawk -v start_offset=3D"$start_offset" '\ } } ' ${tmp_file} > "${output_file}" +# Check if the `context' member is 16 bytes aligned. Delete output_file +# and bail out with error if not. +MOD=3D$(awk '/_cygtls.context_p/{ print $3 % 16; }' "${output_file}") +if [ $MOD -ne 0 ] +then + echo "Error: _cygtls.context member is not 16 bytes aligned!" + rm "${output_file}" + exit 1 +fi