From: Florian Weimer <fweimer@redhat.com>
To: Carlos O'Donell <carlos@redhat.com>
Cc: musl@lists.openwall.com, Markus Wichmann <nullplan@gmx.net>
Subject: Re: [musl] Is errno signal-safe?
Date: Wed, 16 Feb 2022 22:01:13 +0100 [thread overview]
Message-ID: <87wnhuy19i.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <75d1d0f9-950b-6bb1-0ed5-f1d28df0cef8@redhat.com> (Carlos O'Donell's message of "Wed, 16 Feb 2022 14:56:12 -0500")
* Carlos O'Donell:
> On 2/16/22 14:40, Markus Wichmann wrote:
>> Hi all,
>>
>> today I had a flash of inspiration while staring at some code: errno is
>> a global variable, right? OK, it is thread-local, but still a global
>> variable in the context of one thread. And looking at a global variable
>> while it may (or may not) be modified in a signal handler is not safe to
>> do.
>
> It is required that errno, if changed, must be restored by the signal
> handler before exit (though note that for glibc the underlying lazy
> TLS allocation implementation makes errno AS-unsafe for first use in a
> signal handler because calloc is used to allocate the storage).
glibc uses initial-exec TLS under the hood for storing the int variable,
so the variable access itself async-signal-safe (whether it goes
directly to errno@GLIBC_PRIVATE or via __errno_location, it doesn't
matter).
Thanks,
Florian
next prev parent reply other threads:[~2022-02-16 21:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-16 19:40 Markus Wichmann
2022-02-16 19:56 ` Carlos O'Donell
2022-02-16 21:01 ` Florian Weimer [this message]
2022-02-16 21:02 ` Carlos O'Donell
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=87wnhuy19i.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=carlos@redhat.com \
--cc=musl@lists.openwall.com \
--cc=nullplan@gmx.net \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).