From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 44972 invoked by alias); 20 Feb 2017 12:51:47 -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 44933 invoked by uid 89); 20 Feb 2017 12:51:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=wasting X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Feb 2017 12:51:41 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52E621555E; Mon, 20 Feb 2017 12:51:41 +0000 (UTC) Received: from localhost (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1KCpeD9023782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 20 Feb 2017 07:51:41 -0500 From: Sergio Durigan Junior To: Pedro Alves Cc: GDB Patches , dje@google.com Subject: Re: [PATCH] PR gdb/16188: Verify PTRACE_TRACEME succeeded References: <20170216201931.5843-1-sergiodj@redhat.com> <20170218050900.31399-1-sergiodj@redhat.com> X-URL: http://blog.sergiodj.net Date: Mon, 20 Feb 2017 12:51:00 -0000 In-Reply-To: (Pedro Alves's message of "Mon, 20 Feb 2017 12:19:35 +0000") Message-ID: <87tw7pm3dw.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2017-02/txt/msg00540.txt.bz2 On Monday, February 20 2017, Pedro Alves wrote: > Hi Sergio, > > This LGTM, save for the errno handling in Darwin bits: > > On 02/18/2017 05:09 AM, Sergio Durigan Junior wrote: >> diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c >> index 8c5e8a0..e02e51d 100644 >> --- a/gdb/darwin-nat.c >> +++ b/gdb/darwin-nat.c >> @@ -254,7 +254,6 @@ darwin_ptrace (const char *name, >> { >> int ret; >> >> - errno = 0; >> ret = ptrace (request, pid, arg3, arg4); >> if (ret == -1 && errno == 0) >> ret = 0; > > Removing "errno = 0" here is incorrect. There are ptrace calls where a -1 > return is not an error, thus that check for "errno==0" after the > ptrace call. Since system calls are not required to clear errno on > success, that errno=0 is required. > > This is Darwin, but the Linux man pages, in "man ptrace" say: > > On error, all requests return -1, and errno is set appropriately. Since the > value returned by a successful PTRACE_PEEK* request may be -1, the caller > must clear errno before the call, and then check it afterward to determine whether > or not an error occurred. > > And actually, the comment just above darwin_ptrace talks > about clearning errno. So it's really incorrect. Oh, I'm really sorry, this was actually a mistake on the patch. I meant to delete the 'errno = 0;' on darwin_ptrace_me, not on darwin_ptrace. Of course, I understand that errno must be cleared before the ptrace call and I had read the exact same paragraph on the manpage. Anyway, sorry for wasting your time on this. >> @@ -1728,23 +1727,30 @@ darwin_ptrace_me (void) >> int res; >> char c; >> >> + errno = 0; > > OTOH, I don't see the need to clear it here. Below, > errno will only be used when a syscall fails, and in > failure case, the syscall must set errno. Yeah. I fixed the mistake and pushed the patch. Thanks. 0db8980cc0ee05727c11f8b7c6674137a4d5de4e -- Sergio GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36 Please send encrypted e-mail if possible http://sergiodj.net/