From c96226c6baa853f43981b0240974e33a0b661f8d Mon Sep 17 00:00:00 2001 From: Joshua Peraza Date: Tue, 23 Apr 2019 09:59:29 -0700 Subject: [PATCH] linux: move handler protocol types into a class This patch adds the class ExceptionHandlerProtocol to contain all the relevant types, but should not make any functional changes. Change-Id: I65ada239a6bf3195899fdd96f005c042cdd59749 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1575796 Commit-Queue: Joshua Peraza Reviewed-by: Mark Mentovai --- client/crashpad_client_linux_test.cc | 2 +- handler/handler_main.cc | 2 +- .../linux/crash_report_exception_handler.cc | 6 +- .../linux/crash_report_exception_handler.h | 22 ++-- handler/linux/exception_handler_server.cc | 44 ++++--- handler/linux/exception_handler_server.h | 29 +++-- .../linux/exception_handler_server_test.cc | 22 ++-- util/linux/exception_handler_client.cc | 29 +++-- util/linux/exception_handler_client.h | 7 +- util/linux/exception_handler_protocol.cc | 4 +- util/linux/exception_handler_protocol.h | 119 ++++++++++-------- util/linux/ptrace_broker.cc | 25 ++-- util/linux/ptrace_broker.h | 4 +- util/linux/ptrace_client.cc | 12 +- 14 files changed, 181 insertions(+), 146 deletions(-) diff --git a/client/crashpad_client_linux_test.cc b/client/crashpad_client_linux_test.cc index f61ea44f..68a49e7c 100644 --- a/client/crashpad_client_linux_test.cc +++ b/client/crashpad_client_linux_test.cc @@ -342,7 +342,7 @@ class StartHandlerForClientTest { context); exception_information.thread_id = syscall(SYS_gettid); - ClientInformation info; + ExceptionHandlerProtocol::ClientInformation info; info.exception_information_address = FromPointerCast( &exception_information); diff --git a/handler/handler_main.cc b/handler/handler_main.cc index 31686b3e..e87d17b7 100644 --- a/handler/handler_main.cc +++ b/handler/handler_main.cc @@ -880,7 +880,7 @@ int HandlerMain(int argc, #if defined(OS_LINUX) || defined(OS_ANDROID) if (options.exception_information_address) { - ClientInformation info; + ExceptionHandlerProtocol::ClientInformation info; info.exception_information_address = options.exception_information_address; info.sanitization_information_address = options.sanitization_information_address; diff --git a/handler/linux/crash_report_exception_handler.cc b/handler/linux/crash_report_exception_handler.cc index 5401bafa..345e234d 100644 --- a/handler/linux/crash_report_exception_handler.cc +++ b/handler/linux/crash_report_exception_handler.cc @@ -45,7 +45,7 @@ CrashReportExceptionHandler::~CrashReportExceptionHandler() = default; bool CrashReportExceptionHandler::HandleException( pid_t client_process_id, - const ClientInformation& info, + const ExceptionHandlerProtocol::ClientInformation& info, VMAddress requesting_thread_stack_address, pid_t* requesting_thread_id, UUID* local_report_id) { @@ -67,7 +67,7 @@ bool CrashReportExceptionHandler::HandleException( bool CrashReportExceptionHandler::HandleExceptionWithBroker( pid_t client_process_id, - const ClientInformation& info, + const ExceptionHandlerProtocol::ClientInformation& info, int broker_sock, UUID* local_report_id) { Metrics::ExceptionEncountered(); @@ -85,7 +85,7 @@ bool CrashReportExceptionHandler::HandleExceptionWithBroker( bool CrashReportExceptionHandler::HandleExceptionWithConnection( PtraceConnection* connection, - const ClientInformation& info, + const ExceptionHandlerProtocol::ClientInformation& info, VMAddress requesting_thread_stack_address, pid_t* requesting_thread_id, UUID* local_report_id) { diff --git a/handler/linux/crash_report_exception_handler.h b/handler/linux/crash_report_exception_handler.h index 18051656..dba8b63a 100644 --- a/handler/linux/crash_report_exception_handler.h +++ b/handler/linux/crash_report_exception_handler.h @@ -65,22 +65,24 @@ class CrashReportExceptionHandler : public ExceptionHandlerServer::Delegate { // ExceptionHandlerServer::Delegate: bool HandleException(pid_t client_process_id, - const ClientInformation& info, + const ExceptionHandlerProtocol::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; + bool HandleExceptionWithBroker( + pid_t client_process_id, + const ExceptionHandlerProtocol::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); + bool HandleExceptionWithConnection( + PtraceConnection* connection, + const ExceptionHandlerProtocol::ClientInformation& info, + VMAddress requesting_thread_stack_address, + pid_t* requesting_thread_id, + UUID* local_report_id = nullptr); CrashReportDatabase* database_; // weak CrashReportUploadThread* upload_thread_; // weak diff --git a/handler/linux/exception_handler_server.cc b/handler/linux/exception_handler_server.cc index c2842120..4cefd8b4 100644 --- a/handler/linux/exception_handler_server.cc +++ b/handler/linux/exception_handler_server.cc @@ -110,10 +110,13 @@ bool HaveCapSysPtrace() { return (cap_data.effective & (1 << CAP_SYS_PTRACE)) != 0; } -bool SendMessageToClient(int client_sock, ServerToClientMessage::Type type) { - ServerToClientMessage message = {}; +bool SendMessageToClient( + int client_sock, + ExceptionHandlerProtocol::ServerToClientMessage::Type type) { + ExceptionHandlerProtocol::ServerToClientMessage message = {}; message.type = type; - if (type == ServerToClientMessage::kTypeSetPtracer) { + if (type == + ExceptionHandlerProtocol::ServerToClientMessage::kTypeSetPtracer) { message.pid = getpid(); } return LoggingWriteFile(client_sock, &message, sizeof(message)); @@ -134,11 +137,12 @@ class PtraceStrategyDeciderImpl : public PtraceStrategyDecider { case PtraceScope::kRestricted: if (!SendMessageToClient(sock, - ServerToClientMessage::kTypeSetPtracer)) { + ExceptionHandlerProtocol:: + ServerToClientMessage::kTypeSetPtracer)) { return Strategy::kError; } - Errno status; + ExceptionHandlerProtocol::Errno status; if (!LoggingReadFileExactly(sock, &status, sizeof(status))) { return Strategy::kError; } @@ -170,12 +174,13 @@ class PtraceStrategyDeciderImpl : public PtraceStrategyDecider { private: static Strategy TryForkingBroker(int client_sock) { - if (!SendMessageToClient(client_sock, - ServerToClientMessage::kTypeForkBroker)) { + if (!SendMessageToClient( + client_sock, + ExceptionHandlerProtocol::ServerToClientMessage::kTypeForkBroker)) { return Strategy::kError; } - Errno status; + ExceptionHandlerProtocol::Errno status; if (!LoggingReadFileExactly(client_sock, &status, sizeof(status))) { return Strategy::kError; } @@ -369,7 +374,7 @@ bool ExceptionHandlerServer::UninstallClientSocket(Event* event) { } bool ExceptionHandlerServer::ReceiveClientMessage(Event* event) { - ClientToServerMessage message; + ExceptionHandlerProtocol::ClientToServerMessage message; iovec iov; iov.iov_base = &message; iov.iov_len = sizeof(message); @@ -405,15 +410,17 @@ bool ExceptionHandlerServer::ReceiveClientMessage(Event* event) { return false; } - if (msg.msg_iov[0].iov_len != sizeof(ClientToServerMessage)) { + if (msg.msg_iov[0].iov_len != + sizeof(ExceptionHandlerProtocol::ClientToServerMessage)) { LOG(ERROR) << "unexpected message size " << msg.msg_iov[0].iov_len; return false; } auto client_msg = - reinterpret_cast(msg.msg_iov[0].iov_base); + reinterpret_cast( + msg.msg_iov[0].iov_base); switch (client_msg->type) { - case ClientToServerMessage::kCrashDumpRequest: + case ExceptionHandlerProtocol::ClientToServerMessage::kCrashDumpRequest: return HandleCrashDumpRequest(msg, client_msg->client_info, client_msg->requesting_thread_stack_address, @@ -427,7 +434,7 @@ bool ExceptionHandlerServer::ReceiveClientMessage(Event* event) { bool ExceptionHandlerServer::HandleCrashDumpRequest( const msghdr& msg, - const ClientInformation& client_info, + const ExceptionHandlerProtocol::ClientInformation& client_info, VMAddress requesting_thread_stack_address, int client_sock) { cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); @@ -459,8 +466,10 @@ bool ExceptionHandlerServer::HandleCrashDumpRequest( return false; case PtraceStrategyDecider::Strategy::kNoPtrace: - return SendMessageToClient(client_sock, - ServerToClientMessage::kTypeCrashDumpFailed); + return SendMessageToClient( + client_sock, + ExceptionHandlerProtocol::ServerToClientMessage:: + kTypeCrashDumpFailed); case PtraceStrategyDecider::Strategy::kDirectPtrace: delegate_->HandleException( @@ -473,8 +482,9 @@ bool ExceptionHandlerServer::HandleCrashDumpRequest( break; } - return SendMessageToClient(client_sock, - ServerToClientMessage::kTypeCrashDumpComplete); + return SendMessageToClient( + client_sock, + ExceptionHandlerProtocol::ServerToClientMessage::kTypeCrashDumpComplete); } } // namespace crashpad diff --git a/handler/linux/exception_handler_server.h b/handler/linux/exception_handler_server.h index 6f13fdc7..1b73601c 100644 --- a/handler/linux/exception_handler_server.h +++ b/handler/linux/exception_handler_server.h @@ -82,11 +82,12 @@ class ExceptionHandlerServer { //! \param[out] local_report_id The unique identifier for the report created //! in the local report database. Optional. //! \return `true` on success. `false` on failure with a message logged. - virtual 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) = 0; + virtual bool HandleException( + pid_t client_process_id, + const ExceptionHandlerProtocol::ClientInformation& info, + VMAddress requesting_thread_stack_address = 0, + pid_t* requesting_thread_id = nullptr, + UUID* local_report_id = nullptr) = 0; //! \brief Called on the receipt of a crash dump request from a client for a //! crash that should be mediated by a PtraceBroker. @@ -97,10 +98,11 @@ class ExceptionHandlerServer { //! \param[out] local_report_id The unique identifier for the report created //! in the local report database. Optional. //! \return `true` on success. `false` on failure with a message logged. - virtual bool HandleExceptionWithBroker(pid_t client_process_id, - const ClientInformation& info, - int broker_sock, - UUID* local_report_id = nullptr) = 0; + virtual bool HandleExceptionWithBroker( + pid_t client_process_id, + const ExceptionHandlerProtocol::ClientInformation& info, + int broker_sock, + UUID* local_report_id = nullptr) = 0; protected: ~Delegate() {} @@ -147,10 +149,11 @@ class ExceptionHandlerServer { bool InstallClientSocket(ScopedFileHandle socket); bool UninstallClientSocket(Event* event); bool ReceiveClientMessage(Event* event); - bool HandleCrashDumpRequest(const msghdr& msg, - const ClientInformation& client_info, - VMAddress requesting_thread_stack_address, - int client_sock); + bool HandleCrashDumpRequest( + const msghdr& msg, + const ExceptionHandlerProtocol::ClientInformation& client_info, + VMAddress requesting_thread_stack_address, + int client_sock); std::unordered_map> clients_; std::unique_ptr shutdown_event_; diff --git a/handler/linux/exception_handler_server_test.cc b/handler/linux/exception_handler_server_test.cc index 7d15cbb9..1c57fce1 100644 --- a/handler/linux/exception_handler_server_test.cc +++ b/handler/linux/exception_handler_server_test.cc @@ -103,7 +103,7 @@ class TestDelegate : public ExceptionHandlerServer::Delegate { } bool HandleException(pid_t client_process_id, - const ClientInformation& info, + const ExceptionHandlerProtocol::ClientInformation& info, VMAddress requesting_thread_stack_address, pid_t* requesting_thread_id = nullptr, UUID* local_report_id = nullptr) override { @@ -134,10 +134,11 @@ class TestDelegate : public ExceptionHandlerServer::Delegate { return true; } - bool HandleExceptionWithBroker(pid_t client_process_id, - const ClientInformation& info, - int broker_sock, - UUID* local_report_id = nullptr) override { + bool HandleExceptionWithBroker( + pid_t client_process_id, + const ExceptionHandlerProtocol::ClientInformation& info, + int broker_sock, + UUID* local_report_id = nullptr) override { PtraceClient client; bool connected = client.Initialize(broker_sock, client_process_id); EXPECT_TRUE(connected); @@ -165,10 +166,11 @@ class MockPtraceStrategyDecider : public PtraceStrategyDecider { Strategy ChooseStrategy(int sock, const ucred& client_credentials) override { if (strategy_ == Strategy::kUseBroker) { - ServerToClientMessage message = {}; - message.type = ServerToClientMessage::kTypeForkBroker; + ExceptionHandlerProtocol::ServerToClientMessage message = {}; + message.type = + ExceptionHandlerProtocol::ServerToClientMessage::kTypeForkBroker; - Errno status; + ExceptionHandlerProtocol::Errno status; bool result = LoggingWriteFile(sock, &message, sizeof(message)) && LoggingReadFileExactly(sock, &status, sizeof(status)); EXPECT_TRUE(result); @@ -220,7 +222,7 @@ class ExceptionHandlerServerTest : public testing::Test { ~CrashDumpTest() = default; void MultiprocessParent() override { - ClientInformation info; + ExceptionHandlerProtocol::ClientInformation info; ASSERT_TRUE( LoggingReadFileExactly(ReadPipeHandle(), &info, sizeof(info))); @@ -239,7 +241,7 @@ class ExceptionHandlerServerTest : public testing::Test { void MultiprocessChild() override { ASSERT_EQ(close(server_test_->sock_to_client_), 0); - ClientInformation info; + ExceptionHandlerProtocol::ClientInformation info; info.exception_information_address = 42; ASSERT_TRUE(LoggingWriteFile(WritePipeHandle(), &info, sizeof(info))); diff --git a/util/linux/exception_handler_client.cc b/util/linux/exception_handler_client.cc index e4548d62..60970695 100644 --- a/util/linux/exception_handler_client.cc +++ b/util/linux/exception_handler_client.cc @@ -35,7 +35,8 @@ ExceptionHandlerClient::ExceptionHandlerClient(int sock) ExceptionHandlerClient::~ExceptionHandlerClient() = default; -int ExceptionHandlerClient::RequestCrashDump(const ClientInformation& info) { +int ExceptionHandlerClient::RequestCrashDump( + const ExceptionHandlerProtocol::ClientInformation& info) { VMAddress sp = FromPointerCast(&sp); int status = SendCrashDumpRequest(info, sp); @@ -64,10 +65,12 @@ void ExceptionHandlerClient::SetCanSetPtracer(bool can_set_ptracer) { can_set_ptracer_ = can_set_ptracer; } -int ExceptionHandlerClient::SendCrashDumpRequest(const ClientInformation& info, - VMAddress stack_pointer) { - ClientToServerMessage message; - message.type = ClientToServerMessage::kCrashDumpRequest; +int ExceptionHandlerClient::SendCrashDumpRequest( + const ExceptionHandlerProtocol::ClientInformation& info, + VMAddress stack_pointer) { + ExceptionHandlerProtocol::ClientToServerMessage message; + message.type = + ExceptionHandlerProtocol::ClientToServerMessage::kCrashDumpRequest; message.requesting_thread_stack_address = stack_pointer; message.client_info = info; @@ -105,19 +108,19 @@ int ExceptionHandlerClient::SendCrashDumpRequest(const ClientInformation& info, } int ExceptionHandlerClient::WaitForCrashDumpComplete() { - ServerToClientMessage message; + ExceptionHandlerProtocol::ServerToClientMessage message; // If the server hangs up, ReadFileExactly will return false without setting // errno. errno = 0; while (ReadFileExactly(server_sock_, &message, sizeof(message))) { switch (message.type) { - case ServerToClientMessage::kTypeForkBroker: { + case ExceptionHandlerProtocol::ServerToClientMessage::kTypeForkBroker: { Signals::InstallDefaultHandler(SIGCHLD); pid_t pid = fork(); if (pid <= 0) { - Errno error = pid < 0 ? errno : 0; + ExceptionHandlerProtocol::Errno error = pid < 0 ? errno : 0; if (!WriteFile(server_sock_, &error, sizeof(error))) { return errno; } @@ -148,16 +151,18 @@ int ExceptionHandlerClient::WaitForCrashDumpComplete() { continue; } - case ServerToClientMessage::kTypeSetPtracer: { - Errno result = SetPtracer(message.pid); + case ExceptionHandlerProtocol::ServerToClientMessage::kTypeSetPtracer: { + ExceptionHandlerProtocol::Errno result = SetPtracer(message.pid); if (!WriteFile(server_sock_, &result, sizeof(result))) { return errno; } continue; } - case ServerToClientMessage::kTypeCrashDumpComplete: - case ServerToClientMessage::kTypeCrashDumpFailed: + case ExceptionHandlerProtocol::ServerToClientMessage:: + kTypeCrashDumpComplete: + case ExceptionHandlerProtocol::ServerToClientMessage:: + kTypeCrashDumpFailed: return 0; } diff --git a/util/linux/exception_handler_client.h b/util/linux/exception_handler_client.h index 25a8a442..6492a12e 100644 --- a/util/linux/exception_handler_client.h +++ b/util/linux/exception_handler_client.h @@ -38,7 +38,7 @@ class ExceptionHandlerClient { //! //! \param[in] info Information about this client. //! \return 0 on success or an error code on failure. - int RequestCrashDump(const ClientInformation& info); + int RequestCrashDump(const ExceptionHandlerProtocol::ClientInformation& info); //! \brief Uses `prctl(PR_SET_PTRACER, ...)` to set the process with //! process ID \a pid as the ptracer for this process. @@ -53,8 +53,9 @@ class ExceptionHandlerClient { void SetCanSetPtracer(bool can_set_ptracer); private: - int SendCrashDumpRequest(const ClientInformation& info, - VMAddress stack_pointer); + int SendCrashDumpRequest( + const ExceptionHandlerProtocol::ClientInformation& info, + VMAddress stack_pointer); int WaitForCrashDumpComplete(); int server_sock_; diff --git a/util/linux/exception_handler_protocol.cc b/util/linux/exception_handler_protocol.cc index 3feca698..7ab77d39 100644 --- a/util/linux/exception_handler_protocol.cc +++ b/util/linux/exception_handler_protocol.cc @@ -16,10 +16,10 @@ namespace crashpad { -ClientInformation::ClientInformation() +ExceptionHandlerProtocol::ClientInformation::ClientInformation() : exception_information_address(0), sanitization_information_address(0) {} -ClientToServerMessage::ClientToServerMessage() +ExceptionHandlerProtocol::ClientToServerMessage::ClientToServerMessage() : version(kVersion), type(kCrashDumpRequest), client_info() {} } // namespace crashpad diff --git a/util/linux/exception_handler_protocol.h b/util/linux/exception_handler_protocol.h index 0ab3ffd0..d5eb5e88 100644 --- a/util/linux/exception_handler_protocol.h +++ b/util/linux/exception_handler_protocol.h @@ -19,81 +19,90 @@ #include #include +#include "base/macros.h" #include "util/file/file_io.h" #include "util/misc/address_types.h" namespace crashpad { +class ExceptionHandlerProtocol { + public: #pragma pack(push, 1) -//! \brief The type used for error reporting. -using Errno = int32_t; -static_assert(sizeof(Errno) >= sizeof(errno), "Errno type is too small"); + //! \brief The type used for error reporting. + using Errno = int32_t; + static_assert(sizeof(Errno) >= sizeof(errno), "Errno type is too small"); -//! \brief A boolean status suitable for communication between processes. -enum Bool : char { kBoolFalse, kBoolTrue }; + //! \brief A boolean status suitable for communication between processes. + enum Bool : char { kBoolFalse, kBoolTrue }; -//! \brief Information about a client registered with an ExceptionHandlerServer. -struct ClientInformation { - //! \brief Constructs this object. - ClientInformation(); + //! \brief Information about a client registered with an + //! ExceptionHandlerServer. + struct ClientInformation { + //! \brief Constructs this object. + ClientInformation(); - //! \brief The address in the client's address space of an - //! ExceptionInformation struct. - VMAddress exception_information_address; + //! \brief The address in the client's address space of an + //! ExceptionInformation struct. + VMAddress exception_information_address; - //! \brief The address in the client's address space of a - //! SanitizationInformation struct, or 0 if there is no such struct. - VMAddress sanitization_information_address; -}; - -//! \brief The message passed from client to server. -struct ClientToServerMessage { - static constexpr int32_t kVersion = 1; - - //! \brief Constructs this object. - ClientToServerMessage(); - - //! \brief Indicates what message version is being used. - int32_t version; - - //! \brief A stack address of the thread sending the message. - VMAddress requesting_thread_stack_address; - - enum Type : uint32_t { - //! \brief Used to request a crash dump for the sending client. - kCrashDumpRequest - } type; - - union { - //! \brief Valid for type == kCrashDumpRequest - ClientInformation client_info; + //! \brief The address in the client's address space of a + //! SanitizationInformation struct, or 0 if there is no such struct. + VMAddress sanitization_information_address; }; -}; -//! \brief The message passed from server to client. -struct ServerToClientMessage { - enum Type : uint32_t { - //! \brief Indicates that the client should fork a PtraceBroker process. - kTypeForkBroker, + //! \brief The message passed from client to server. + struct ClientToServerMessage { + static constexpr int32_t kVersion = 1; - //! \brief Inidicates that the client should set allow the handler to trace - //! it using PR_SET_PTRACER. - kTypeSetPtracer, + //! \brief Constructs this object. + ClientToServerMessage(); - //! \brief Indicates that the handler has completed a requested crash dump. - kTypeCrashDumpComplete, + //! \brief Indicates what message version is being used. + int32_t version; - //! \brief Indicicates that the handler was unable to produce a crash dump. - kTypeCrashDumpFailed - } type; + //! \brief A stack address of the thread sending the message. + VMAddress requesting_thread_stack_address; - //! \brief The handler's process ID. Valid for kTypeSetPtracer. - pid_t pid; -}; + enum Type : uint32_t { + //! \brief Used to request a crash dump for the sending client. + kCrashDumpRequest + } type; + + union { + //! \brief Valid for type == kCrashDumpRequest + ClientInformation client_info; + }; + }; + + //! \brief The message passed from server to client. + struct ServerToClientMessage { + enum Type : uint32_t { + //! \brief Indicates that the client should fork a PtraceBroker process. + kTypeForkBroker, + + //! \brief Inidicates that the client should set allow the handler to + //! trace it using PR_SET_PTRACER. + kTypeSetPtracer, + + //! \brief Indicates that the handler has completed a requested crash + //! dump. + kTypeCrashDumpComplete, + + //! \brief Indicicates that the handler was unable to produce a crash + //! dump. + kTypeCrashDumpFailed + } type; + + //! \brief The handler's process ID. Valid for kTypeSetPtracer. + pid_t pid; + }; #pragma pack(pop) + DISALLOW_IMPLICIT_CONSTRUCTORS(ExceptionHandlerProtocol); +}; + } // namespace crashpad #endif // CRASHPAD_UTIL_LINUX_EXCEPTION_HANDLER_PROTOCOL_H_ diff --git a/util/linux/ptrace_broker.cc b/util/linux/ptrace_broker.cc index 4d7e4ced..6ec0af5b 100644 --- a/util/linux/ptrace_broker.cc +++ b/util/linux/ptrace_broker.cc @@ -139,9 +139,10 @@ int PtraceBroker::RunImpl() { attach_on_stack = true; } - Bool status = kBoolFalse; + ExceptionHandlerProtocol::Bool status = + ExceptionHandlerProtocol::kBoolFalse; if (attach->ResetAttach(request.tid)) { - status = kBoolTrue; + status = ExceptionHandlerProtocol::kBoolTrue; if (!attach_on_stack) { ++attach_count_; } @@ -151,21 +152,23 @@ int PtraceBroker::RunImpl() { return errno; } - if (status == kBoolFalse) { - Errno error = errno; + if (status == ExceptionHandlerProtocol::kBoolFalse) { + ExceptionHandlerProtocol::Errno error = errno; if (!WriteFile(sock_, &error, sizeof(error))) { return errno; } } - if (attach_on_stack && status == kBoolTrue) { + if (attach_on_stack && status == ExceptionHandlerProtocol::kBoolTrue) { return RunImpl(); } continue; } case Request::kTypeIs64Bit: { - Bool is_64_bit = ptracer_.Is64Bit() ? kBoolTrue : kBoolFalse; + ExceptionHandlerProtocol::Bool is_64_bit = + ptracer_.Is64Bit() ? ExceptionHandlerProtocol::kBoolTrue + : ExceptionHandlerProtocol::kBoolFalse; if (!WriteFile(sock_, &is_64_bit, sizeof(is_64_bit))) { return errno; } @@ -175,15 +178,15 @@ int PtraceBroker::RunImpl() { case Request::kTypeGetThreadInfo: { GetThreadInfoResponse response; response.success = ptracer_.GetThreadInfo(request.tid, &response.info) - ? kBoolTrue - : kBoolFalse; + ? ExceptionHandlerProtocol::kBoolTrue + : ExceptionHandlerProtocol::kBoolFalse; if (!WriteFile(sock_, &response, sizeof(response))) { return errno; } - if (response.success == kBoolFalse) { - Errno error = errno; + if (response.success == ExceptionHandlerProtocol::kBoolFalse) { + ExceptionHandlerProtocol::Errno error = errno; if (!WriteFile(sock_, &error, sizeof(error))) { return errno; } @@ -249,7 +252,7 @@ int PtraceBroker::RunImpl() { } } -int PtraceBroker::SendError(Errno err) { +int PtraceBroker::SendError(ExceptionHandlerProtocol::Errno err) { return WriteFile(sock_, &err, sizeof(err)) ? 0 : errno; } diff --git a/util/linux/ptrace_broker.h b/util/linux/ptrace_broker.h index 47dd4d9b..6a7bfb72 100644 --- a/util/linux/ptrace_broker.h +++ b/util/linux/ptrace_broker.h @@ -146,7 +146,7 @@ class PtraceBroker { ThreadInfo info; //! \brief Specifies the success or failure of this call. - Bool success; + ExceptionHandlerProtocol::Bool success; }; #pragma pack(pop) @@ -196,7 +196,7 @@ class PtraceBroker { bool AllocateAttachments(); void ReleaseAttachments(); int RunImpl(); - int SendError(Errno err); + int SendError(ExceptionHandlerProtocol::Errno err); int SendReadError(ReadError err); int SendOpenResult(OpenResult result); int SendFileContents(FileHandle handle); diff --git a/util/linux/ptrace_client.cc b/util/linux/ptrace_client.cc index d822d10e..f0d0d50a 100644 --- a/util/linux/ptrace_client.cc +++ b/util/linux/ptrace_client.cc @@ -31,7 +31,7 @@ namespace crashpad { namespace { bool ReceiveAndLogError(int sock, const std::string& operation) { - Errno error; + ExceptionHandlerProtocol::Errno error; if (!LoggingReadFileExactly(sock, &error, sizeof(error))) { return false; } @@ -69,12 +69,12 @@ bool AttachImpl(int sock, pid_t tid) { return false; } - Bool success; + ExceptionHandlerProtocol::Bool success; if (!LoggingReadFileExactly(sock, &success, sizeof(success))) { return false; } - if (success != kBoolTrue) { + if (success != ExceptionHandlerProtocol::kBoolTrue) { ReceiveAndLogError(sock, "PtraceBroker Attach"); return false; } @@ -159,11 +159,11 @@ bool PtraceClient::Initialize(int sock, pid_t pid, bool try_direct_memory) { return false; } - Bool is_64_bit; + ExceptionHandlerProtocol::Bool is_64_bit; if (!LoggingReadFileExactly(sock_, &is_64_bit, sizeof(is_64_bit))) { return false; } - is_64_bit_ = is_64_bit == kBoolTrue; + is_64_bit_ = is_64_bit == ExceptionHandlerProtocol::kBoolTrue; if (try_direct_memory) { auto direct_mem = std::make_unique(); @@ -209,7 +209,7 @@ bool PtraceClient::GetThreadInfo(pid_t tid, ThreadInfo* info) { return false; } - if (response.success == kBoolTrue) { + if (response.success == ExceptionHandlerProtocol::kBoolTrue) { *info = response.info; return true; }