From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Pedro Alves <palves@redhat.com>
Cc: GDB Patches <gdb-patches@sourceware.org>, dje@google.com
Subject: Re: [PATCH] PR gdb/16188: Verify PTRACE_TRACEME succeeded
Date: Mon, 20 Feb 2017 12:51:00 -0000 [thread overview]
Message-ID: <87tw7pm3dw.fsf@redhat.com> (raw)
In-Reply-To: <e43135bc-c07b-25dd-cae7-3d146d490d4b@redhat.com> (Pedro Alves's message of "Mon, 20 Feb 2017 12:19:35 +0000")
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/
next prev parent reply other threads:[~2017-02-20 12:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-16 20:19 Sergio Durigan Junior
2017-02-17 10:48 ` Pedro Alves
2017-02-18 4:55 ` Sergio Durigan Junior
2017-02-18 5:09 ` Sergio Durigan Junior
2017-02-20 12:19 ` Pedro Alves
2017-02-20 12:51 ` Sergio Durigan Junior [this message]
2017-02-20 13:05 ` [PATCH] Fix thinko on last commit Sergio Durigan Junior
2017-02-20 13:08 ` Sergio Durigan Junior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tw7pm3dw.fsf@redhat.com \
--to=sergiodj@redhat.com \
--cc=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).