From a5e466bc2c02df13e369d2ef846d0895e562d732 Mon Sep 17 00:00:00 2001 From: Undefine Date: Sat, 31 Oct 2026 21:45:19 +0100 Subject: [PATCH] LibACPI: Add Object::as_pointer and Object::release_as Those will be needed to avoid some copies that are not allowed in the kernel. --- Userland/Libraries/LibACPI/Object.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibACPI/Object.h b/Userland/Libraries/LibACPI/Object.h index fb67ec0eb7b..434e7a9fc7a 100644 --- a/Userland/Libraries/LibACPI/Object.h +++ b/Userland/Libraries/LibACPI/Object.h @@ -81,9 +81,26 @@ public: template constexpr ErrorOr as() const + { + return *TRY(as_pointer()); + } + + template + constexpr ErrorOr as_pointer() const { if (m_data.has()) - return m_data.get(); + return m_data.get_pointer(); + + // TODO: Implement casting according both to ACPI spec and whatever Windows does. + // https://uefi.org/specs/ACPI/6.6/19_ASL_Reference.html#implicit-source-operand-conversion + return Error::from_string_view_or_print_error_and_return_errno("Can not cast given type!"sv, EINVAL); + } + + template + constexpr ErrorOr release_as() + { + if (m_data.has()) + return move(m_data.get()); // TODO: Implement casting according both to ACPI spec and whatever Windows does. // https://uefi.org/specs/ACPI/6.6/19_ASL_Reference.html#implicit-source-operand-conversion