1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 use std::collections::HashMap;
6
7 use anyhow::Result;
8 use base::RecvTube;
9 use base::SendTube;
10 use serde::Deserialize;
11 use serde::Serialize;
12 #[cfg(windows)]
13 use win_util::ProcessType;
14
15 #[cfg(unix)]
16 pub enum ProcessType {}
17
18 /// The reason a SimulatedException crash report is being requested.
19 #[derive(Clone, Copy, Serialize, Deserialize, Debug, Eq, PartialEq)]
20 pub enum CrashReportReason {
21 /// A default value for unspecified crash report reason.
22 Unknown,
23 }
24
25 #[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, Eq)]
26 enum CrashTubeCommand {
27 UploadCrashReport(CrashReportReason),
28 }
29
30 pub mod product_type {
31 pub const EMULATOR: &str = "KiwiEmulator_main";
32 pub const BROKER: &str = "KiwiEmulator_broker";
33 pub const DISK: &str = "KiwiEmulator_disk";
34 pub const NET: &str = "KiwiEmulator_net";
35 pub const SLIRP: &str = "KiwiEmulator_slirp";
36 pub const METRICS: &str = "KiwiEmulator_metrics";
37 pub const GPU: &str = "KiwiEmulator_gpu";
38 pub const SND: &str = "KiwiEmulator_snd";
39 pub const SPU: &str = "KiwiEmulator_spu";
40 }
41
42 /// Attributes about a process that are required to set up annotations for crash reports.
43 #[derive(Debug, Serialize, Deserialize, Clone)]
44 pub struct CrashReportAttributes {
45 pub product_type: String,
46 pub pipe_name: Option<String>,
47 pub report_uuid: Option<String>,
48 pub product_name: Option<String>,
49 pub product_version: Option<String>,
50 }
51
52 /// Handler for remote crash requests from other processes.
53 pub struct RemoteCrashHandler {}
54
55 impl RemoteCrashHandler {
56 /// Creates a handler for remote crash requests from other processes.
new(_crash_tube: RecvTube) -> Result<Self>57 pub fn new(_crash_tube: RecvTube) -> Result<Self> {
58 Ok(Self {})
59 }
60 }
61
62 impl Drop for RemoteCrashHandler {
drop(&mut self)63 fn drop(&mut self) {}
64 }
65
66 /// Setup crash reporting for a process. Each process MUST provide a unique `product_type` to avoid
67 /// making crash reports incomprehensible.
setup_crash_reporting(mut _attrs: CrashReportAttributes) -> Result<String>68 pub fn setup_crash_reporting(mut _attrs: CrashReportAttributes) -> Result<String> {
69 Ok(String::new())
70 }
71
72 /// Sets a map of tubes to trigger SimulatedException crash reports for each process type. Should
73 /// only be called on the main process.
set_crash_tube_map(_map: HashMap<ProcessType, Vec<SendTube>>)74 pub fn set_crash_tube_map(_map: HashMap<ProcessType, Vec<SendTube>>) {}
75
76 /// Captures a crash dump and uploads a crash report, without crashing the process.
77 ///
78 /// A crash report from the current process is always taken, modulo rate limiting. Additionally,
79 /// crash reports can be triggered on other processes, if the caller is the main process and
80 /// `reason` was mapped to process types with `set_crash_tube_map`.
upload_crash_report(_reason: CrashReportReason)81 pub fn upload_crash_report(_reason: CrashReportReason) {}
82
83 /// Sets the package name to given `_package_name`.
set_package_name(_package_name: &str)84 pub fn set_package_name(_package_name: &str) {}
85