diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/poco/Foundation/src/SignalHandler.cpp | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/src/SignalHandler.cpp')
-rw-r--r-- | contrib/libs/poco/Foundation/src/SignalHandler.cpp | 222 |
1 files changed, 111 insertions, 111 deletions
diff --git a/contrib/libs/poco/Foundation/src/SignalHandler.cpp b/contrib/libs/poco/Foundation/src/SignalHandler.cpp index eaa1dc7ec8..4aca858367 100644 --- a/contrib/libs/poco/Foundation/src/SignalHandler.cpp +++ b/contrib/libs/poco/Foundation/src/SignalHandler.cpp @@ -1,111 +1,111 @@ -// -// SignalHandler.cpp -// -// Library: Foundation -// Package: Threading -// Module: SignalHandler -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#include "Poco/SignalHandler.h" - - -#if defined(POCO_OS_FAMILY_UNIX) && !defined(POCO_VXWORKS) - - -#include "Poco/Thread.h" -#include "Poco/NumberFormatter.h" -#include "Poco/Exception.h" -#include <cstdlib> -#include <signal.h> - - -namespace Poco { - - -SignalHandler::JumpBufferVec SignalHandler::_jumpBufferVec; - - -SignalHandler::SignalHandler() -{ - JumpBufferVec& jbv = jumpBufferVec(); - JumpBuffer buf; - jbv.push_back(buf); -} - - -SignalHandler::~SignalHandler() -{ - jumpBufferVec().pop_back(); -} - - -sigjmp_buf& SignalHandler::jumpBuffer() -{ - return jumpBufferVec().back().buf; -} - - -void SignalHandler::throwSignalException(int sig) -{ - switch (sig) - { - case SIGILL: - throw SignalException("Illegal instruction"); - case SIGBUS: - throw SignalException("Bus error"); - case SIGSEGV: - throw SignalException("Segmentation violation"); - case SIGSYS: - throw SignalException("Invalid system call"); - default: - throw SignalException(NumberFormatter::formatHex(sig)); - } -} - - -void SignalHandler::install() -{ -#ifndef POCO_NO_SIGNAL_HANDLER - struct sigaction sa; - sa.sa_handler = handleSignal; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - sigaction(SIGILL, &sa, 0); - sigaction(SIGBUS, &sa, 0); - sigaction(SIGSEGV, &sa, 0); - sigaction(SIGSYS, &sa, 0); -#endif -} - - -void SignalHandler::handleSignal(int sig) -{ - JumpBufferVec& jb = jumpBufferVec(); - if (!jb.empty()) - siglongjmp(jb.back().buf, sig); - - // Abort if no jump buffer registered - std::abort(); -} - - -SignalHandler::JumpBufferVec& SignalHandler::jumpBufferVec() -{ - ThreadImpl* pThread = ThreadImpl::currentImpl(); - if (pThread) - return pThread->_jumpBufferVec; - else - return _jumpBufferVec; -} - - -} // namespace Poco - - -#endif // POCO_OS_FAMILY_UNIX +// +// SignalHandler.cpp +// +// Library: Foundation +// Package: Threading +// Module: SignalHandler +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/SignalHandler.h" + + +#if defined(POCO_OS_FAMILY_UNIX) && !defined(POCO_VXWORKS) + + +#include "Poco/Thread.h" +#include "Poco/NumberFormatter.h" +#include "Poco/Exception.h" +#include <cstdlib> +#include <signal.h> + + +namespace Poco { + + +SignalHandler::JumpBufferVec SignalHandler::_jumpBufferVec; + + +SignalHandler::SignalHandler() +{ + JumpBufferVec& jbv = jumpBufferVec(); + JumpBuffer buf; + jbv.push_back(buf); +} + + +SignalHandler::~SignalHandler() +{ + jumpBufferVec().pop_back(); +} + + +sigjmp_buf& SignalHandler::jumpBuffer() +{ + return jumpBufferVec().back().buf; +} + + +void SignalHandler::throwSignalException(int sig) +{ + switch (sig) + { + case SIGILL: + throw SignalException("Illegal instruction"); + case SIGBUS: + throw SignalException("Bus error"); + case SIGSEGV: + throw SignalException("Segmentation violation"); + case SIGSYS: + throw SignalException("Invalid system call"); + default: + throw SignalException(NumberFormatter::formatHex(sig)); + } +} + + +void SignalHandler::install() +{ +#ifndef POCO_NO_SIGNAL_HANDLER + struct sigaction sa; + sa.sa_handler = handleSignal; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sigaction(SIGILL, &sa, 0); + sigaction(SIGBUS, &sa, 0); + sigaction(SIGSEGV, &sa, 0); + sigaction(SIGSYS, &sa, 0); +#endif +} + + +void SignalHandler::handleSignal(int sig) +{ + JumpBufferVec& jb = jumpBufferVec(); + if (!jb.empty()) + siglongjmp(jb.back().buf, sig); + + // Abort if no jump buffer registered + std::abort(); +} + + +SignalHandler::JumpBufferVec& SignalHandler::jumpBufferVec() +{ + ThreadImpl* pThread = ThreadImpl::currentImpl(); + if (pThread) + return pThread->_jumpBufferVec; + else + return _jumpBufferVec; +} + + +} // namespace Poco + + +#endif // POCO_OS_FAMILY_UNIX |