| 77 | |
| 78 | |
| 79 | ThreadStatus::ThreadStatus() |
| 80 | : thread_id{getThreadId()} |
| 81 | { |
| 82 | last_rusage = std::make_unique<RUsageCounters>(); |
| 83 | |
| 84 | memory_tracker.setDescription("(for thread)"); |
| 85 | log = &Poco::Logger::get("ThreadStatus"); |
| 86 | |
| 87 | current_thread = this; |
| 88 | |
| 89 | /// NOTE: It is important not to do any non-trivial actions (like updating ProfileEvents or logging) before ThreadStatus is created |
| 90 | /// Otherwise it could lead to SIGSEGV due to current_thread dereferencing |
| 91 | |
| 92 | /// Will set alternative signal stack to provide diagnostics for stack overflow errors. |
| 93 | /// If not already installed for current thread. |
| 94 | /// Sanitizer makes larger stack usage and also it's incompatible with alternative stack by default (it sets up and relies on its own). |
| 95 | #if !defined(SANITIZER) && !defined(ARCADIA_BUILD) |
| 96 | if (!has_alt_stack) |
| 97 | { |
| 98 | /// Don't repeat tries even if not installed successfully. |
| 99 | has_alt_stack = true; |
| 100 | |
| 101 | /// We have to call 'sigaltstack' before first 'sigaction'. (It does not work other way, for unknown reason). |
| 102 | stack_t altstack_description{}; |
| 103 | altstack_description.ss_sp = alt_stack.getData(); |
| 104 | altstack_description.ss_flags = 0; |
| 105 | altstack_description.ss_size = alt_stack.getSize(); |
| 106 | |
| 107 | if (0 != sigaltstack(&altstack_description, nullptr)) |
| 108 | { |
| 109 | LOG_WARNING(log, "Cannot set alternative signal stack for thread, {}", errnoToString(errno)); |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | /// Obtain existing sigaction and modify it by adding a flag. |
| 114 | struct sigaction action{}; |
| 115 | if (0 != sigaction(SIGSEGV, nullptr, &action)) |
| 116 | { |
| 117 | LOG_WARNING(log, "Cannot obtain previous signal action to set alternative signal stack for thread, {}", errnoToString(errno)); |
| 118 | } |
| 119 | else if (!(action.sa_flags & SA_ONSTACK)) |
| 120 | { |
| 121 | action.sa_flags |= SA_ONSTACK; |
| 122 | |
| 123 | if (0 != sigaction(SIGSEGV, &action, nullptr)) |
| 124 | { |
| 125 | LOG_WARNING(log, "Cannot set action with alternative signal stack for thread, {}", errnoToString(errno)); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | #endif |
| 131 | } |
| 132 | |
| 133 | ThreadStatus::~ThreadStatus() |
| 134 | { |
nothing calls this directly
no test coverage detected