defs: use new kernel info structure#30
Conversation
137d9b4 to
b0519ab
Compare
e8f8f18 to
db8db97
Compare
include/boot.h
Outdated
| #define MLE_UUID1 0x74a7476f | ||
| #define MLE_UUID2 0xa2555c0f | ||
| #define MLE_UUID3 0x42b651cb | ||
| typedef struct __packed mle_header { |
There was a problem hiding this comment.
No need for this to be packed
|
By the way, I believe this address issue #41. |
Linux boot protocol versions 2.15+ use separate section to provide static information about the kernel, see [1]. MLE header offset, previously found directly in zero_page, is moved to this structure. This patch searches for proper address, located in new kernel_info structure. [1] https://01.org/linuxgraphics/gfx-docs/drm/x86/boot.html Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
db8db97 to
3b01316
Compare
main.c
Outdated
| if (bp->version < 0x020f | ||
| || ki->header != KERNEL_INFO_HEADER | ||
| || mle_header->uuid[0] != MLE_UUID0 |
There was a problem hiding this comment.
Sadly, Clang can (and will) miscompile this (Clang devs argue that it is legal under the C spec). It can logically turn each || into | to aggressively reduce the number of jumps (/basic blocks).
The most efficient (compact) way to write this is:
if (bp->version < 0x020f ||
(ki = _p(bp->code32_start +
bp->kern_info_offset))->header != KERNEL_INFO_HEADER ||
(mle_header = _p(bp->code32_start +
ki->mle_header_offset))->uuid[0] != MLE_UUID0 ||
...
which moves the assignment of the ki and mle_header variables until after the sequence point from the preceding || which forces the safety check to be first.
However, we should also do some sanity checks that all offsets from bp->code32_start fall within the kernel image, or a malformed kernel header can cause us to operate on junk. Perhaps we want some inline helpers such as $FOO *get_$FOO_header(...) which do all the sanity checks, so the outside logic can be:
if (bp->version < 0x020f ||
(ki = get_kern_info_header(bp)) != NULL ||
(mle_header = get_mle_header(bp, ki)) != NULL)
...
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
|
The Clang build fails reliably because it thinks |
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Linux boot protocol versions 2.15+ use separate section to provide static
information about the kernel, see [1]. MLE header offset, previously found
directly in zero_page, is moved to this new structure. This patch searches
for proper address, depending on boot protocol version.
As the old way of providing MLE header offset didn't make it to upstream
kernel, it should be deprecated at some point. It is left for the time
being, as there are some other components still using it.
[1] https://01.org/linuxgraphics/gfx-docs/drm/x86/boot.html
Signed-off-by: Krystian Hebel krystian.hebel@3mdeb.com