blob: c9b4482ac8b923338daf7951c0f4cf48c9a3c2ba [file]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#ifndef SRC_DEVELOPER_FORENSICS_EXCEPTIONS_PROCESS_HANDLER_H_
#define SRC_DEVELOPER_FORENSICS_EXCEPTIONS_PROCESS_HANDLER_H_
#include <fidl/fuchsia.exception.internal/cpp/fidl.h>
#include <lib/async/dispatcher.h>
#include <lib/fit/function.h>
#include <lib/zx/channel.h>
#include <lib/zx/exception.h>
#include <lib/zx/process.h>
#include <lib/zx/thread.h>
namespace forensics {
namespace exceptions {
// Handles a pending exception by handing it off to a subprocess. The lifetime of the subprocess
// is automatically managed and it is replaced if it crashes.
class ProcessHandler : public fidl::AsyncEventHandler<fuchsia_exception_internal::CrashReporter> {
public:
using LogMonikerFn = fit::function<void(const std::string&)>;
ProcessHandler(async_dispatcher_t* dispatcher, bool suspend_enabled, LogMonikerFn log_moniker,
fit::closure on_available);
~ProcessHandler() override;
ProcessHandler(ProcessHandler&&) = default;
ProcessHandler& operator=(ProcessHandler&&) = default;
void Handle(zx::exception exception, zx::process process, zx::thread thread);
// |fidl::AsyncEventHandler<fuchsia_exception_internal::CrashReporter>|
void on_fidl_error(fidl::UnbindInfo error) override;
private:
async_dispatcher_t* dispatcher_;
bool suspend_enabled_;
LogMonikerFn log_moniker_;
fit::closure on_available_;
zx::process subprocess_;
fidl::Client<fuchsia_exception_internal::CrashReporter> crash_reporter_;
};
} // namespace exceptions
} // namespace forensics
#endif // SRC_DEVELOPER_FORENSICS_EXCEPTIONS_PROCESS_HANDLER_H_