#ifndef COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
#define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
#include <sys/types.h>
#include <memory>
#include <set>
#include <string>
#include "base/containers/heap_array.h"
#include "base/files/file_path.h"
#include "base/files/scoped_file.h"
#include "base/memory/raw_ptr.h"
#include "base/message_loop/message_pump_for_io.h"
#include "base/process/process_handle.h"
#include "base/synchronization/atomic_flag.h"
#include "base/synchronization/lock.h"
#include "base/task/current_thread.h"
#include "build/build_config.h"
#include "arkweb/build/features/features.h"
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(ARKWEB_CRASHPAD)
#include "components/crash/core/app/breakpad_linux_impl.h"
#endif
namespace base {
class SequencedTaskRunner;
class Thread;
}
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(ARKWEB_CRASHPAD)
namespace breakpad {
struct BreakpadInfo;
class CrashHandlerHostLinux : public base::MessagePumpForIO::FdWatcher,
public base::CurrentThread::DestructionObserver {
public:
CrashHandlerHostLinux(const std::string& process_type,
const base::FilePath& dumps_path,
bool upload);
CrashHandlerHostLinux(const CrashHandlerHostLinux&) = delete;
CrashHandlerHostLinux& operator=(const CrashHandlerHostLinux&) = delete;
~CrashHandlerHostLinux() override;
void StartUploaderThread();
int GetDeathSignalSocket() const {
return process_socket_;
}
void OnFileCanWriteWithoutBlocking(int fd) override;
void OnFileCanReadWithoutBlocking(int fd) override;
void WillDestroyCurrentMessageLoop() override;
bool IsShuttingDown() const;
private:
void Init();
void WriteDumpFile(BreakpadInfo* info,
base::HeapArray<char> crash_context,
pid_t crashing_pid);
void QueueCrashDumpTask(std::unique_ptr<BreakpadInfo> info, int signal_fd);
void FindCrashingThreadAndDump(
pid_t crashing_pid,
const std::string& expected_syscall_data,
base::HeapArray<char> crash_context,
std::unique_ptr<crash_reporter::internal::TransitionalCrashKeyStorage>
crash_keys,
#if defined(ADDRESS_SANITIZER)
base::HeapArray<char> asan_report,
#endif
uint64_t uptime,
size_t oom_size,
int signal_fd,
int attempt);
const std::string process_type_;
const base::FilePath dumps_path_;
#if !BUILDFLAG(IS_ANDROID)
const bool upload_;
#endif
int process_socket_;
int browser_socket_;
base::MessagePumpForIO::FdWatchController fd_watch_controller_;
std::unique_ptr<base::Thread> uploader_thread_;
base::AtomicFlag shutting_down_;
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
};
}
#endif
#if !BUILDFLAG(IS_CHROMEOS)
namespace crashpad {
class CrashHandlerHost : public base::MessagePumpForIO::FdWatcher,
public base::CurrentThread::DestructionObserver {
public:
class Observer {
public:
virtual void ChildReceivedCrashSignal(base::ProcessId pid, int signo) = 0;
};
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
static CrashHandlerHost* Get();
CrashHandlerHost(const CrashHandlerHost&) = delete;
CrashHandlerHost& operator=(const CrashHandlerHost&) = delete;
int GetDeathSignalSocket();
protected:
~CrashHandlerHost() override;
private:
CrashHandlerHost();
void Init();
bool ReceiveClientMessage(int client_fd,
base::ScopedFD* handler_fd,
bool* write_minidump_to_database);
void NotifyCrashSignalObservers(base::ProcessId pid, int signo);
void OnFileCanWriteWithoutBlocking(int fd) override;
void OnFileCanReadWithoutBlocking(int fd) override;
void WillDestroyCurrentMessageLoop() override;
base::Lock observers_lock_;
std::set<raw_ptr<Observer, SetExperimental>> observers_;
base::MessagePumpForIO::FdWatchController fd_watch_controller_;
base::ScopedFD process_socket_;
base::ScopedFD browser_socket_;
};
}
#endif
#endif