[Cfp-interest 2907] Re: Signal handlers and the floating point environment

Vincent Lefevre vincent at vinc17.net
Thu Oct 5 06:16:36 PDT 2023


On 2023-10-04 23:00:02 +0000, Rajan Bhakta wrote:
> Regarding C26B, issue 14, I believe the following may capture at least part of the issues raised.
> 
> What is the state of the floating-point environment upon a signal handler invocation? What about after the handler returns?
> The floating point environment is not an object, but has thread storage duration. Signal handlers (outside abort and raise) accessing any object with static or thread storage duration results in undefined behaviour.
> If an operation such as DBL_MAX + DBL_MAX occurs in the signal handler, what happens? Since no object is accessed, UB does not necessarily occur. But what happens?
> What happens if a signal occurs during an operation that would modify the floating point environment?

N3149 says:

    5.1.2.3 Program execution

    [...]

  5 When the processing of the abstract machine is interrupted by
    receipt of a signal, the values of objects that are neither
    lock-free atomic objects nor of type volatile sig_atomic_t
    are unspecified, as is the state of the dynamic floating-point
                                            ^^^^^^^^^^^^^^^^^^^^^^
    environment. The representation of any object modified by the
    ^^^^^^^^^^^
    handler that is neither a lock-free atomic object nor of type
    volatile sig_atomic_t becomes indeterminate when the handler
    exits, as does the state of the dynamic floating-point environment
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    if it is modified by the handler and not restored to its original
    state.

So a signal handler may modify the floating-point environment, but
in such a case, it needs to restore it to its original state.

Moreover, since its state is unspecified in the signal handler,
I suppose that a signal handler that uses floating point may need
to set its environment to a supported state, even if the program
has never changed the default.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the Cfp-interest mailing list