blob: 856d83bd7bec6be1d9cbdc0dbd5627956a51261b [file] [log] [blame]
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ArcvmNativeCollector handles crashes of native binaries in ARCVM. When the
// ARCVM kernel detects a crash, it executes arc-native-crash-dispatcher via its
// /proc/sys/kernel/core_pattern. arc-native-crash-dispatcher calls
// arc-native-crash-collector32 or arc-native-crash-collector64 and writes dump
// files at /data/vendor/arc_native_crash_reports in the ARCVM filesystem.
// ArcCrashCollector, which is a service running in ARCVM, monitors the
// /data/vendor/arc_native_crash_reports directory and sends detected dump files
// to Chrome via Mojo. Finally Chrome invokes this collector.
#ifndef CRASH_REPORTER_ARCVM_NATIVE_COLLECTOR_H_
#define CRASH_REPORTER_ARCVM_NATIVE_COLLECTOR_H_
#include "crash-reporter/arc_util.h"
#include "crash-reporter/crash_collector.h"
#include <string>
#include <base/files/file_path.h>
// Collector for native crashes in ARCVM.
class ArcvmNativeCollector : public CrashCollector {
public:
// The basic information about crash. They are used for the filename of files
// passed to crash_sender.
struct CrashInfo {
time_t time; // The time when the crash happens.
pid_t pid; // The process ID (in ARCVM) of the crashed process.
std::string exec_name; // The name of crashed binary.
};
ArcvmNativeCollector();
~ArcvmNativeCollector() override;
// Handles a native crash in ARCVM.
// TODO(kimiyuki): Replace |minidump_fd| with a path and make "/dev/stdin" the
// default argument.
bool HandleCrash(const arc_util::BuildProperty& build_property,
const CrashInfo& crash_info,
int minidump_fd);
private:
friend class ArcvmNativeCollectorMock;
friend class ArcvmNativeCollectorTest;
FRIEND_TEST(ArcvmNativeCollectorTest, HandleCrash);
FRIEND_TEST(ArcvmNativeCollectorTest, AddArcMetadata);
// Checks whether it should dump the crash.
bool ShouldDump(std::string* reason) const;
// Adds ARC-related metadata to the crash report.
void AddArcMetadata(const arc_util::BuildProperty& build_property,
const CrashInfo& crash_info);
// Reads the content from FD and writes it to the specified path.
bool DumpFdToFile(int fd, const base::FilePath& path);
};
#endif // CRASH_REPORTER_ARCVM_NATIVE_COLLECTOR_H_