mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: musl@lists.openwall.com, Markus Wichmann <nullplan@gmx.net>
Subject: Re: [musl] Is errno signal-safe?
Date: Wed, 16 Feb 2022 16:02:49 -0500	[thread overview]
Message-ID: <4481efb2-88d5-6b42-215d-6d7d96713274@redhat.com> (raw)
In-Reply-To: <87wnhuy19i.fsf@oldenburg.str.redhat.com>

On 2/16/22 16:01, Florian Weimer wrote:
> * 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. I'd forgotten about that quirk. Every *other* use of non-initial-exec TLS is
still AS-unsafe.

-- 
Cheers,
Carlos.


      reply	other threads:[~2022-02-16 21:03 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
2022-02-16 21:02     ` Carlos O'Donell [this message]

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=4481efb2-88d5-6b42-215d-6d7d96713274@redhat.com \
    --to=carlos@redhat.com \
    --cc=fweimer@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).