From owner-freebsd-standards@FreeBSD.ORG  Thu Jul 17 21:21:14 2014
Return-Path: <owner-freebsd-standards@FreeBSD.ORG>
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 <multiple recipients>; 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: <bug-191906-15@https.bugs.freebsd.org/bugzilla/>
 <21448.10927.483892.974746@khavrinen.csail.mit.edu>
Date: Thu, 17 Jul 2014 14:21:10 -0700
Message-ID: <CAGHfRMBYZ9m6FL5MBCPtUYUwo6O4hbWzO49MWas1zRpMiWCvtg@mail.gmail.com>
Subject: Re: [Bug 191906] New: pthread_cancel(NULL) on FreeBSD returns EINVAL, 
 not ESRCH according to manpage
From: Garrett Cooper <yaneurabeya@gmail.com>
To: Garrett Wollman <wollman@csail.mit.edu>
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 <freebsd-standards.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/freebsd-standards>, 
 <mailto:freebsd-standards-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-standards/>
List-Post: <mailto:freebsd-standards@freebsd.org>
List-Help: <mailto:freebsd-standards-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-standards>, 
 <mailto:freebsd-standards-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 17 Jul 2014 21:21:14 -0000

On Thu, Jul 17, 2014 at 12:57 PM, Garrett Wollman <wollman@csail.mit.edu> wrote:
> <<On Thu, 17 Jul 2014 03:13:01 +0000, bugzilla-noreply@freebsd.org said:
>
>> 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