|
@@ -1,9 +1,15 @@
|
|
|
//! Module for [CommandLineTag].
|
|
|
|
|
|
-use crate::{Tag, TagTrait, TagTypeId};
|
|
|
+use crate::{Tag, TagTrait, TagType, TagTypeId};
|
|
|
use core::fmt::{Debug, Formatter};
|
|
|
+use core::mem;
|
|
|
use core::str;
|
|
|
|
|
|
+#[cfg(feature = "builder")]
|
|
|
+use {crate::builder::boxed_dst_tag, alloc::boxed::Box, alloc::vec::Vec};
|
|
|
+
|
|
|
+pub(crate) const METADATA_SIZE: usize = mem::size_of::<TagTypeId>() + mem::size_of::<u32>();
|
|
|
+
|
|
|
/// This tag contains the command line string.
|
|
|
///
|
|
|
/// The string is a normal C-style UTF-8 zero-terminated string that can be
|
|
@@ -18,6 +24,14 @@ pub struct CommandLineTag {
|
|
|
}
|
|
|
|
|
|
impl CommandLineTag {
|
|
|
+ /// Create a new command line tag from the given string.
|
|
|
+ #[cfg(feature = "builder")]
|
|
|
+ pub fn new(command_line: &str) -> Box<Self> {
|
|
|
+ let mut bytes: Vec<_> = command_line.bytes().collect();
|
|
|
+ bytes.push(0);
|
|
|
+ boxed_dst_tag(TagType::Cmdline, &bytes)
|
|
|
+ }
|
|
|
+
|
|
|
/// Reads the command line of the kernel as Rust string slice without
|
|
|
/// the null-byte.
|
|
|
///
|
|
@@ -52,10 +66,8 @@ impl Debug for CommandLineTag {
|
|
|
|
|
|
impl TagTrait for CommandLineTag {
|
|
|
fn dst_size(base_tag: &Tag) -> usize {
|
|
|
- // The size of the sized portion of the command line tag.
|
|
|
- let tag_base_size = 8;
|
|
|
- assert!(base_tag.size >= 8);
|
|
|
- base_tag.size as usize - tag_base_size
|
|
|
+ assert!(base_tag.size as usize >= METADATA_SIZE);
|
|
|
+ base_tag.size as usize - METADATA_SIZE
|
|
|
}
|
|
|
}
|
|
|
|