1
- use crate :: TagTrait ;
2
- use crate :: { Tag , TagTypeId } ;
1
+ use crate :: { Tag , TagTrait , TagType , TagTypeId } ;
3
2
use core:: fmt:: { Debug , Formatter } ;
3
+ use core:: mem:: size_of;
4
4
use core:: str:: Utf8Error ;
5
5
6
+ #[ cfg( feature = "builder" ) ]
7
+ use { crate :: builder:: boxed_dst_tag, alloc:: boxed:: Box , alloc:: vec:: Vec } ;
8
+
9
+ const METADATA_SIZE : usize = size_of :: < TagTypeId > ( ) + size_of :: < u32 > ( ) ;
10
+
6
11
/// The bootloader name tag.
7
12
#[ derive( ptr_meta:: Pointee ) ]
8
13
#[ repr( C , packed) ] // only repr(C) would add unwanted padding before first_section
@@ -14,6 +19,13 @@ pub struct BootLoaderNameTag {
14
19
}
15
20
16
21
impl BootLoaderNameTag {
22
+ #[ cfg( feature = "builder" ) ]
23
+ pub fn new ( name : & str ) -> Box < Self > {
24
+ let mut bytes: Vec < _ > = name. bytes ( ) . collect ( ) ;
25
+ bytes. push ( 0 ) ;
26
+ boxed_dst_tag ( TagType :: BootLoaderName , & bytes)
27
+ }
28
+
17
29
/// Reads the name of the bootloader that is booting the kernel as Rust
18
30
/// string slice without the null-byte.
19
31
///
@@ -46,10 +58,8 @@ impl Debug for BootLoaderNameTag {
46
58
47
59
impl TagTrait for BootLoaderNameTag {
48
60
fn dst_size ( base_tag : & Tag ) -> usize {
49
- // The size of the sized portion of the bootloader name tag.
50
- let tag_base_size = 8 ;
51
- assert ! ( base_tag. size >= 8 ) ;
52
- base_tag. size as usize - tag_base_size
61
+ assert ! ( base_tag. size as usize >= METADATA_SIZE ) ;
62
+ base_tag. size as usize - METADATA_SIZE
53
63
}
54
64
}
55
65
0 commit comments