From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.10]) by sourceware.org (Postfix) with ESMTPS id 93D113850411 for ; Fri, 4 Sep 2020 19:51:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 93D113850411 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cygwin.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=corinna-cygwin@cygwin.com Received: from calimero.vinschen.de ([217.91.18.234]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MAPBF-1kP2CJ0VNT-00BvYF for ; Fri, 04 Sep 2020 21:51:44 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id A60D5A83A8D; Fri, 4 Sep 2020 21:51:43 +0200 (CEST) Date: Fri, 4 Sep 2020 21:51:43 +0200 From: Corinna Vinschen To: cygwin-developers@cygwin.com Subject: Re: Fibers and cygtls Message-ID: <20200904195143.GY4127@calimero.vinschen.de> Reply-To: cygwin-developers@cygwin.com Mail-Followup-To: cygwin-developers@cygwin.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:voC0VLTSV9eEmHob0WZwVHLXxDTLKOFQgrPQgX6/JWjlRbGXdQH pt6yKnXvo5fzljEffjyISWRdaOJfg3bJ6otnIa2VZsm3f01S0B3IwDLDwAR9yPgSgz1HaFW cf8+TSuqalYITew1iYl7qPCT3wtGhGt3DucPtpPz3IGzC/vrSE77uOvyvQ4wqGY4BheN5fd SmMmg755qzrP087OvPXYg== X-UI-Out-Filterresults: notjunk:1;V03:K0:j6u9TaE8Yis=:wPc21yhZ7N/h4r7sCUMZRa WUrw9DM3+SAyHM4ngn/VWp+JqcndPApyq9II9UTWyr53dFGxOW+vhrdHM3hZzJ2SZBLp8D8+6 cQ9IC2PWWJmSasf7ZuDGBAs9cWnq5JWcQLaf1vtmfjaI4OyydwydbHvhbEN0aX7zA2bXuC8fK hezOTFcJGV8CUoA6lkhLSS+HHBEQKg/zWh7egx07ChMfOKS6cM8QY9WDHE5ZFwEnaYhG4vKjW nm0axzKsuUR0K35OLR/t86HhCEVBXlZ9wIP8dr0HReB13+zm/TjX0aO2RofbKKbLs659Xbzss KeU60ZlHoO6c4S6iIsNLJZIOLUC1MRZjl4xharqaxbPz8Ii4CWZCBTHZSBuoFWWPwPu4pB4n2 Ldt20SJZb1BLcvJhTdO+gSL30TcDnBHWOjVNjj5ivzq9ljz0avfLtidYEOCn1LZ33s0uqSqAa Bvp0BygwEroPnI7u1d/kHrbKeCgwRLrVPVbN9SArjpZjG2hfKX+F8LvpRdRPsqfa0Ve2li738 L+93Ac9+p2i0CIU79VsUvFQFSFD1v9QbDIhNhLLGXPPzbnGb/ED2ibU3Fgabs1i7Rg4Cwir9u fH+GHZnLpUg+CXOFNzkFSwr3y3yOmOQvzrcQnWwASx0EV4beNQ3k3YibDLMjYDuLIvTQhjJsp nHPwmVXxe9yd8XILO9f7vH0wgda7G0kFAcNDxEVFNYN/g9ogubM2ov2kkMdl5y86Ob+e8wj1w ChBzkp3R6I0YX8dA342zalpH4z3/1HULyB+tVISizQ+xaFvhzFu3YoytWbFKFTvbrRiqOI6iR EWj4HkBoySVeJkmCOvjt5Oe313Qpn1Iq2+Whb1R066DFLt5lfeHv5v70HBCCO9LLB82OMWgsS P637dSWL79Iw1V1si21w== X-Spam-Status: No, score=-100.6 required=5.0 tests=BAYES_00, GOOD_FROM_CORINNA_CYGWIN, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Sep 2020 19:51:47 -0000 On Sep 4 12:13, David McFarland via Cygwin-developers wrote: > For a while now I've been trying to get nix working on Cygwin. It > compiles fine, but when it's run, it will exit unexpectedly in a way > that doesn't return an error code to Cygwin, and doesn't break in gdb. > > I tracked this to its use of boost coroutines, which use boost-context > to switch fibers. boost-context can be built using either a custom asm > implementation, or using windows fibers (CreateFiber). > > Both the boost-context asm implementation and win32 fibers switch the > NT_TIB StackBase and StackLimit fields (to a user provided buffer) when > switching fibers. StackBase is used to find the cygtls for the current > thread (in _my_tls, and with asm in gendef etc). Because of this, A > program will crash when any syscall is made from a fiber. Using Windows fibers verbatim is rather dangerous in the Cygwin context. There are more problems than just the tls area on the thread stack. If you call CreateFiber, you get an arbitrary stack created by Windows. The x86_64 stacks are all in reproducible slots in the thread stack area starting at 0x080000000L. One very important reason is that standard Windows stacks tend to break reproducability at fork() time. As for the i686 stacks... never mind, it's hopeless anyway. There's something vaguely similar inside Cygwin, the implementation of the alternate signal stack (sigaltstack). For a comment on how this works see the comment in exceptions.cc, line 1726ff. This may (or may not) be a role model for implementing coroutine stacks. Bottom line is, before trying to use Windows fibers, or before letting boost use Windows functions on Cygwin (sigh), check what other POSIX or BSD systems provide to implement coroutines. If there's an API, let's implement this API in Cygwin and then use that from user space. Corinna