From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25391 invoked by alias); 26 Apr 2018 07:58:21 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 24122 invoked by uid 89); 26 Apr 2018 07:58:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,SPF_PASS,TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=set-up, 2.10 X-HELO: mail-wm0-f46.google.com Received: from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Apr 2018 07:58:09 +0000 Received: by mail-wm0-f46.google.com with SMTP id j4so11261935wme.1 for ; Thu, 26 Apr 2018 00:58:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:openpgp:autocrypt :message-id:date:user-agent:mime-version; bh=Exzzql9TZZ+yOqYuwfbe6zIPnB7Eo9OF+6qL/EUdxNs=; b=LSvV/Ur0DZrbnP40jCG1EbTHEIU6BmCi1n7CT8uNZGrXQApyatq75twPGnZ7cYH8yq 1q85KezzBS1comZnJY7lL1TYk5agn9uQwg4ira3fpZOKXtN5+xc1T+fpzl4Mz3rm/6Mh +8jv/o07nZTGEO51lgHXB8XjqjtuPHq48PhOEQv6JDplYPPrXsw3XwSZQi6tqIQVkHmt GPRqw4Km/xGEFy0n5XQGdZfD/4SQCdzeowUzbwJ+7A6mxm4fjYjNgaGOdPIvZ8CL4SxU JjAHuV97+AGrqWZ8nz2SmZVGcykzzb+1jVNZ6piC8YCmO5icRuBcVecTwSt0tyhbJHy4 Jv1w== X-Gm-Message-State: ALQs6tATpx/DaS5cgfDHwx+Ks+1mUxDE8Fj2eWhkgXusITrN7n7zmQyW 5wN6Rd+yleVZhKs6LWXaBCVlFg== X-Google-Smtp-Source: AIpwx4/F9psJFiYJHps2M4gYKtiXfTq2ZOdwniI7Kl6CG1AIbcTc5huI4lfB/ZSJih3uORf7tcDl2g== X-Received: by 10.80.181.85 with SMTP id z21mr43109720edd.223.1524729487534; Thu, 26 Apr 2018 00:58:07 -0700 (PDT) Received: from localhost.localdomain (200116b8202bec003e7c9aa70cdc3f0b.dip.versatel-1u1.de. [2001:16b8:202b:ec00:3e7c:9aa7:cdc:3f0b]) by smtp.googlemail.com with ESMTPSA id y29sm11527096edl.6.2018.04.26.00.58.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Apr 2018 00:58:06 -0700 (PDT) To: cygwin@cygwin.com From: Thomas Zimmermann Subject: Bug: Synchronous signals broken on Cygwin 64 Openpgp: preference=signencrypt Autocrypt: addr=tdz@users.sourceforge.net; prefer-encrypt=mutual; keydata= xsDiBEQ8FzARBAD9199cx5bJZ7nvSuaGA6ZLv1WyPtIeKWXj8mOfpn/tfmKUlzFijUChGBGP 1/FGssV/KnR+1zWdxsgtYuE8bbslJEGRP/fgaOgxisCKjkU8/SKXKKYoxS568m2TwBO512so PTj2mC3yWz4nU7ZTmgoJzf8r8TDZ3GBbHCoO21tUjwCgkjiAm08Kh72NtbMysXW88eOcFfUE ANvt1VrkyDjLD/viv7MHYUMLKLaFdNZUnJi4Rx6NwIqNxLDeGyPPp17/X2ls397Wl9PAZRJB 96/3E5WAOCyaKJc605luoyvv0CJ5+VuAQDVXKGdX/jr7EnhkyXmcm8ChKR/1Lct6jn5Wp922 utdklQcYEkSNMJbRsKReluxXaD6kBAC2qI/mOyRtJLxoszYG2hLf1BAOopJb13J1TCRQv3Df El2zmbPyYOfMQzbnFBrZ5yMve6I5/9hWksMMUWrdtgGDEsBFMa8iFb9FPsbKrDBmR66wpNFf s7GPEcWpIueBGu+vmXtUN8zE4mvUxFixc7iiPx46TCctKFqujGf6ubhlpc0tVGhvbWFzIFpp bW1lcm1hbm4gPHRkekB1c2Vycy5zb3VyY2Vmb3JnZS5uZXQ+wl0EExECAB0FAkQ8FzAGCwkI BwMCBBUCCAMEFgIDAQIeAQIXgAAKCRDZ2tfUTvHfCIydAJ4ndgH+dGp131Bx0su0VkWIiCfg iwCdHB339NSWt0kXY4+/Zhfpenzj9EXOwE0ERDwXMRAEAKcJyo9UpIp4Z4Mer58CL+ErcgwU xWdH5yhRV0++D70R6N5e+Yoa20V5trrNhpCEeAvjLW77VRqCYPO3hn0mmN2jSO8qMdBn7rXS ND9WFrlnSSCGsYQeoKj0z2KlQ8Waxg+r3b23azbMinF30x9303S3ZhrWvSf8wxIgd+u3HeXj AAMGA/9s/AWniacRR8T2ABN0ASjXp1SCSYmezL9Jp8MfSWvLcNrB/0Oi/o3+1HfJiTHg7o8l H6tpqScWsKpPZbYxmo9vb9sVjAOLzGpeV8S6Pe1pcXfiOuZLMJ5OTga6GxWimmP7rrWKTIlP x57wXD+v6c4A4VYW973YXNh1mVXwON3ydMJGBBgRAgAGBQJEPBcxAAoJENna19RO8d8IASEA niQqMp4Yd00/t47D09opsugE9GBHAJ9sJZgtyq9lLB3xCFm16nooejR/XA== Message-ID: Date: Thu, 26 Apr 2018 07:58:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="lFbo5slULApREF5dDJHaWmp8CmioOLeRi" X-IsSubscribed: yes X-SW-Source: 2018-04/txt/msg00316.txt.bz2 --lFbo5slULApREF5dDJHaWmp8CmioOLeRi Content-Type: multipart/mixed; boundary="wtxaMxR8iwSUN3mw6nddWiunoTLQjB9QC"; protected-headers="v1" From: Thomas Zimmermann To: cygwin@cygwin.com Message-ID: Subject: Bug: Synchronous signals broken on Cygwin 64 --wtxaMxR8iwSUN3mw6nddWiunoTLQjB9QC Content-Type: multipart/mixed; boundary="------------2835FB10DBC0098E1855BDF8" Content-Language: en-US This is a multi-part message in MIME format. --------------2835FB10DBC0098E1855BDF8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-length: 2443 Hello mailing list, I noticed that synchronous signals (e.g., SIGSEGV, SIGFPE) appear to be broken on 64-bit Cygwin systems. I could not find additional information on the mailing list. If this is not already a known problem, you'll find some analysis below. I use Cygwin DLL 2.10 with all packages up-to-date. My test system runs Windows 7. The expected behavior is that an installed signal handler runs exactly once for a signal and the OS terminates the program if the handler returns. This works on 32-bit Cygwin. From my observation, Cygwin 64 differs in the follow ways: 1) Generating a synchronous signal on the main thread, makes the signal handler enter an endless loop. The attached test 'syncsig.c' illustrates this. 2) Generating a synchronous signal on an additional POSIX thread ignores the installed signal handler entirely. The handler does not run and the program gets terminated immediately. The attached test 'syncsig_mt.c' illustrates this. As mentioned, both cases work correctly on 32-bit installations. I cannot point to the exact location of the problem, but it appears that the Cygwin exception-handler code is not set up by 64-bit code. In case 2) I can see the Windows function KiUserExceptionDispatcher() being executed for the synchronous signal on the affected thread. This should lead to a call to the Cygwin exception handler. It does for 32-bit, but not for 64-bit code. =46rom what I've seen, the exception handler is installed in the c'tor exception::exception(). [exception.cc:138] The only invocation I found was in SetThreadName(). [miscfuncs.cc:951] This set-up code is 32-bit-only. BTW, is there a bug tracker for Cygwin? I'd open a bug report there, or add the information to an existing one. Best regards Thomas [exception.cc:138] https://cygwin.com/git/gitweb.cgi?p=3Dnewlib-cygwin.git;a=3Dblob;f=3Dwinsup= /cygwin/exception.h;h=3Dffff7464ba11b5526fcf9d13e32334912a30a3b0;hb=3D4c73a= d6b20378e4b74355fcdb2005f2aac489c9f#l138 [miscfuncs.cc:951] https://cygwin.com/git/gitweb.cgi?p=3Dnewlib-cygwin.git;a=3Dblob;f=3Dwinsup= /cygwin/miscfuncs.cc;h=3D3ad658739ad9e85868ca74ce2e86aa6ddbdbfb37;hb=3D4c73= ad6b20378e4b74355fcdb2005f2aac489c9f#l951 --=20 Implement thread-safe and fault-tolerant software in C: visit picotm.org -- GnuPG: http://tdz.users.sourceforge.net/tdz.asc Fingerprint: 16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08 Website: transactionblog.org --------------2835FB10DBC0098E1855BDF8 Content-Type: text/x-csrc; name="syncsig.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="syncsig.c" Content-length: 1071 /* * This test program works on 32-bit and 64-bit Cygwin. On 32-bit=20 * systems, the signal handler runs *exactly* once, which is the correct * behaviour. On 64-bit systems, the exception code enters an endless=20 * loop and the signal handler runs over and over. * * Compile with * * gcc -Wall -O0 -osyncsig ./syncsig.c * * Run with * * ./syncsig * * Expected Result * * Program prints "signal handler running" once * * Actual Result * * On 64-bit systems, the handler runs in an endless loop * */ #include #include #include static void signal_handler(int signum, siginfo_t* info, void* ucontext) { fprintf(stderr, "signal handler running\n"); // unsafe in real code! } int main(int argc, char* argv[]) { struct sigaction act =3D { .sa_sigaction =3D signal_handler, .sa_flags =3D SA_SIGINFO, }; sigemptyset(&act.sa_mask); sigaction(SIGFPE, &act, NULL); /* Trigger Windows Exception for division by zero */ argc /=3D !argc; fprintf(stderr, "no exception generated\n"); return EXIT_SUCCESS; } --------------2835FB10DBC0098E1855BDF8 Content-Type: text/x-csrc; name="syncsig_mt.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="syncsig_mt.c" Content-length: 1185 /* * This test program works on 32-bit Cygwin, but fails on 64-bit systems. * Running a signal handler for SIGFPE on the created POSIX thread does * not work. * * Compile with * * gcc -Wall -O0 -pthread -osyncsig_mt ./syncsig_mt.c * * Run with * * ./syncsig_mt * * Expected Result * * Program prints "signal handler running" * * Actual Result * * No output on 64-bit systems, signal handler does not run * */ #include #include #include #include static void signal_handler(int signum, siginfo_t* info, void* ucontext) { fprintf(stderr, "signal handler running\n"); // unsafe in real code! } static void* thread_start(void* arg) { int argc =3D *(int*)arg; /* Trigger Windows Exception for division by zero */ argc /=3D !argc; fprintf(stderr, "no exception generated\n"); return NULL; } int main(int argc, char* argv[]) { struct sigaction act =3D { .sa_sigaction =3D signal_handler, .sa_flags =3D SA_SIGINFO, }; sigemptyset(&act.sa_mask); sigaction(SIGFPE, &act, NULL); pthread_t thread; pthread_create(&thread, NULL, thread_start, &argc); pthread_join(thread, NULL); return EXIT_SUCCESS; } --------------2835FB10DBC0098E1855BDF8-- --wtxaMxR8iwSUN3mw6nddWiunoTLQjB9QC-- --lFbo5slULApREF5dDJHaWmp8CmioOLeRi Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-length: 195 -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQQW//WZgvjlqhjGUiDZ2tfUTvHfCAUCWuGGhwAKCRDZ2tfUTvHf CEnhAJ9wLkhD26VXiy8Bn9RD+gDFC2l6TgCfcvzQdlj1X4exFpdCJNoom9eNINI= =JJyM -----END PGP SIGNATURE----- --lFbo5slULApREF5dDJHaWmp8CmioOLeRi--