It's pattern matching- the underscore is like a default label in a switch statement. It means "anything not matched above," while the line above it means "put optional_rsdt in the new variable real_rsdt if it 'fits' in that type." It's how I extracted the value from optional_rsdt- the match statement is a null check. Because you're allergic to functional programming, which I obviously shouldn't have mentioned, here's the C syntax:Brendan wrote:Ah - now I understand. The underscore character on line 70 ("_ -> /* no rsdt */") is your renamed NULL.
Actually, no. I don't understand the line above it ("real_rsdt: acpi_rsdt* -> parse_acpi_tables(real_rsdt)") which looks like it creates a variable called "read_rsdt" of type "acpi_rsdt*" and assigns the value returned by "parse_acpi_tables(real_rsdt)" to the variable. In C syntax it'd be "acpit_rsdt *read_rsdt = parse_acpi_tables(real_rsdt);", and you'd get a warning about using an uninitialised variable as the argument to "parse_acpi_tables()".
Code: Select all
if (optional_rsdt) {
acpi_rsdt *real_rsdt = optional_rsdt;
parse_acpi_tables(real_rsdt);
}
else {
/* no rsdt */
}
madt->controllers is a byte array with its contents being cast to different-sized structures, not "a heterogeneous array that isn't a heterogeneous array." But yes, it would make more sense to check if the length field of the current controller goes past the madt structure. That would be caught by the compiler in this imaginary language. Would it be caught in C?Brendan wrote:How does the "controller <= madt->controllers[-1]&;" make sense? Should I translate it into "stop looping if the starting address of the current controller is not lower than or equal to the starting address of the last entry in a heterogeneous array that isn't a heterogeneous array"?
Wouldn't it make more sense to do "stop looping if the address of the "length" field in the controller structure would be past the end of the parent "acpi_madt" structure; and (if the first check passes and you can safely use the length field of the controller structure) also stop looping if the "controller start address plus controller length field" is beyond the size of the parent acpi_madt structure"?
If you can't rely on the length fields of the ACPI structures, you're screwed anyway and you'd get the same checksum result no matter how you write the program. At that point, the problem is in the firmware. Besides, as we all know this is a systems programming language and the goal is not 100% memory safety, just an improvement over the brain-dead type checker that is C's.Brendan wrote:Given a correct RSDT? Nobody said it's a correct RSDT.
I've already explained how this is possible, but that discussion got sidetracked onto functional programming because you're allergic to academia and refuse to look at research papers that explain the details.Brendan wrote:I don't think that the ability to do compile time enforcement of explicit run-time checking is realistic either (another "sounds easy to do until you attempt to implement a compiler that does it" feature).