]> xenbits.xensource.com Git - seabios.git/commitdiff
csm: Sanitise alignment constraint in Legacy16GetTableAddress
authorDavid Woodhouse <dwmw2@infradead.org>
Thu, 13 Jun 2019 15:25:13 +0000 (16:25 +0100)
committerKevin O'Connor <kevin@koconnor.net>
Tue, 18 Jun 2019 22:42:19 +0000 (18:42 -0400)
The alignment constraint is defined in the CSM specifications as
"Bit mapped.  First non-zero bit from the right is the alignment."

Use __fls() to sanitise the alignment given that definition, since
passing a non-power-of-two alignment to _malloc() isn't going to work
well. And cope with being passed zero, which was happening for the
E820 table allocation from EDK2.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
src/fw/csm.c

index 03b4bb81e3e85757cb6ec776e4bd2067222542ca..3fcc252975c71e5ed2184e3af36e50a2d89fa7d6 100644 (file)
@@ -258,11 +258,21 @@ handle_csm_0006(struct bregs *regs)
     u16 region = regs->bx; // (1 for F000 seg, 2 for E000 seg, 0 for either)
     void *chunk = NULL;
 
+    dprintf(3, "Legacy16GetTableAddress size %x align %x region %d\n",
+        size, align, region);
+
     if (!region)
         region = 3;
 
-    dprintf(3, "Legacy16GetTableAddress size %x align %x region %d\n",
-        size, align, region);
+    // DX = Required address alignment. Bit mapped.
+    // First non-zero bit from the right is the alignment.*/
+    if (align) {
+        align = 1 << __ffs(align);
+        if (align < MALLOC_MIN_ALIGN)
+            align = MALLOC_MIN_ALIGN;
+    } else {
+        align = MALLOC_MIN_ALIGN;
+    }
 
     if (region & 2)
         chunk = _malloc(&ZoneLow, size, align);