From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Tadeus Prastowo <0x66726565@gmail.com>
Cc: "libc-help@sourceware.org" <libc-help@sourceware.org>,
Florian Weimer <fweimer@redhat.com>
Subject: Re: raise() marked __leaf__ is not C-compliant?
Date: Wed, 28 Oct 2020 17:17:30 -0300 [thread overview]
Message-ID: <569317ca-b87a-68cc-a776-f524ec76ca3c@linaro.org> (raw)
In-Reply-To: <CAA1YtmsTSZa3nUDywdtwtxFpWrwnAzsJpx4uzNEKZqJmvuy8LA@mail.gmail.com>
On 28/10/2020 16:23, Tadeus Prastowo wrote:
> On Wed, Oct 28, 2020 at 6:34 PM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>
>> On 28/10/2020 10:19, Tadeus Prastowo wrote:
>>> On Wed, Oct 28, 2020 at 12:53 PM Adhemerval Zanella
>>> <adhemerval.zanella@linaro.org> wrote:
>>>>
>>>> The sentence "raise() definitely runs a signal handler" is not really
>>>> valid in a portable sense. Afaik neither C nor POSIX states which signals
>>>> should be delivered synchronously or asynchronously (although some do
>>>> only make sense to be delivered synchronously such as SIGSEGV).
>>>>
>>>> However, Linux does ran some signals synchronously and I agree that using
>>>> leaf attribute is incorrect and lead to this kind of problems. My point is
>>>> to be fully portable, you need to assume any signal might be delivered
>>>> asynchronously (and C standard specifies the volatile sig_atomic_t for
>>>> such cases).
>>>
>>> Thank you for your response.
>>>
>>> However, C, including C99, C11, and the latest C18 [1], says: "If a
>>> signal handler is called, the raise function shall not return until
>>> after the signal handler does." And, POSIX [2] says: "If a signal
>>> handler is called, the raise() function shall not return until after
>>> the signal handler does." So, the sentence "raise() definitely runs a
>>> signal handler" is valid in a portable sense as required by the
>>> standards, no?
>>
>> My understanding is it allows synchronous signals, not enforce it;
>> and if the signal is synchronous then it should complete prior hand.
>
> I understand your point as the C standard says:
>
> [...] distinct values that are the signal numbers, each corresponding
> to the specified condition:
> SIGABRT [...]
> SIGFPE [...]
> SIGILL [...]
> SIGINT [...]
> SIGSEGV [...]
> SIGTERM [...]
> An implementation need not generate any of these signals, except as a
> result of explicit calls to the raise function. [...] The complete
> set of signals, their semantics, and their default handling is
> implementation-defined; all signal numbers shall be positive.
>
> [...]
>
> void (*signal(int sig, void (*func)(int)))(int);
> Description
> [...]
> When a signal occurs and func points to a function, it is
> implementation-defined whether the equivalent of signal(sig, SIG_DFL);
> is executed [...]; in the case of SIGILL, the implementation may
> alternatively define that no action is taken. Then the equivalent of
> (*func)(sig); is executed.
>
> End quote.
>
> So, yes, you are right that the sentence "raise() definitely runs a
> signal handler" is inaccurate because, as quoted above, C standard
> allows an implementation to not run the handler that the user has
> designated to handle the signal being generated by raise(). However,
> if the implementation decides that "the equivalent of (*func)(sig); is
> executed", then the C standard requires that "the raise function shall
> not return until after the signal handler does."
I agree this does make sense for *synchronous* signal triggering. My
point ir neither C not POSIX specify which signal should be synchronous.
In fact, afaik neither standard does make a clearly distinction nor
specific the expected semantic for signal "synchronicity" (it is really
implementation defined).
>
> To conclude, in my earlier post, I meant to say: Glibc-2.30 raise()
> may run a signal handler that is defined in the current compilation
> unit to use static variables. So, unless the C standard says that it
> is an undefined behavior to access a non-volatile object with static
> storage duration from within a signal handler that is called
> synchronously by raise() on a normal execution path, the marking of
> raise() with __leaf__ makes raise() non-compliant with the C standard.
I am not a language lawyer here, and I agree with you that adding leaf
attribute on 'raise' is wrong. But because glibc can't guarantee how
the underlying kernel will trigger the signal in a raise syscall.
I still think that once you can't assume the signal will be triggered
synchronously, you can't also assume that accessing non-volatile object
with static storage duration from within a signal handler might not
trigger undefined behavior.
next prev parent reply other threads:[~2020-10-28 20:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-27 16:57 Tadeus Prastowo
2020-10-27 18:50 ` Adhemerval Zanella
2020-10-28 5:47 ` Tadeus Prastowo
2020-10-28 6:13 ` Tadeus Prastowo
2020-10-28 7:33 ` Tadeus Prastowo
2020-10-28 11:53 ` Adhemerval Zanella
2020-10-28 13:19 ` Tadeus Prastowo
2020-10-28 17:34 ` Adhemerval Zanella
2020-10-28 19:23 ` Tadeus Prastowo
2020-10-28 20:17 ` Adhemerval Zanella [this message]
2020-10-29 7:50 ` Tadeus Prastowo
2020-10-28 8:21 ` Florian Weimer
2020-10-28 12:58 ` Tadeus Prastowo
2020-10-28 17:16 ` Tadeus Prastowo
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=569317ca-b87a-68cc-a776-f524ec76ca3c@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=0x66726565@gmail.com \
--cc=fweimer@redhat.com \
--cc=libc-help@sourceware.org \
/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).