DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 5BNCIN1J3223458 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 5BNCIN1J3223458 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=Jn96wVUQ X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72FD64BA2E30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1766492302; bh=cR2a8x3HOLeh6rDLxjqGPyax57CwclOFcHfmTnD7akA=; 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=Jn96wVUQRYjIKasGgJAqz1C8gsv7D+jylGXY4GfTOAI4RfcoqDkGFl7Wl3iYDYJyr vnScrQPDqeNQD9LuTPEJ4Q42tX3go07fa7xAyO+p2Bt9j+ENLJG4AM+YqByzrrDqAz X0KqLVNcviizzn7/utgRkCfH70IQSHbUAdRo1XsY= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C31434BA2E05 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C31434BA2E05 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766492249; cv=none; b=hyaFjjRFb0Cg03Tqu55rF06QTUr56UZbLP4BbfMqAtXSpk3R8Wl/P0CNYSJyrJDCIB0Ki7a46plRvI3pfsHjJrI/iXBUGVZ3jYBYTdOrLQy0jSsPAMR72wT4ETdobprIXWpPxVgS/UqmciZM0sH+sKytVcD0wqi6rNwe4hE/QHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766492249; c=relaxed/simple; bh=Qiwq3Hl/8oX90h0JeKho+y7iZsWfhF9hWj4vcWZSwAQ=; h=Date:From:To:Subject:Message-Id:Mime-Version:DKIM-Signature; b=gG/24thSYMJhJKoxaauqri15khc3aUwXIvRT61O+t6bKt6nn9yhNBH1cVU049baK8St+jF9VDBc2RATJ9Ec4PFTxZrhGfOkJCfHrRyeL8IEoHnSSp4XKp/znbwWciUQiI8h7h/WLe11PXaFA28+rCb42a4xOKum7tYJvT8pkIJk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C31434BA2E05 Date: Tue, 23 Dec 2025 21:17:25 +0900 To: cygwin AT cygwin DOT com Subject: Re: Recent testsuite/winsup.api/pthread/cancel2 failure Message-Id: <20251223211725.f1e869f65eaf4d6dba85c578@nifty.ne.jp> In-Reply-To: <20251223190713.e2efc476782898d55f00b64f@nifty.ne.jp> References: <20251214162637 DOT 1ee05b084788ba073fe94670 AT nifty DOT ne DOT jp> <20251214163936 DOT 6841fc62145d8f54cfa31fe7 AT nifty DOT ne DOT jp> <9d058204-fb3f-43b4-9e32-6adc7af12ff4 AT dronecode DOT org DOT uk> <20251217193737 DOT 3d3d686ebe3865c183315dc5 AT nifty DOT ne DOT jp> <20251222230450 DOT a2e308861cebfab9cdb5dcc1 AT nifty DOT ne DOT jp> <20251222233746 DOT d45ae16e4e06de5af7b27f26 AT nifty DOT ne DOT jp> <20251223190713 DOT e2efc476782898d55f00b64f AT nifty DOT ne DOT jp> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Tue__23_Dec_2025_21_17_25_+0900_JxB=r53Gkn4dsmH0" X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Takashi Yano via Cygwin Reply-To: Takashi Yano Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" This is a multi-part message in MIME format. --Multipart=_Tue__23_Dec_2025_21_17_25_+0900_JxB=r53Gkn4dsmH0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 23 Dec 2025 19:07:13 +0900 Takashi Yano wrote: > On Mon, 22 Dec 2025 16:46:53 +0100 > Corinna Vinschen wrote: > > On Dec 22 23:37, Takashi Yano via Cygwin wrote: > > > Alignment issue? > > > > > > This might be the right thing. > > > > > > diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc > > > index 86a00e76e..ec1e3c98c 100644 > > > --- a/winsup/cygwin/thread.cc > > > +++ b/winsup/cygwin/thread.cc > > > @@ -630,6 +630,8 @@ pthread::cancel () > > > threadlist_t *tl_entry = cygheap->find_tls (cygtls); > > > if (!cygtls->inside_kernel (&context)) > > > { > > > + if ((context._CX_stackPtr & 8) == 0) > > > + context._CX_stackPtr -= 8; > > > > Does that really help? Checking for 8 byte alignment is usually done > > with (X & 7) != 0, because this won't catch 16 byte aligned stacks. > > This code does not aim for 8 byte alignment, but 16n + 8. I assume > context._CX_stackPtr & 7 is always 0. I wonder if this assumption > is true. What if user code pushes 16 bit register such as AX? > It might be necessary to mask least 3 bits in advance. > > diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc > index 86a00e76e..628aef16f 100644 > --- a/winsup/cygwin/thread.cc > +++ b/winsup/cygwin/thread.cc > @@ -630,6 +630,9 @@ pthread::cancel () > threadlist_t *tl_entry = cygheap->find_tls (cygtls); > if (!cygtls->inside_kernel (&context)) > { > + context._CX_stackPtr &= 0xfffffffffffffff8UL; > + if ((context._CX_stackPtr & 8) == 0) > + context._CX_stackPtr -= 8; > context._CX_instPtr = (ULONG_PTR) pthread::static_cancel_self; > SetThreadContext (win32_obj_id, &context); > } I confirmed that the attached reproducer (repro.c) works fine with this patch. -- Takashi Yano --Multipart=_Tue__23_Dec_2025_21_17_25_+0900_JxB=r53Gkn4dsmH0 Content-Type: text/x-csrc; name="repro.c" Content-Disposition: attachment; filename="repro.c" Content-Transfer-Encoding: 7bit #include #include #include #define USE_ASYNC 1 static int thread_started; void *mythread(void *) { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); #if USE_ASYNC pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); #else pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); #endif thread_started = 1; for (;;) { __asm__ ("push %ax"); for (volatile int i=0; i<1000; i++) ; __asm__ ("pop %ax"); for (volatile int i=0; i<1000; i++) ; #if !USE_ASYNC pthread_testcancel(); #endif } return NULL; } int main() { int i; pthread_t t; void *result = 0; thread_started = 0; pthread_create(&t, NULL, mythread, NULL); while (thread_started == 0) usleep(1000); usleep(10000); pthread_cancel(t); pthread_join(t, &result); if (result != PTHREAD_CANCELED) printf("Thread started %d: result %d\n", thread_started, result); else printf("Thread canceled.\n"); return 0; } --Multipart=_Tue__23_Dec_2025_21_17_25_+0900_JxB=r53Gkn4dsmH0 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- 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 --Multipart=_Tue__23_Dec_2025_21_17_25_+0900_JxB=r53Gkn4dsmH0--