yangzhg commented on a change in pull request #8545:
URL: https://github.com/apache/incubator-doris/pull/8545#discussion_r830722869
##########
File path: be/src/common/signal_handler.h
##########
@@ -0,0 +1,449 @@
+// Copyright (c) 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Author: Satoru Takabayashi
+//
+// Implementation of InstallFailureSignalHandler().
+
+#define BOOST_STACKTRACE_USE_BACKTRACE
+#include <boost/stacktrace.hpp>
+#include <glog/logging.h>
+#include <gutil/macros.h>
+
+#include <csignal>
+#include <ctime>
+#include <iostream>
+#include <pthread.h>
+#ifdef HAVE_UCONTEXT_H
+# include <ucontext.h>
+#endif
+#include <unistd.h>
+#ifdef HAVE_SYS_UCONTEXT_H
+# include <sys/ucontext.h>
+#endif
+#include <algorithm>
+
+namespace doris::signal {
+
+namespace {
+
+// We'll install the failure signal handler for these signals. We could
+// use strsignal() to get signal names, but we don't use it to avoid
+// introducing yet another #ifdef complication.
+//
+// The list should be synced with the comment in signalhandler.h.
+const struct {
+ int number;
+ const char *name;
+} kFailureSignals[] = {
+ { SIGSEGV, "SIGSEGV" },
+ { SIGILL, "SIGILL" },
+ { SIGFPE, "SIGFPE" },
+ { SIGABRT, "SIGABRT" },
+ { SIGBUS, "SIGBUS" },
+ { SIGTERM, "SIGTERM" },
+};
+
+static bool kFailureSignalHandlerInstalled = false;
+
+/*
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * These signal explainer is copied from Meta's Folly
+ */
+const char* sigill_reason(int si_code) {
+ switch (si_code) {
+ case ILL_ILLOPC:
+ return "illegal opcode";
+ case ILL_ILLOPN:
+ return "illegal operand";
+ case ILL_ILLADR:
+ return "illegal addressing mode";
+ case ILL_ILLTRP:
+ return "illegal trap";
+ case ILL_PRVOPC:
+ return "privileged opcode";
+ case ILL_PRVREG:
+ return "privileged register";
+ case ILL_COPROC:
+ return "coprocessor error";
+ case ILL_BADSTK:
+ return "internal stack error";
+
+ default:
+ return nullptr;
+ }
+}
+
+const char* sigfpe_reason(int si_code) {
+ switch (si_code) {
+ case FPE_INTDIV:
+ return "integer divide by zero";
+ case FPE_INTOVF:
+ return "integer overflow";
+ case FPE_FLTDIV:
+ return "floating-point divide by zero";
+ case FPE_FLTOVF:
+ return "floating-point overflow";
+ case FPE_FLTUND:
+ return "floating-point underflow";
+ case FPE_FLTRES:
+ return "floating-point inexact result";
+ case FPE_FLTINV:
+ return "floating-point invalid operation";
+ case FPE_FLTSUB:
+ return "subscript out of range";
+
+ default:
+ return nullptr;
+ }
+}
+
+const char* sigsegv_reason(int si_code) {
+ switch (si_code) {
+ case SEGV_MAPERR:
+ return "address not mapped to object";
+ case SEGV_ACCERR:
+ return "invalid permissions for mapped object";
+
+ default:
+ return nullptr;
+ }
+}
+
+const char* sigbus_reason(int si_code) {
+ switch (si_code) {
+ case BUS_ADRALN:
+ return "invalid address alignment";
+ case BUS_ADRERR:
+ return "nonexistent physical address";
+ case BUS_OBJERR:
+ return "object-specific hardware error";
+
+ // MCEERR_AR and MCEERR_AO: in sigaction(2) but not in headers.
+
+ default:
+ return nullptr;
+ }
+}
+
+const char* signal_reason(int signum, int si_code) {
+ switch (signum) {
+ case SIGILL:
+ return sigill_reason(si_code);
+ case SIGFPE:
+ return sigfpe_reason(si_code);
+ case SIGSEGV:
+ return sigsegv_reason(si_code);
+ case SIGBUS:
+ return sigbus_reason(si_code);
+ default:
+ return nullptr;
+ }
+}
+
+// The class is used for formatting error messages. We don't use printf()
+// as it's not async signal safe.
+class MinimalFormatter {
+ public:
+ MinimalFormatter(char *buffer, size_t size)
+ : buffer_(buffer),
+ cursor_(buffer),
+ end_(buffer + size) {
+ }
+
+ // Returns the number of bytes written in the buffer.
+ std::size_t num_bytes_written() const { return
static_cast<std::size_t>(cursor_ - buffer_); }
+
+ // Appends string from "str" and updates the internal cursor.
+ void AppendString(const char* str) {
Review comment:
Why use Camel Case here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]