Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 1 | // Copyright 2021, 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 | //! VM Payload Config |
| 16 | |
| 17 | use serde::{Deserialize, Serialize}; |
| 18 | |
| 19 | /// VM payload config |
Inseob Kim | 89b2459 | 2024-02-23 18:59:43 +0900 | [diff] [blame] | 20 | #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 21 | pub struct VmPayloadConfig { |
Inseob Kim | 89b2459 | 2024-02-23 18:59:43 +0900 | [diff] [blame] | 22 | /// OS config. |
| 23 | /// Deprecated: don't use. Error if not "" or "microdroid". |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 24 | #[serde(default)] |
Inseob Kim | 89b2459 | 2024-02-23 18:59:43 +0900 | [diff] [blame] | 25 | #[deprecated] |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 26 | pub os: OsConfig, |
| 27 | |
| 28 | /// Task to run in a VM |
| 29 | #[serde(default)] |
| 30 | pub task: Option<Task>, |
| 31 | |
| 32 | /// APEXes to activate in a VM |
| 33 | #[serde(default)] |
| 34 | pub apexes: Vec<ApexConfig>, |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 35 | |
Inseob Kim | a5a262f | 2021-11-17 19:41:03 +0900 | [diff] [blame] | 36 | /// Extra APKs to be passed to a VM |
| 37 | #[serde(default)] |
| 38 | pub extra_apks: Vec<ApkConfig>, |
| 39 | |
Jooyung Han | 5dc4217 | 2021-10-05 16:43:47 +0900 | [diff] [blame] | 40 | /// Tells VirtualizationService to use staged APEXes if possible |
| 41 | #[serde(default)] |
| 42 | pub prefer_staged: bool, |
Shikha Panwar | 6f03c94 | 2022-04-13 20:26:50 +0000 | [diff] [blame] | 43 | |
| 44 | /// Whether to export the tomsbtones (VM crashes) out of VM to host |
Inseob Kim | ab1037d | 2023-02-08 17:03:31 +0900 | [diff] [blame] | 45 | /// Default: true for debuggable VMs, false for non-debuggable VMs |
| 46 | pub export_tombstones: Option<bool>, |
Alan Stokes | 01b3ef0 | 2022-09-22 17:43:24 +0100 | [diff] [blame] | 47 | |
| 48 | /// Whether the authfs service should be started in the VM. This enables read or write of host |
| 49 | /// files with integrity checking, but not confidentiality. |
| 50 | #[serde(default)] |
| 51 | pub enable_authfs: bool, |
Vincent Donnefort | 538a2c6 | 2024-03-20 16:01:10 +0000 | [diff] [blame] | 52 | |
| 53 | /// Ask the kernel for transparent huge-pages (THP). This is only a hint and |
| 54 | /// the kernel will allocate THP-backed memory only if globally enabled by |
| 55 | /// the system and if any can be found. See |
| 56 | /// https://docs.kernel.org/admin-guide/mm/transhuge.html |
| 57 | #[serde(default)] |
| 58 | pub hugepages: bool, |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /// OS config |
| 62 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 63 | pub struct OsConfig { |
| 64 | /// The name of OS to use |
| 65 | pub name: String, |
| 66 | } |
| 67 | |
| 68 | impl Default for OsConfig { |
| 69 | fn default() -> Self { |
Inseob Kim | 89b2459 | 2024-02-23 18:59:43 +0900 | [diff] [blame] | 70 | Self { name: "".to_owned() } |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | /// Payload's task can be one of plain executable |
| 75 | /// or an .so library which can be started via /system/bin/microdroid_launcher |
Charisee | 668224f | 2023-03-03 02:02:34 +0000 | [diff] [blame] | 76 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, Default)] |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 77 | pub enum TaskType { |
| 78 | /// Task's command indicates the path to the executable binary. |
| 79 | #[serde(rename = "executable")] |
Charisee | 668224f | 2023-03-03 02:02:34 +0000 | [diff] [blame] | 80 | #[default] |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 81 | Executable, |
| 82 | /// Task's command indicates the .so library in /mnt/apk/lib/{arch} |
| 83 | #[serde(rename = "microdroid_launcher")] |
| 84 | MicrodroidLauncher, |
| 85 | } |
| 86 | |
| 87 | /// Task to run in a VM |
| 88 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 89 | pub struct Task { |
| 90 | /// Decides how to execute the command: executable(default) | microdroid_launcher |
| 91 | #[serde(default, rename = "type")] |
| 92 | pub type_: TaskType, |
| 93 | |
| 94 | /// Command to run |
| 95 | /// - For executable task, this is the path to the executable. |
| 96 | /// - For microdroid_launcher task, this is the name of .so |
| 97 | pub command: String, |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 98 | } |
| 99 | |
Jooyung Han | 634e2d7 | 2021-06-10 16:27:38 +0900 | [diff] [blame] | 100 | /// APEX config |
| 101 | /// For now, we only pass the name of APEX. |
| 102 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 103 | pub struct ApexConfig { |
| 104 | /// The name of APEX |
| 105 | pub name: String, |
| 106 | } |
Inseob Kim | a5a262f | 2021-11-17 19:41:03 +0900 | [diff] [blame] | 107 | |
| 108 | /// APK config |
| 109 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 110 | pub struct ApkConfig { |
| 111 | /// The path of APK |
| 112 | pub path: String, |
| 113 | } |