@@ -28,18 +28,30 @@ type measurementOutput struct {
2828 MrImage string `json:"mr_image"`
2929}
3030
31+ const (
32+ GB = 1024 * 1024 * 1024 // in bytes
33+ MB = 1024 * 1024
34+ )
35+
3136var knownKeyProviders = map [string ]string {
3237 "sgx-v0" : "0x4888adb026ff91c1320c4f544a9f5d9e0561e13fc64947a10aa1556d0071b2cc" ,
3338 "none" : "0x3369c4d32b9f1320ebba5ce9892a283127b7e96e1d511d7f292e5d9ed2c10b8c" ,
3439}
3540
36- // parseMemorySize parses a human readable memory size (e.g., "1G", "512M") into megabytes
41+ // parseMemorySize parses a human readable memory size (e.g., "1G", "512M") into bytes
3742func parseMemorySize (size string ) (uint64 , error ) {
3843 size = strings .TrimSpace (strings .ToUpper (size ))
3944 if len (size ) == 0 {
4045 return 0 , fmt .Errorf ("empty memory size" )
4146 }
4247
48+ // Check if the input is purely numeric (no unit)
49+ if _ , err := strconv .ParseUint (size , 10 , 64 ); err == nil {
50+ // If it's a valid number with no unit, interpret as MB
51+ num , _ := strconv .ParseUint (size , 10 , 64 )
52+ return num , nil
53+ }
54+
4355 // Get the unit (last character)
4456 unit := size [len (size )- 1 :]
4557 // Get the number (everything except the last character)
@@ -51,12 +63,12 @@ func parseMemorySize(size string) (uint64, error) {
5163 return 0 , fmt .Errorf ("invalid memory size number: %v" , err )
5264 }
5365
54- // Convert to megabytes based on unit
66+ // Convert to bytes based on unit
5567 switch unit {
5668 case "G" :
57- return num * 1024 , nil // Convert GB to MB
69+ return num * GB , nil // Convert GB to bytes
5870 case "M" :
59- return num , nil // Already in MB
71+ return num * MB , nil // Convert MB to bytes
6072 default :
6173 return 0 , fmt .Errorf ("invalid memory unit '%s', must be one of: G, M" , unit )
6274 }
@@ -65,23 +77,22 @@ func parseMemorySize(size string) (uint64, error) {
6577type memoryValue uint64
6678
6779func (m * memoryValue ) String () string {
68- mb := uint64 (* m )
69- const (
70- GB = 1024 // in MB
71- )
72-
73- if mb >= GB && mb % GB == 0 {
74- return fmt .Sprintf ("%dG" , mb / GB )
80+ m_bytes := uint64 (* m )
81+ if m_bytes >= GB && m_bytes % GB == 0 {
82+ return fmt .Sprintf ("%dG" , m_bytes / GB )
83+ }
84+ if m_bytes >= MB && m_bytes % MB == 0 {
85+ return fmt .Sprintf ("%dM" , m_bytes / MB )
7586 }
76- return fmt .Sprintf ("%dM " , mb )
87+ return fmt .Sprintf ("%d " , m_bytes )
7788}
7889
7990func (m * memoryValue ) Set (value string ) error {
80- mb , err := parseMemorySize (value )
91+ m_bytes , err := parseMemorySize (value )
8192 if err != nil {
8293 return err
8394 }
84- * m = memoryValue (mb )
95+ * m = memoryValue (m_bytes )
8596 return nil
8697}
8798
@@ -91,7 +102,7 @@ func main() {
91102 fwPath string
92103 kernelPath string
93104 initrdPath string
94- memorySize memoryValue = 2048 // 2G default (in MB)
105+ memorySize memoryValue
95106 cpuCountUint uint
96107 kernelCmdline string
97108 jsonOutput bool
0 commit comments