From 1c5985148c8e03fddb1df1e4dccc10b14f2b583f Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 30 Oct 2023 17:51:18 +0200 Subject: [PATCH] Kernel: Allow offsetof with packed fields This is not standard C++ but should be fine with my toolchain. --- kernel/CMakeLists.txt | 3 +++ kernel/kernel/ACPI.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index d7e140a5..bbc24efc 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -148,6 +148,9 @@ target_compile_options(kernel PUBLIC $<$:-Wno-literal-suff target_compile_options(kernel PUBLIC -fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.) target_compile_options(kernel PUBLIC -fstack-protector -ffreestanding -Wall -Werror=return-type -Wstack-usage=1024 -fno-omit-frame-pointer -mgeneral-regs-only) +# This might not work with other toolchains +target_compile_options(kernel PUBLIC $<$:-Wno-invalid-offsetof>) + if(ENABLE_KERNEL_UBSAN) target_compile_options(kernel PUBLIC -fsanitize=undefined) endif() diff --git a/kernel/kernel/ACPI.cpp b/kernel/kernel/ACPI.cpp index 86ac0a3a..e853a253 100644 --- a/kernel/kernel/ACPI.cpp +++ b/kernel/kernel/ACPI.cpp @@ -213,7 +213,7 @@ namespace Kernel auto* fadt = (FADT*)header; paddr_t dsdt_paddr = 0; - if (fadt->length > 140) // 140 is the offset of x_dsdt + if (fadt->length > offsetof(FADT, x_dsdt)) dsdt_paddr = fadt->x_dsdt; if (dsdt_paddr == 0 || !PageTable::is_valid_pointer(dsdt_paddr)) dsdt_paddr = fadt->dsdt;