From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68091 invoked by alias); 17 Nov 2015 05:41:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 68059 invoked by uid 89); 17 Nov 2015 05:41:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: smtp.gentoo.org Received: from smtp.gentoo.org (HELO smtp.gentoo.org) (140.211.166.183) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 17 Nov 2015 05:41:35 +0000 Received: from vapier.lan (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with SMTP id 950D934063E; Tue, 17 Nov 2015 05:41:33 +0000 (UTC) Date: Tue, 17 Nov 2015 05:41:00 -0000 From: Mike Frysinger To: Kevin Buettner Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] PPC sim: Don't close file descriptors 0, 1, or 2 Message-ID: <20151117054133.GI31395@vapier.lan> Mail-Followup-To: Kevin Buettner , gdb-patches@sourceware.org References: <20151116145807.4aedd84f@pinnacle.lan> <20151116235317.GF31395@vapier.lan> <20151116210533.058520d2@pinnacle.lan> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="cf0hFtnykp6aONGL" Content-Disposition: inline In-Reply-To: <20151116210533.058520d2@pinnacle.lan> X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg00332.txt.bz2 --cf0hFtnykp6aONGL Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2273 On 16 Nov 2015 21:05, Kevin Buettner wrote: > On Mon, 16 Nov 2015 18:53:17 -0500 Mike Frysinger wrote: > > On 16 Nov 2015 14:58, Kevin Buettner wrote: > > > This occurs because the powerpc simulator closes, on behalf of the > > > testcase, the file descriptors associated with stdin, stdout, and > > > stderr. GDB still needs these descriptors to communicate with the > > > user or, in this case, with the testing framework. > >=20 > > special casing this logic in the sim looks wrong to me. why > > is the testcase itself trying to close stdin/stdout/stderr ? >=20 > It's not just one test case, but a bunch of them, 229 to be exact. >=20 > I haven't investigated all of them, but in many (if not all) of them, > close() is being called during exit(). This problem arises when > GDB runs the testcase to completion. sounds like that code is broken then ... > sim/common achieves the same result by placing file descriptors 0, 1, > 2, and MAX_CALLBACK_FDS together in a circular fd_buddy list. (See > os_init() in sim/common/callback.c.) close() is never called on any of > these descriptors due to the fact that they're in a (circular) list of > greater than one element. When one of these descriptors (0, 1, or 2) > is closed (in os_close()), it is simply removed from the fd_buddy > list, with no close() operation actually being performed. Note that > when the final one is "closed", it is still on an fd_buddy list with > MAX_CALLBACK_FDS - hence it won't be closed either. >=20 > So sim/common is doing the same thing as my proposed patch for ppc; > sim/common is just using a more elegant mechanism to avoid calling > close() on these three file descriptors. the difference is that this code sequence misbehaves after your change: close(1); write(1, "foo", 3); under the common sim, the write will return EBADF. considering how much of common/ came from ppc/ i'm a little surprised virtualization of the fd table didn't. it would be nice if we could at least hide these three fds (a static array of 3 bools maybe?), but i won't push hard for you to do that. you should however be making the same change to the other emulation layers. you've done it only to netbsd, but the ppc sim has the same code for the other layers too (like unix, and ...). -mike --cf0hFtnykp6aONGL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJWSr4NAAoJEEFjO5/oN/WBuiwP/1kfKWKXVRaXbcTwVuTKmP2C Xh9Vn66cf5kwUnbMMWf62QJLx/TOusGIhWL24wjJmiLRkbadLu57lqhlna1o7CIH IZYuToi+vKxZ0iqxUOAr75XXTOAEAnIVbs8IQk+PYxqmuZ/bSLCwKlSjuwKIgkJt fZx8ItlAWNLSAFlKsGMgFA3wGoifmZk5jh8b8hD2LtPH+8nzyX8u49wnwb9BFmot zfcgwUvBPk2uKUQwwoytGsIGGZ2V736ZEYQybRFJ9cWl/LJhwk5SpwyZk93Ma3WW CZnNUvxs6xoDp9Z3TLLqcuKzRBFY+wKV0pNiT3Rlk4WmZ7kO+aCCrugOA/fp4ioX 9TUW9IVFB/MUM8h4WQDjMQec7/Dml2jYyNc/F/WcPZS7T82c27K8tYi8KA5xltO0 BkbmmxYdJyXqlWggA8oKlmw8U+2bpj/QQmsurbfmKjf2zpy8htcaPn1y8wdKApkC ceYnf0BfD2eMhRjJdrO7yZEmghE1ungr8fyAh3upUmoQDdnvsyTsXuhVncFkX1h8 uM+B2xW/xfzRCE0HSYI5y9L0Z6xjas9NsnpXom92pCk2NEM8lzH2d7hV6Xm2/P+b 0JLrueuhY/3gzVC8NU8MqybGa4AXwE0C0Od3Qve7UvBbbnUSmRhbc3l9DzNrqIoF mj9hBp8B+H0dMTCn30mD =Yi8a -----END PGP SIGNATURE----- --cf0hFtnykp6aONGL--