Skip to content

Commit

Permalink
Allowing to disable signal handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Nov 1, 2023
1 parent 89f342b commit 4df7a91
Show file tree
Hide file tree
Showing 6 changed files with 1,662 additions and 1,676 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#endif

#include <hpx/assert.hpp>
#include <hpx/coroutines/signal_handler_debugging.hpp>
#include <hpx/type_support/unused.hpp>
#include <hpx/util/get_and_reset_value.hpp>

Expand Down Expand Up @@ -267,23 +268,26 @@ namespace hpx::threads::coroutines {
// https://rethinkdb.com/blog/handling-stack-overflow-on-custom-stacks/
// http://www.evanjones.ca/software/threading.html
//
segv_stack.ss_sp = valloc(SEGV_STACK_SIZE);
segv_stack.ss_flags = 0;
segv_stack.ss_size = SEGV_STACK_SIZE;

std::memset(&action, '\0', sizeof(action));
action.sa_flags = SA_SIGINFO | SA_ONSTACK;
action.sa_sigaction = &ucontext_context_impl::sigsegv_handler;

sigaltstack(&segv_stack, nullptr);
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGSEGV);
sigaction(SIGSEGV, &action, nullptr);
if (register_signal_handler)
{
segv_stack.ss_sp = valloc(SEGV_STACK_SIZE);
segv_stack.ss_flags = 0;
segv_stack.ss_size = SEGV_STACK_SIZE;

std::memset(&action, '\0', sizeof(action));
action.sa_flags = SA_SIGINFO | SA_ONSTACK;
action.sa_sigaction =
&ucontext_context_impl::sigsegv_handler;

sigaltstack(&segv_stack, nullptr);
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGSEGV);
sigaction(SIGSEGV, &action, nullptr);
}
#endif
}

#if defined(HPX_HAVE_STACKOVERFLOW_DETECTION)

static void sigsegv_handler(
int signum, siginfo_t* infoptr, void* ctxptr)
{
Expand Down Expand Up @@ -313,9 +317,11 @@ namespace hpx::threads::coroutines {
std::cerr
<< "Configure the hpx runtime to allocate a larger "
"coroutine stack size.\n Use the "
"hpx.stacks.small_size, hpx.stacks.medium_size,\n "
"hpx.stacks.small_size, "
"hpx.stacks.medium_size,\n "
"hpx.stacks.large_size, or hpx.stacks.huge_size "
"configuration\nflags to configure coroutine stack "
"configuration\nflags to configure coroutine "
"stack "
"sizes.\n"
<< std::endl;

Expand Down
2 changes: 1 addition & 1 deletion libs/core/coroutines/src/signal_handler_debugging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ namespace hpx::threads::coroutines {
std::size_t trace_depth = 0;
#endif
#if !defined(HPX_WINDOWS)
bool register_signal_handler = 1;
bool register_signal_handler = true;
#endif
} // namespace hpx::threads::coroutines
9 changes: 5 additions & 4 deletions libs/core/init_runtime_local/src/init_runtime_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ namespace hpx {
}

////////////////////////////////////////////////////////////////////////
void init_environment()
void init_environment(
[[maybe_unused]] hpx::util::runtime_configuration const& cfg)
{
HPX_UNUSED(hpx::filesystem::initial_path());

Expand Down Expand Up @@ -397,7 +398,7 @@ namespace hpx {
&hpx::detail::register_locks_predicate);
#endif
#if !defined(HPX_HAVE_DISABLED_SIGNAL_EXCEPTION_HANDLERS)
set_error_handlers();
set_error_handlers(cfg);
#endif
hpx::threads::detail::set_get_default_pool(
&hpx::detail::get_default_pool);
Expand Down Expand Up @@ -446,8 +447,6 @@ namespace hpx {
hpx::program_options::variables_map& vm)> const& f,
int argc, char** argv, init_params const& params, bool blocking)
{
init_environment();

int result = 0;
try
{
Expand All @@ -468,6 +467,8 @@ namespace hpx {
{
result = cmdline.call(params.desc_cmdline, argc, argv);

init_environment(cmdline.rtcfg_);

hpx::threads::policies::detail::affinity_data
affinity_data{};
affinity_data.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ namespace hpx {
hpx::program_options::options_description app_options_;
};

HPX_CORE_EXPORT void set_error_handlers();
HPX_CORE_EXPORT void set_error_handlers(
hpx::util::runtime_configuration const& cfg);

namespace util {
///////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 4df7a91

Please sign in to comment.