|
Message-ID: <87wnhuy19i.fsf@oldenburg.str.redhat.com> Date: Wed, 16 Feb 2022 22:01:13 +0100 From: Florian Weimer <fweimer@...hat.com> To: Carlos O'Donell <carlos@...hat.com> Cc: musl@...ts.openwall.com, Markus Wichmann <nullplan@....net> Subject: Re: Is errno signal-safe? * 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@...BC_PRIVATE or via __errno_location, it doesn't matter). Thanks, Florian
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.