Parcourir la source

Replace checksum calculation

Isaac Woods il y a 7 ans
Parent
commit
ced19e123f
2 fichiers modifiés avec 9 ajouts et 5 suppressions
  1. 4 0
      src/lib.rs
  2. 5 5
      src/sdt.rs

+ 4 - 0
src/lib.rs

@@ -122,6 +122,8 @@ where
         /*
          * ACPI Version 1.0. It's a RSDT!
          */
+        (*mapping).validate(b"RSDT")?;
+
         let num_tables =
             ((*mapping).length() as usize - mem::size_of::<SdtHeader>()) / mem::size_of::<u32>();
         let tables_base =
@@ -134,6 +136,8 @@ where
         /*
          * ACPI Version 2.0+. It's a XSDT!
          */
+        (*mapping).validate(b"XSDT")?;
+
         let num_tables =
             ((*mapping).length() as usize - mem::size_of::<SdtHeader>()) / mem::size_of::<u64>();
         let tables_base =

+ 5 - 5
src/sdt.rs

@@ -39,14 +39,14 @@ impl SdtHeader {
             return Err(AcpiError::SdtInvalidTableId);
         }
 
-        // Sum all bytes in the SDT (not just the header)
-        let mut sum: usize = 0;
+        // Validate the checksum
+        let self_ptr = self as *const SdtHeader as *const u8;
+        let mut sum: u8 = 0;
         for i in 0..self.length {
-            sum += unsafe { *(self as *const SdtHeader as *const u8).offset(i as isize) } as usize;
+            sum = sum.wrapping_add(unsafe { *(self_ptr.offset(i as isize)) } as u8);
         }
 
-        // Check that the lowest byte is 0
-        if sum % 0b1111_1111 != 0 {
+        if sum > 0 {
             return Err(AcpiError::SdtInvalidChecksum);
         }