From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 114291 invoked by alias); 20 Feb 2017 12:19:41 -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 114280 invoked by uid 89); 20 Feb 2017 12:19:40 -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= 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:19:39 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 7BA0C8046E; Mon, 20 Feb 2017 12:19:39 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1KCJalR032356; Mon, 20 Feb 2017 07:19:37 -0500 Subject: Re: [PATCH] PR gdb/16188: Verify PTRACE_TRACEME succeeded To: Sergio Durigan Junior , GDB Patches References: <20170216201931.5843-1-sergiodj@redhat.com> <20170218050900.31399-1-sergiodj@redhat.com> Cc: dje@google.com From: Pedro Alves Message-ID: Date: Mon, 20 Feb 2017 12:19:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170218050900.31399-1-sergiodj@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-02/txt/msg00539.txt.bz2 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. > @@ -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. > /* Close write end point. */ > - close (ptrace_fds[1]); > + if (close (ptrace_fds[1]) < 0) > + trace_start_error_with_name ("close"); > > /* Wait until gdb is ready. */ > res = read (ptrace_fds[0], &c, 1); > if (res != 0) > - error (_("unable to read from pipe, read returned: %d"), res); > - close (ptrace_fds[0]); > + trace_start_error (_("unable to read from pipe, read returned: %d"), res); > + > + if (close (ptrace_fds[0]) < 0) > + trace_start_error_with_name ("close"); > > /* Get rid of privileges. */ > - setegid (getgid ()); > + if (setegid (getgid ()) < 0) > + trace_start_error_with_name ("setegid"); > > /* Set TRACEME. */ > - PTRACE (PT_TRACE_ME, 0, 0, 0); > + if (PTRACE (PT_TRACE_ME, 0, 0, 0) < 0) > + trace_start_error_with_name ("PTRACE"); > > /* Redirect signals to exception port. */ > - PTRACE (PT_SIGEXC, 0, 0, 0); > + if (PTRACE (PT_SIGEXC, 0, 0, 0) < 0) > + trace_start_error_with_name ("PTRACE"); > } Thanks, Pedro Alves