From owner-svn-src-head@freebsd.org Sun Aug 28 01:52:17 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 51A84B772AA; Sun, 28 Aug 2016 01:52:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C78DB982; Sun, 28 Aug 2016 01:52:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u7S1qBd3042367 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sun, 28 Aug 2016 04:52:12 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u7S1qBd3042367 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u7S1qAN7042366; Sun, 28 Aug 2016 04:52:10 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 28 Aug 2016 04:52:10 +0300 From: Konstantin Belousov To: Andrey Chernov Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r304928 - in head/lib/libc: amd64/sys i386/sys sys Message-ID: <20160828015210.GI83214@kib.kiev.ua> References: <201608272303.u7RN3N0D078505@repo.freebsd.org> <9bcf10db-de3f-33ce-e418-03ce3283ac90@freebsd.org> <20160828005637.GG83214@kib.kiev.ua> <59ac1812-7c77-b677-51c4-dcadc6b2be7f@freebsd.org> <20160828011501.GH83214@kib.kiev.ua> <80ad9e03-74bc-8c99-666f-787772bef2b9@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <80ad9e03-74bc-8c99-666f-787772bef2b9@freebsd.org> User-Agent: Mutt/1.6.1 (2016-04-27) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Aug 2016 01:52:17 -0000 On Sun, Aug 28, 2016 at 04:25:46AM +0300, Andrey Chernov wrote: > On 28.08.2016 4:15, Konstantin Belousov wrote: > >> POSIX: "No function in this volume of POSIX.1-2008 shall set errno to zero." > > I am quite curious where ptrace(2) is defined by POSIX. > > POSIX just repeats C99 statement for its own functions, supporting this > rule too, but C99 rule is more general and related to any library functions. > > >> POSIX: "For each thread of a process, the value of errno shall not be > >> affected by function calls or assignments to errno by other threads." > > And ? What should the citation add new to the substance > > of the code change ? > > This is for your comment "On both i386 and amd64, the errno symbol was > directly referenced, which only works correctly in single-threaded > process." I still do not understand what you want to say there. Errno as the symbol existing in the symbol table of libc, gives 'POSIX errno' value for the main thread. Preprocessor definition converts C language accesses to errno into some indirections which result in accesses to per-thread errno location. The bug in x86 asm code was due to direct usage of errno. What POSIX requires from the C-level errno symbol does not define a semantic for the memory location pointed to by the errno sym-table symbol. And amusingly, all other arches did it right, except aarch64 and risc-v copied from aarch64. They lack the wrapper at all, I wrote aarch64 ptrace.S already. > > >> C99 statement sounds stricter: > >> "The value of errno is zero at program startup, but is never set to zero > >> by any library function. 176)" > >> And syscall is not different from library function from C99 point of view. > > Point me to a single line in C99 which mentions ptrace(). > > > > Do you understand what did the commit changed, and what it did not ? > > Setting errno to zero before the syscall was the existing behaviour > > before the change, and I did not modified anything there. But previous > > wrapper set errno to zero in main thread even if called from some other > > thread, which was the bug fixed. > > If you may notice, I don't blame you and don't say that you introduce > setting errno to 0. I just want to bring your attention to the problem > while you are in that area and familiar with it. > I know that POSIX requires that POSIX-defined functions did not modified errno except on error, but it cannot require anything from functions which are not defined by the standard. I agree that it would be more consistent for ptrace(2) to not do that as well, but the behaviour is already there for 35 years and I do not view the 'consistency' as a serious reason to break ABI and introduce random failures for innocent consumers of it. On Sun, Aug 28, 2016 at 04:37:11AM +0300, Andrey Chernov wrote: > On 28.08.2016 4:25, Andrey Chernov wrote: > >> Point me to a single line in C99 which mentions ptrace(). > > Already done: ptrace == "any library function". *Shaking head* 'Library functions' references in the context of C99/C11 are implicitely limited to the functions defined by the chapter 7 Library of the standard. To play this sillyness to the end, please answer whether I am allowed to provide static functions definitions in the libraries headers ? E.g. clause 7.1.2 6 of C11 says: Any declaration of a library function shall have external linkage.