My questions:
- Is there a way to finally determine if a function is safe using an async signal if you do not have access to its implementation?
- If not, is there a way to check if the function is safe enough for an asynchronous signal to be called from a signal handler?
If you read the man-pages of the signal () or sigaction (), you get a list of safe functions for asynchronous functions (functions that can be safely called inside the signal handler). However, I believe that this list is not exhaustive. For example, the following page http://linux.die.net/man/7/signal in the Async-safe-safe header :
POSIX.1-2004 (also known as POSIX.1-2001 Technical Corrigendum 2) requires an implementation to ensure that the following functions can be safely called inside the signal handler:
And then it will list the normal safe asynchronous functions listed on the manual pages above. When I read this, he says "it requires" and not "these are the only ones."
For example, this site says back_trace_symbols_fd () is a safe asynchronous signal. This function receives data from dladdr (), and it does not use malloc (), like back_trace_symbols (), so it looks like it can be safe. In addition, I did some testing, and the output structure of dladdr () contains char * variables, but they are NOT malloc'ed at runtime. The char string that they point to exists at runtime even before dladdr () is called.
Any thoughts or ideas that may point me in the right direction are appreciated.
source
share