// TODO: __USE_DYNAMIC_STACK_SIZE is dependent on the features.h include and not a built-in compiler define, so it might be problematic to depend on it
#ifdef __USE_DYNAMIC_STACK_SIZE
staticconstexprsize_tMYSTACKSIZE = (16*1024)+32768; // wild guess about a reasonable buffer
#else
staticconstexprsize_tMYSTACKSIZE = (16*1024)+SIGSTKSZ; // wild guess about a reasonable buffer
#endif
staticchar mytstack[MYSTACKSIZE]= {0}; // alternative stack for signal handler
staticbool bStackBelowHeap=false; // lame attempt to locate heap vs. stack address space. See CppCheckExecutor::check_wrapper()
staticFILE* signalOutput = stdout; // TODO: get rid of this
/**
* \param[in] ptr address to be examined.
* \return true if address is supposed to be on stack (contrary to heap). If ptr is 0 false will be returned.
* If unknown better return false.
*/
staticboolIsAddressOnStack(constvoid* ptr)
{
if (nullptr==ptr)
returnfalse;
char a;
if (bStackBelowHeap)
return ptr < &a;
return ptr > &a;
}
/* (declare this list here, so it may be used in signal handlers in addition to main())
* A list of signals available in ISO C
* Check out http://pubs.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html
* For now we only want to detect abnormal behaviour for a few selected signals:
*/
#defineDECLARE_SIGNAL(x) std::make_pair(x, #x)
using Signalmap_t = std::map<int, std::string>;
staticconst Signalmap_t listofsignals = {
DECLARE_SIGNAL(SIGABRT),
DECLARE_SIGNAL(SIGBUS),
DECLARE_SIGNAL(SIGFPE),
DECLARE_SIGNAL(SIGILL),
DECLARE_SIGNAL(SIGINT),
DECLARE_SIGNAL(SIGQUIT),
DECLARE_SIGNAL(SIGSEGV),
DECLARE_SIGNAL(SIGSYS),
// don't care: SIGTERM
DECLARE_SIGNAL(SIGUSR1),
//DECLARE_SIGNAL(SIGUSR2) no usage currently
};
#undef DECLARE_SIGNAL
/*
* Entry pointer for signal handlers
* It uses functions which are not safe to be called from a signal handler,
* (http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04 has a whitelist)
* but when ending up here something went terribly wrong anyway.
* And all which is left is just printing some information and terminate.