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 use std::os::raw::c_char;
7
8 use anyhow::Result;
9 use base::RecvTube;
10 use base::SendTube;
11 use serde::Deserialize;
12 use serde::Serialize;
13 #[cfg(windows)]
14 use win_util::ProcessType;
15
16 #[cfg(any(target_os = "android", target_os = "linux"))]
17 pub enum ProcessType {}
18
19 /// The reason a SimulatedException crash report is being requested.
20 #[derive(Clone, Copy, Serialize, Deserialize, Debug, Eq, PartialEq)]
21 pub enum CrashReportReason {
22 /// A default value for unspecified crash report reason.
23 Unknown,
24 /// A gfxstream render thread hanged.
25 GfxstreamRenderThreadHang,
26 /// A gfxstream sync thread hanged.
27 GfxstreamSyncThreadHang,
28 /// A gfxstream hang was detected unassociated with a specific type.
29 GfxstreamOtherHang,
30 }
31
32 #[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, Eq)]
33 enum CrashTubeCommand {
34 UploadCrashReport(CrashReportReason),
35 }
36
37 pub mod product_type {
38 pub const EMULATOR: &str = "KiwiEmulator_main";
39 pub const BROKER: &str = "KiwiEmulator_broker";
40 pub const DISK: &str = "KiwiEmulator_disk";
41 pub const NET: &str = "KiwiEmulator_net";
42 pub const SLIRP: &str = "KiwiEmulator_slirp";
43 pub const METRICS: &str = "KiwiEmulator_metrics";
44 pub const GPU: &str = "KiwiEmulator_gpu";
45 pub const SND: &str = "KiwiEmulator_snd";
46 pub const SPU: &str = "KiwiEmulator_spu";
47 }
48
49 /// Attributes about a process that are required to set up annotations for crash reports.
50 #[derive(Debug, Serialize, Deserialize, Clone)]
51 pub struct CrashReportAttributes {
52 pub product_type: String,
53 pub pipe_name: Option<String>,
54 pub report_uuid: Option<String>,
55 pub product_name: Option<String>,
56 pub product_version: Option<String>,
57 }
58
59 /// Handler for remote crash requests from other processes.
60 pub struct RemoteCrashHandler {}
61
62 impl RemoteCrashHandler {
63 /// Creates a handler for remote crash requests from other processes.
new(_crash_tube: RecvTube) -> Result<Self>64 pub fn new(_crash_tube: RecvTube) -> Result<Self> {
65 Ok(Self {})
66 }
67 }
68
69 impl Drop for RemoteCrashHandler {
drop(&mut self)70 fn drop(&mut self) {}
71 }
72
73 /// Setup crash reporting for a process. Each process MUST provide a unique `product_type` to avoid
74 /// making crash reports incomprehensible.
setup_crash_reporting(mut _attrs: CrashReportAttributes) -> Result<String>75 pub fn setup_crash_reporting(mut _attrs: CrashReportAttributes) -> Result<String> {
76 Ok(String::new())
77 }
78
79 /// Sets a map of tubes to trigger SimulatedException crash reports for each process type. Should
80 /// only be called on the main process.
set_crash_tube_map(_map: HashMap<ProcessType, Vec<SendTube>>)81 pub fn set_crash_tube_map(_map: HashMap<ProcessType, Vec<SendTube>>) {}
82
83 /// Captures a crash dump and uploads a crash report, without crashing the process.
84 ///
85 /// A crash report from the current process is always taken, modulo rate limiting. Additionally,
86 /// crash reports can be triggered on other processes, if the caller is the main process and
87 /// `reason` was mapped to process types with `set_crash_tube_map`.
upload_crash_report(_reason: CrashReportReason)88 pub fn upload_crash_report(_reason: CrashReportReason) {}
89
90 /// Sets the package name to given `_package_name`.
set_package_name(_package_name: &str)91 pub fn set_package_name(_package_name: &str) {}
92
93 /// Update (insert when key is not present) a key-value pair annotation in a crash report.
update_annotation(_key: *const c_char, _value: *const c_char)94 pub extern "C" fn update_annotation(_key: *const c_char, _value: *const c_char) {}
95
96 pub struct GfxstreamAbort;
97