This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Consensus on MT-, AS- and AC-Safety docs.


On Nov 19, 2013, "Joseph S. Myers" <joseph@codesourcery.com> wrote:

> * libm functions generally may set the thread-local errno.

> * libm functions, and floating-point arithmetic, may use and modify the 
> floating-point environment.

I've added the following paragraph to the definition of AS-Safe:

  Many functions that are AS-Safe may set @code{errno}, or modify the
  floating-point environment, because their doing so does not make them
  unsuitable for use in signal handlers.  However, programs could
  misbehave should asynchronous signal handlers modify this thread-local
  state, and the signal handling machinery cannot be counted on to
  preserve it.  Therefore, signal handlers that call functions that may
  set @code{errno} or modify the floating-point environment @emph{must}
  save their original values, and restore them before returning.


I wonder if we should have a future-proof API for signal handlers to
call in order to save local state that AS-Safe libc functions may call
and that should be preserved by signal handlers.  Something like:

#define sigsavestate() do { sigsave_t __sigsaved = { errno };
#define sigreststate() errno = __sigsaved.err_no; } while (0)

Maybe with pthread cleanup around it too.  Note that I left the fp env
out of the initializer in this generic fallback definition, for only on
a few platforms does it have to be saved; those would override the
header that defines the sigsave_t type and the macros.

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]