mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-28 05:08:14 +00:00
When a crashing process is in a different PID namespace than the handler, the crasher doesn't have a way of knowing its own thread ID in the handler's namespace and the kernel lacks mechanisms to perform this translation before Linux 4.1 (where the information is present in /proc/<pid>/status:NSPid). This patch gives the handler a way of identifying the requesting thread by sending a stack address along with the crash dump request, which the handler can search for in each of the process' threads. This information is useful both for attaching exception information to the right thread and to allow the handler to send signals to the correct thread when using a shared socket connection. Bug: crashpad:284, crashpad:286 Change-Id: I4fa366c8fb17f932b056265cf71a4af160ba342f Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1558828 Commit-Queue: Joshua Peraza <jperaza@chromium.org> Reviewed-by: Mark Mentovai <mark@chromium.org>
96 lines
4.3 KiB
C++
96 lines
4.3 KiB
C++
// Copyright 2018 The Crashpad Authors. All rights reserved.
|
||
//
|
||
// 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.
|
||
|
||
#ifndef CRASHPAD_HANDLER_LINUX_CRASH_REPORT_EXCEPTION_HANDLER_H_
|
||
#define CRASHPAD_HANDLER_LINUX_CRASH_REPORT_EXCEPTION_HANDLER_H_
|
||
|
||
#include <map>
|
||
#include <string>
|
||
|
||
#include "base/macros.h"
|
||
#include "client/crash_report_database.h"
|
||
#include "handler/crash_report_upload_thread.h"
|
||
#include "handler/linux/exception_handler_server.h"
|
||
#include "handler/user_stream_data_source.h"
|
||
#include "util/linux/exception_handler_protocol.h"
|
||
#include "util/linux/ptrace_connection.h"
|
||
#include "util/misc/address_types.h"
|
||
#include "util/misc/uuid.h"
|
||
|
||
namespace crashpad {
|
||
|
||
//! \brief An exception handler that writes crash reports for exceptions
|
||
//! to a CrashReportDatabase.
|
||
class CrashReportExceptionHandler : public ExceptionHandlerServer::Delegate {
|
||
public:
|
||
//! \brief Creates a new object that will store crash reports in \a database.
|
||
//!
|
||
//! \param[in] database The database to store crash reports in. Weak.
|
||
//! \param[in] upload_thread The upload thread to notify when a new crash
|
||
//! report is written into \a database. Report upload is skipped if this
|
||
//! value is `nullptr`.
|
||
//! \param[in] process_annotations A map of annotations to insert as
|
||
//! process-level annotations into each crash report that is written. Do
|
||
//! not confuse this with module-level annotations, which are under the
|
||
//! control of the crashing process, and are used to implement Chrome’s
|
||
//! “crash keys.” Process-level annotations are those that are beyond the
|
||
//! control of the crashing process, which must reliably be set even if
|
||
//! the process crashes before it’s able to establish its own annotations.
|
||
//! To interoperate with Breakpad servers, the recommended practice is to
|
||
//! specify values for the `"prod"` and `"ver"` keys as process
|
||
//! annotations.
|
||
//! \param[in] user_stream_data_sources Data sources to be used to extend
|
||
//! crash reports. For each crash report that is written, the data sources
|
||
//! are called in turn. These data sources may contribute additional
|
||
//! minidump streams. `nullptr` if not required.
|
||
CrashReportExceptionHandler(
|
||
CrashReportDatabase* database,
|
||
CrashReportUploadThread* upload_thread,
|
||
const std::map<std::string, std::string>* process_annotations,
|
||
const UserStreamDataSources* user_stream_data_sources);
|
||
|
||
~CrashReportExceptionHandler();
|
||
|
||
// ExceptionHandlerServer::Delegate:
|
||
|
||
bool HandleException(pid_t client_process_id,
|
||
const ClientInformation& info,
|
||
VMAddress requesting_thread_stack_address = 0,
|
||
pid_t* requesting_thread_id = nullptr,
|
||
UUID* local_report_id = nullptr) override;
|
||
|
||
bool HandleExceptionWithBroker(pid_t client_process_id,
|
||
const ClientInformation& info,
|
||
int broker_sock,
|
||
UUID* local_report_id = nullptr) override;
|
||
|
||
private:
|
||
bool HandleExceptionWithConnection(PtraceConnection* connection,
|
||
const ClientInformation& info,
|
||
VMAddress requesting_thread_stack_address,
|
||
pid_t* requesting_thread_id,
|
||
UUID* local_report_id = nullptr);
|
||
|
||
CrashReportDatabase* database_; // weak
|
||
CrashReportUploadThread* upload_thread_; // weak
|
||
const std::map<std::string, std::string>* process_annotations_; // weak
|
||
const UserStreamDataSources* user_stream_data_sources_; // weak
|
||
|
||
DISALLOW_COPY_AND_ASSIGN(CrashReportExceptionHandler);
|
||
};
|
||
|
||
} // namespace crashpad
|
||
|
||
#endif // CRASHPAD_HANDLER_LINUX_CRASH_REPORT_EXCEPTION_HANDLER_H_
|