rust-osdev/acpi

AML: Terminal `If` without `Else` causing `UnexpectedEndOfStream` in control methods

alnyan opened this issue · 1 comments

When a DefIfElse operation appears at the end of a control method, the code parsing it throws an UnexpectedEndOfStream while trying to parse the Else part of the op.

The following ASL fails:

Method (_INI, 0, NotSerialized) {
    If ((\SCMP (\_OS, "Microsoft Windows NT") == Zero)) {
        ...
    }
    // No Else part and no other opcodes
}

And the following two examples don't (assuming they're the bodies of the same _INI method):

If ((\SCMP (\_OS, "Microsoft Windows NT") == Zero)) {
    ...
} Else {
    // May even be empty, it just needs to be there
}

and

If ((\SCMP (\_OS, "Microsoft Windows NT") == Zero)) {
    ...
}
Local1 = 0x00 // Just some random code after the If

So when parsing DefIfElse, the parser tries to read beyond the end of the stream, returning an error. A fix for this shouldn't be hard to implement, I'll try doing that, but I'm currently busy trying to implement some primitive kind of *Ref ops support.

Fixed by #190

Aside: thanks for the great examples in the issue! Useful to have this stuff for posterity