From a3ca745b5acc6d09acf07e21105ce0c25ec70f69 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 9 Apr 2020 18:03:57 +0200 Subject: [PATCH] Kernel: Use StringView for ACPI table signatures --- Kernel/ACPI/ACPIParser.h | 2 +- Kernel/ACPI/ACPIStaticParser.cpp | 31 +++++++++++++---------- Kernel/ACPI/ACPIStaticParser.h | 2 +- Kernel/ACPI/Definitions.h | 6 +---- Kernel/Interrupts/InterruptManagement.cpp | 2 +- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Kernel/ACPI/ACPIParser.h b/Kernel/ACPI/ACPIParser.h index 0fb09fd3373..8a69682b5c8 100644 --- a/Kernel/ACPI/ACPIParser.h +++ b/Kernel/ACPI/ACPIParser.h @@ -47,7 +47,7 @@ public: set_the(*new ParserType(rsdp)); } - virtual PhysicalAddress find_table(const char* sig) = 0; + virtual PhysicalAddress find_table(const StringView& signature) = 0; virtual void try_acpi_reboot() = 0; virtual bool can_reboot() = 0; diff --git a/Kernel/ACPI/ACPIStaticParser.cpp b/Kernel/ACPI/ACPIStaticParser.cpp index 042dd7cc0f4..292f71f17a6 100644 --- a/Kernel/ACPI/ACPIStaticParser.cpp +++ b/Kernel/ACPI/ACPIStaticParser.cpp @@ -37,6 +37,11 @@ namespace Kernel { namespace ACPI { +static bool match_table_signature(PhysicalAddress table_header, const StringView& signature); +static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt, const StringView& signature); +static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt, const StringView& signature); +static bool validate_table(const Structures::SDTHeader&, size_t length); + void StaticParser::locate_static_data() { locate_main_system_description_table(); @@ -45,7 +50,7 @@ void StaticParser::locate_static_data() init_facs(); } -PhysicalAddress StaticParser::find_table(const char* sig) +PhysicalAddress StaticParser::find_table(const StringView& signature) { #ifdef ACPI_DEBUG dbg() << "ACPI: Calling Find Table method!"; @@ -55,7 +60,7 @@ PhysicalAddress StaticParser::find_table(const char* sig) #ifdef ACPI_DEBUG dbg() << "ACPI: Examining Table @ P " << p_sdt; #endif - if (!strncmp(sdt->sig, sig, 4)) { + if (!strncmp(sdt->sig, signature.characters_without_null_termination(), 4)) { #ifdef ACPI_DEBUG dbg() << "ACPI: Found Table @ P " << p_sdt; #endif @@ -256,7 +261,7 @@ void StaticParser::initialize_main_system_description_table() auto sdt = map_typed(m_main_system_description_table, length); - klog() << "ACPI: Main Description Table valid? " << StaticParsing::validate_table(*sdt, length); + klog() << "ACPI: Main Description Table valid? " << validate_table(*sdt, length); if (m_xsdt_supported) { auto& xsdt = (const Structures::XSDT&)*sdt; @@ -343,7 +348,7 @@ static PhysicalAddress find_rsdp_in_bios_area() return {}; } -inline bool StaticParsing::validate_table(const Structures::SDTHeader& v_header, size_t length) +static bool validate_table(const Structures::SDTHeader& v_header, size_t length) { u8 checksum = 0; auto* sdt = (const u8*)&v_header; @@ -364,11 +369,11 @@ PhysicalAddress StaticParsing::find_rsdp() return find_rsdp_in_bios_area(); } -PhysicalAddress StaticParsing::search_table(PhysicalAddress rsdp_address, const char* signature) +PhysicalAddress StaticParsing::find_table(PhysicalAddress rsdp_address, const StringView& signature) { // FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables. // FIXME: Don't blindly use PAGE_SIZE here, but probe the actual length. - ASSERT(strlen(signature) == 4); + ASSERT(signature.length() == 4); auto rsdp = map_typed(rsdp_address); @@ -383,11 +388,11 @@ PhysicalAddress StaticParsing::search_table(PhysicalAddress rsdp_address, const ASSERT_NOT_REACHED(); } -PhysicalAddress StaticParsing::search_table_in_xsdt(PhysicalAddress xsdt_address, const char* signature) +static PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt_address, const StringView& signature) { // FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables. // FIXME: Don't blindly use PAGE_SIZE here, but probe the actual length. - ASSERT(strlen(signature) == 4); + ASSERT(signature.length() == 4); auto xsdt = map_typed(xsdt_address); @@ -398,21 +403,21 @@ PhysicalAddress StaticParsing::search_table_in_xsdt(PhysicalAddress xsdt_address return {}; } -bool StaticParsing::match_table_signature(PhysicalAddress table_header, const char* signature) +static bool match_table_signature(PhysicalAddress table_header, const StringView& signature) { // FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables. // FIXME: Don't blindly use PAGE_SIZE here, but probe the actual length. - ASSERT(strlen(signature) == 4); + ASSERT(signature.length() == 4); auto table = map_typed(table_header); - return !strncmp(table->h.sig, signature, 4); + return !strncmp(table->h.sig, signature.characters_without_null_termination(), 4); } -PhysicalAddress StaticParsing::search_table_in_rsdt(PhysicalAddress rsdt_address, const char* signature) +static PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt_address, const StringView& signature) { // FIXME: There's no validation of ACPI tables here. Use the checksum to validate the tables. // FIXME: Don't blindly use PAGE_SIZE here, but probe the actual length. - ASSERT(strlen(signature) == 4); + ASSERT(signature.length() == 4); auto rsdt = map_typed(rsdt_address); diff --git a/Kernel/ACPI/ACPIStaticParser.h b/Kernel/ACPI/ACPIStaticParser.h index 905995b16ee..506b16de0ea 100644 --- a/Kernel/ACPI/ACPIStaticParser.h +++ b/Kernel/ACPI/ACPIStaticParser.h @@ -36,7 +36,7 @@ class StaticParser : public Parser { friend class Parser; public: - virtual PhysicalAddress find_table(const char* sig) override; + virtual PhysicalAddress find_table(const StringView& signature) override; virtual void try_acpi_reboot() override; virtual bool can_reboot() override; virtual bool can_shutdown() override { return false; } diff --git a/Kernel/ACPI/Definitions.h b/Kernel/ACPI/Definitions.h index 37fa9f657d4..aa4f5718c52 100644 --- a/Kernel/ACPI/Definitions.h +++ b/Kernel/ACPI/Definitions.h @@ -337,11 +337,7 @@ class Parser; namespace StaticParsing { PhysicalAddress find_rsdp(); -bool match_table_signature(PhysicalAddress table_header, const char*); -PhysicalAddress search_table(PhysicalAddress rsdp, const char*); -PhysicalAddress search_table_in_xsdt(PhysicalAddress xsdt, const char*); -PhysicalAddress search_table_in_rsdt(PhysicalAddress rsdt, const char*); -bool validate_table(const Structures::SDTHeader&, size_t length); +PhysicalAddress find_table(PhysicalAddress rsdp, const StringView& signature); }; } } diff --git a/Kernel/Interrupts/InterruptManagement.cpp b/Kernel/Interrupts/InterruptManagement.cpp index 5ac2e087efa..da597beb323 100644 --- a/Kernel/Interrupts/InterruptManagement.cpp +++ b/Kernel/Interrupts/InterruptManagement.cpp @@ -130,7 +130,7 @@ PhysicalAddress InterruptManagement::search_for_madt() auto rsdp = ACPI::StaticParsing::find_rsdp(); if (rsdp.is_null()) return {}; - return ACPI::StaticParsing::search_table(rsdp, "APIC"); + return ACPI::StaticParsing::find_table(rsdp, "APIC"); } InterruptManagement::InterruptManagement()