blob: ec3d591888cfcdb7f45a195938726da4e5d56c95 [file] [log] [blame]
Jaewan Kimc03f6612023-02-20 00:06:26 +09001// Copyright 2023, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Functions for AVF debug policy and debug level
16
17use android_system_virtualizationservice::aidl::android::system::virtualizationservice::{
Jiyong Parked180932023-02-24 19:55:41 +090018 VirtualMachineAppConfig::DebugLevel::DebugLevel, VirtualMachineConfig::VirtualMachineConfig,
Jaewan Kimc03f6612023-02-20 00:06:26 +090019};
20use std::fs::File;
21use std::io::Read;
22
23/// Get debug policy value in bool. It's true iff the value is explicitly set to <1>.
24fn get_debug_policy_bool(path: &'static str) -> Option<bool> {
Jaewan Kim66f062e2023-02-25 01:07:43 +090025 let mut file = File::open(path).ok()?;
26 let mut log: [u8; 4] = Default::default();
27 file.read_exact(&mut log).ok()?;
28 // DT spec uses big endian although Android is always little endian.
29 Some(u32::from_be_bytes(log) == 1)
Jaewan Kimc03f6612023-02-20 00:06:26 +090030}
31
32/// Get whether console output should be configred for VM to leave console and adb log.
33/// Caller should create pipe and prepare for receiving VM log with it.
34pub fn should_prepare_console_output(debug_level: DebugLevel) -> bool {
35 debug_level != DebugLevel::NONE
36 || get_debug_policy_bool("/proc/device-tree/avf/guest/common/log").unwrap_or_default()
Jaewan Kimb24d1dc2023-02-13 15:34:56 +090037 || get_debug_policy_bool("/proc/device-tree/avf/guest/microdroid/adb").unwrap_or_default()
38}
39
40/// Get whether debug apexes (MICRODROID_REQUIRED_APEXES_DEBUG) are required.
41pub fn should_include_debug_apexes(debug_level: DebugLevel) -> bool {
42 debug_level != DebugLevel::NONE
43 || get_debug_policy_bool("/proc/device-tree/avf/guest/microdroid/adb").unwrap_or_default()
Jaewan Kimc03f6612023-02-20 00:06:26 +090044}
Jiyong Parked180932023-02-24 19:55:41 +090045
46/// Decision to support ramdump
47pub fn is_ramdump_needed(config: &VirtualMachineConfig) -> bool {
48 let enabled_in_dp =
49 get_debug_policy_bool("/proc/device-tree/avf/guest/common/ramdump").unwrap_or_default();
Jaewan Kimb0106f82023-03-03 16:11:08 +090050 let debuggable = match config {
Jaewan Kim7898e852023-03-28 07:08:26 +000051 VirtualMachineConfig::RawConfig(_) => false,
Jaewan Kimb0106f82023-03-03 16:11:08 +090052 VirtualMachineConfig::AppConfig(config) => config.debugLevel == DebugLevel::FULL,
Jiyong Parked180932023-02-24 19:55:41 +090053 };
54
Jaewan Kimb0106f82023-03-03 16:11:08 +090055 enabled_in_dp || debuggable
Jiyong Parked180932023-02-24 19:55:41 +090056}