From 83510526b66c17ed26ac86e75eb1632ed0630138 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 12 Nov 2026 10:15:32 +0100 Subject: libs/acpi: don't convert addresses to pointer Previously, ACPI table addresses in both the RSDT and XSDT were converted to pointers. However, this is not actually correct, since within the object model of the kernel, pointers always refer to objects by their linear address, and the addresses encoded in ACPI tables are, by necessity, physical addresses. The API should therefore be honest about the fact that the addresses returned by accessors of the RSDT and XSDT are physical addresses, not pointers to live objects. --- libs/acpi/acpi/data/rsdt.cpp | 6 ++---- libs/acpi/acpi/data/rsdt.hpp | 6 +++--- libs/acpi/acpi/data/rsdt.tests.cpp | 2 +- libs/acpi/acpi/data/xsdt.cpp | 6 ++---- libs/acpi/acpi/data/xsdt.hpp | 6 +++--- libs/acpi/acpi/data/xsdt.tests.cpp | 2 +- 6 files changed, 12 insertions(+), 16 deletions(-) (limited to 'libs') diff --git a/libs/acpi/acpi/data/rsdt.cpp b/libs/acpi/acpi/data/rsdt.cpp index a8626742..99090beb 100644 --- a/libs/acpi/acpi/data/rsdt.cpp +++ b/libs/acpi/acpi/data/rsdt.cpp @@ -1,7 +1,5 @@ #include -#include - #include #include @@ -16,7 +14,7 @@ namespace acpi std::uint32_t address; }; - [[nodiscard]] auto rsdt_entry::address() const noexcept -> table_header * + [[nodiscard]] auto rsdt_entry::address() const noexcept -> std::uintptr_t { using type = decltype(rsdt_entry_data::address); @@ -28,7 +26,7 @@ namespace acpi kstd::libc::memcpy(&value, data.data(), size); - return reinterpret_cast(static_cast(value)); + return static_cast(value); } [[nodiscard]] auto rsdt_entry::length() const noexcept -> std::size_t diff --git a/libs/acpi/acpi/data/rsdt.hpp b/libs/acpi/acpi/data/rsdt.hpp index ca36b33d..843e6cf2 100644 --- a/libs/acpi/acpi/data/rsdt.hpp +++ b/libs/acpi/acpi/data/rsdt.hpp @@ -1,13 +1,13 @@ #ifndef ACPI_DATA_RSDT_HPP #define ACPI_DATA_RSDT_HPP -#include #include #include #include #include #include +#include namespace acpi { @@ -37,8 +37,8 @@ namespace acpi //! Get the address of the ACPI table pointed to by this entry. //! - //! @return A pointer to the ACPI table header of the referenced table. - [[nodiscard]] auto address() const noexcept -> table_header *; + //! @return The physical address of the ACPI table header of the referenced table. + [[nodiscard]] auto address() const noexcept -> std::uintptr_t; //! Get the length of the ACPI table pointed to by this entry. //! diff --git a/libs/acpi/acpi/data/rsdt.tests.cpp b/libs/acpi/acpi/data/rsdt.tests.cpp index c111f749..691fd631 100644 --- a/libs/acpi/acpi/data/rsdt.tests.cpp +++ b/libs/acpi/acpi/data/rsdt.tests.cpp @@ -41,7 +41,7 @@ SCENARIO("RSDT parsing", "[rsdt]") THEN("the first entry has address 0x10") { - REQUIRE(rsdt->cbegin()->address() == reinterpret_cast(0x10)); + REQUIRE(rsdt->cbegin()->address() == 0x10); } THEN("the length is sizeof(rsdt) + 8 * sizeof(rsdt_entry)") diff --git a/libs/acpi/acpi/data/xsdt.cpp b/libs/acpi/acpi/data/xsdt.cpp index c4b109b8..6f280889 100644 --- a/libs/acpi/acpi/data/xsdt.cpp +++ b/libs/acpi/acpi/data/xsdt.cpp @@ -1,7 +1,5 @@ #include -#include - #include #include @@ -16,7 +14,7 @@ namespace acpi std::uint64_t address; }; - [[nodiscard]] auto xsdt_entry::address() const noexcept -> table_header * + [[nodiscard]] auto xsdt_entry::address() const noexcept -> std::uintptr_t { using type = decltype(xsdt_entry_data::address); @@ -28,7 +26,7 @@ namespace acpi kstd::libc::memcpy(&value, data.data(), size); - return reinterpret_cast(static_cast(value)); + return static_cast(value); } [[nodiscard]] auto xsdt_entry::length() const noexcept -> std::size_t diff --git a/libs/acpi/acpi/data/xsdt.hpp b/libs/acpi/acpi/data/xsdt.hpp index ef268d5f..f8c0a775 100644 --- a/libs/acpi/acpi/data/xsdt.hpp +++ b/libs/acpi/acpi/data/xsdt.hpp @@ -1,13 +1,13 @@ #ifndef ACPI_DATA_XSDT_HPP #define ACPI_DATA_XSDT_HPP -#include #include #include #include #include #include +#include namespace acpi { @@ -37,8 +37,8 @@ namespace acpi //! Get the address of the ACPI table pointed to by this entry. //! - //! @return A pointer to the ACPI table header of the referenced table. - [[nodiscard]] auto address() const noexcept -> table_header *; + //! @return The physical address of the ACPI table header of the referenced table. + [[nodiscard]] auto address() const noexcept -> std::uintptr_t; //! Get the length of the ACPI table pointed to by this entry. //! diff --git a/libs/acpi/acpi/data/xsdt.tests.cpp b/libs/acpi/acpi/data/xsdt.tests.cpp index e5eaed67..955c08df 100644 --- a/libs/acpi/acpi/data/xsdt.tests.cpp +++ b/libs/acpi/acpi/data/xsdt.tests.cpp @@ -41,7 +41,7 @@ SCENARIO("XSDT parsing", "[xsdt]") THEN("the first entry has address 0x10") { - REQUIRE(xsdt->cbegin()->address() == reinterpret_cast(0x10)); + REQUIRE(xsdt->cbegin()->address() == 0x10); } THEN("the length is sizeof(xsdt) + 8 * sizeof(xsdt_entry)") -- cgit v1.2.3