Browse Source

AML: Fix DefPackage len < NumElements failing

Mark Poliakov 1 year ago
parent
commit
05c5578c5c
2 changed files with 8 additions and 1 deletions
  1. 6 1
      aml/src/expression.rs
  2. 2 0
      aml/src/value.rs

+ 6 - 1
aml/src/expression.rs

@@ -624,10 +624,15 @@ where
                         package_contents.push(value);
                     }
 
-                    if package_contents.len() != num_elements as usize {
+                    // ACPI6.2, §19.6.101 specifies that if NumElements is present and is greater
+                    // than the number of entries in the PackageList, the default entry of type
+                    // Uninitialized is used
+                    if package_contents.len() > num_elements as usize {
                         return Err((input, context, Propagate::Err(AmlError::MalformedPackage)));
                     }
 
+                    package_contents.resize(num_elements as usize, AmlValue::Uninitialized);
+
                     Ok((input, context, AmlValue::Package(package_contents)))
                 }
             }),

+ 2 - 0
aml/src/value.rs

@@ -174,6 +174,7 @@ impl fmt::Debug for MethodCode {
 
 #[derive(Clone, Debug)]
 pub enum AmlValue {
+    Uninitialized,
     Boolean(bool),
     Integer(u64),
     String(String),
@@ -246,6 +247,7 @@ impl AmlValue {
 
     pub fn type_of(&self) -> AmlType {
         match self {
+            AmlValue::Uninitialized => AmlType::Uninitialized,
             AmlValue::Boolean(_) => AmlType::Integer,
             AmlValue::Integer(_) => AmlType::Integer,
             AmlValue::String(_) => AmlType::String,