From owner-freebsd-standards@FreeBSD.ORG Thu Jul 17 03:13:02 2014 Return-Path: Delivered-To: freebsd-standards@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 01674837 for ; Thu, 17 Jul 2014 03:13:02 +0000 (UTC) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DD0C02207 for ; Thu, 17 Jul 2014 03:13:01 +0000 (UTC) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.14.8/8.14.8) with ESMTP id s6H3D1V9052358 for ; Thu, 17 Jul 2014 03:13:01 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-standards@FreeBSD.org Subject: [Bug 191906] New: pthread_cancel(NULL) on FreeBSD returns EINVAL, not ESRCH according to manpage Date: Thu, 17 Jul 2014 03:13:01 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: standards X-Bugzilla-Version: 11.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: yaneurabeya@gmail.com X-Bugzilla-Status: Needs Triage X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-standards@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jul 2014 03:13:02 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191906 Bug ID: 191906 Summary: pthread_cancel(NULL) on FreeBSD returns EINVAL, not ESRCH according to manpage Product: Base System Version: 11.0-CURRENT Hardware: Any OS: Any Status: Needs Triage Severity: Affects Only Me Priority: --- Component: standards Assignee: freebsd-standards@FreeBSD.org Reporter: yaneurabeya@gmail.com According to pthread_cancel(3) and opengroup, pthread_cancel should only return ESRCH, not EINVAL (but it apparently returns EINVAL for thread=NULL). Found with the NetBSD libthr ATF testcases. % cc -lpthread -Wall -o /root/test_pthread_cancel /root/test_pthread_cancel.c % /root/test_pthread_cancel Invalid argument % cat /root/test_pthread_cancel.c #include #include #include int main(void) { int rv = pthread_cancel(NULL); printf("%s\n", strerror(rv)); return (0); } -- You are receiving this mail because: You are the assignee for the bug. From owner-freebsd-standards@FreeBSD.ORG Thu Jul 17 19:57:38 2014 Return-Path: Delivered-To: freebsd-standards@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 536297FB for ; Thu, 17 Jul 2014 19:57:38 +0000 (UTC) Received: from khavrinen.csail.mit.edu (khavrinen.csail.mit.edu [IPv6:2001:470:8b2d:1e1c:21b:21ff:feb8:d7b0]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "khavrinen.csail.mit.edu", Issuer "Client CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id EB82C2B0B for ; Thu, 17 Jul 2014 19:57:37 +0000 (UTC) Received: from khavrinen.csail.mit.edu (localhost [127.0.0.1]) by khavrinen.csail.mit.edu (8.14.7/8.14.7) with ESMTP id s6HJvZC7087403 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL CN=khavrinen.csail.mit.edu issuer=Client+20CA); Thu, 17 Jul 2014 15:57:35 -0400 (EDT) (envelope-from wollman@khavrinen.csail.mit.edu) Received: (from wollman@localhost) by khavrinen.csail.mit.edu (8.14.7/8.14.7/Submit) id s6HJvZJA087400; Thu, 17 Jul 2014 15:57:35 -0400 (EDT) (envelope-from wollman) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <21448.10927.483892.974746@khavrinen.csail.mit.edu> Date: Thu, 17 Jul 2014 15:57:35 -0400 From: Garrett Wollman To: yaneurabeya@gmail.com Subject: Re: [Bug 191906] New: pthread_cancel(NULL) on FreeBSD returns EINVAL, not ESRCH according to manpage In-Reply-To: References: X-Mailer: VM 7.17 under 21.4 (patch 22) "Instant Classic" XEmacs Lucid X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (khavrinen.csail.mit.edu [127.0.0.1]); Thu, 17 Jul 2014 15:57:35 -0400 (EDT) Cc: freebsd-standards@FreeBSD.org X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jul 2014 19:57:38 -0000 < According to pthread_cancel(3) and opengroup, pthread_cancel should > only return ESRCH, not EINVAL (but it apparently returns EINVAL for > thread=NULL). According to my copy of SUSv7 (1003.1-2008): RETURN VALUE If successful, the pthread_cancel ( ) function shall return zero; otherwise, an error number shall be returned to indicate the error. ERRORS The pthread_cancel ( ) function shall not return an error code of [EINTR]. That is the entirety of what it says about errors for pthread_cancel(). (Page 1572 in the SUSv7 PDF for those following at home.) SUSv6 (1003.1-2001) said something different: ERRORS The pthread_cancel ( ) function may fail if: [ESRCH] No thread could be found corresponding to that specified by the given thread ID. The pthread_cancel ( ) function shall not return an error code of [EINTR]. This error was removed, and passing an invalid pthread_t value to pthread_cancel() is now UNDEFINED in SUSv7. This was changed because pthread_t is a pointer in some branded Unix systems (as well as FreeBSD), and SUSv6 mistakenly required pthread_t to be an arithmetic type. It was felt that these implementations should not be required to validate pthread_t values -- they should be entitled to rely on C's usual lack-of-semantics for invalid pointers. (Recall that in C, merely *loading* an invalid pointer causes undefined behavior, so you clearly are already in UB territory if you try to pass one to a function.) The test you cite is simply wrong, albeit for the opposite reason: int main(void) { int rv = pthread_cancel(NULL); printf("%s\n", strerror(rv)); return (0); } There is no guarantee that NULL can be converted to pthread_t, and applications are not allowed to "look inside" the typedef and use the special properties of the underlying type. -GAWollman From owner-freebsd-standards@FreeBSD.ORG Thu Jul 17 21:21:14 2014 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6B802577; Thu, 17 Jul 2014 21:21:14 +0000 (UTC) Received: from mail-ie0-x232.google.com (mail-ie0-x232.google.com [IPv6:2607:f8b0:4001:c03::232]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 32A432322; Thu, 17 Jul 2014 21:21:11 +0000 (UTC) Received: by mail-ie0-f178.google.com with SMTP id tp5so3783226ieb.9 for ; Thu, 17 Jul 2014 14:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=IZVzJmxEvWTBULTtkTLUQ9rfViuyr+cBt5rB+qIPYW4=; b=hoJoQ42jzbQZayj3HApLos11jFzOqn6AQxncmwBQwnAhinqn6uZ4/NjS/Xca+/8Gk5 DGnG5HshC4UYw1IG+8vRx8yWdeekdIvd8a0zSA5yZS7QQDA69+zrVdJKS2j3qxwF2waZ gQ8avgGOLKGW9HSzTWcTdA36Yfx1+Y3wpU0icp29ZgxTit9OJ00tSHlABXm8cUwhei8s ly6X4tR8CkF+iVtm4/YwiFev4oNfv2/ELSTdlaRfv192GnUsB7cpwHsV959i3HDgdBBs 2cy5Y9H1wD+YZrb6G8S+iRP4b8a8KEnYvZytAWFmkW9vY/LeAEv6X0zN68/pdoeA1P2U By/w== MIME-Version: 1.0 X-Received: by 10.50.88.37 with SMTP id bd5mr32486396igb.1.1405632070602; Thu, 17 Jul 2014 14:21:10 -0700 (PDT) Received: by 10.50.155.195 with HTTP; Thu, 17 Jul 2014 14:21:10 -0700 (PDT) In-Reply-To: <21448.10927.483892.974746@khavrinen.csail.mit.edu> References: <21448.10927.483892.974746@khavrinen.csail.mit.edu> Date: Thu, 17 Jul 2014 14:21:10 -0700 Message-ID: Subject: Re: [Bug 191906] New: pthread_cancel(NULL) on FreeBSD returns EINVAL, not ESRCH according to manpage From: Garrett Cooper To: Garrett Wollman Content-Type: text/plain; charset=UTF-8 Cc: bugzilla-noreply@FreeBSD.org, freebsd-standards@freebsd.org X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jul 2014 21:21:14 -0000 On Thu, Jul 17, 2014 at 12:57 PM, Garrett Wollman wrote: > < >> According to pthread_cancel(3) and opengroup, pthread_cancel should >> only return ESRCH, not EINVAL (but it apparently returns EINVAL for >> thread=NULL). > > According to my copy of SUSv7 (1003.1-2008): > > RETURN VALUE > If successful, the pthread_cancel ( ) function shall return zero; otherwise, an error number shall be > returned to indicate the error. > ERRORS > The pthread_cancel ( ) function shall not return an error code of [EINTR]. > > That is the entirety of what it says about errors for > pthread_cancel(). (Page 1572 in the SUSv7 PDF for those following at > home.) > > SUSv6 (1003.1-2001) said something different: > > ERRORS > The pthread_cancel ( ) function may fail if: > [ESRCH] No thread could be found corresponding to that specified by the given thread > ID. > The pthread_cancel ( ) function shall not return an error code of [EINTR]. > > This error was removed, and passing an invalid pthread_t value to > pthread_cancel() is now UNDEFINED in SUSv7. This was changed because > pthread_t is a pointer in some branded Unix systems (as well as > FreeBSD), and SUSv6 mistakenly required pthread_t to be an arithmetic > type. It was felt that these implementations should not be required > to validate pthread_t values -- they should be entitled to rely on C's > usual lack-of-semantics for invalid pointers. (Recall that in C, > merely *loading* an invalid pointer causes undefined behavior, so you > clearly are already in UB territory if you try to pass one to a > function.) > > The test you cite is simply wrong, albeit for the opposite reason: > > int > main(void) > { > int rv = pthread_cancel(NULL); > > printf("%s\n", strerror(rv)); > return (0); > } > > There is no guarantee that NULL can be converted to pthread_t, and > applications are not allowed to "look inside" the typedef and use the > special properties of the underlying type. Good point (I vaguely remember that discussion on the Austin Group list). This test should be removed in FreeBSD / NetBSD. Thanks! -Garrett