bf44c56a99
ACPICA commit 8ea5ada64b48dada42dbd5f0f58a9ce18f882ede Before this change we see the following UBSAN stack trace in Fuchsia: #0 0x000020d00518f81a in acpi_rs_convert_aml_to_resources(u8*, u32, u32, u8, void**) ../../third_party/acpica/source/components/resources/rslist.c:104 <platform-bus-x86.so>+0x2cd81a #1.2 0x00002348b567277f in ubsan_get_stack_trace() compiler-rt/lib/ubsan/ubsan_diag.cpp:41 <libclang_rt.asan.so>+0x3d77f #1.1 0x00002348b567277f in maybe_print_stack_trace() compiler-rt/lib/ubsan/ubsan_diag.cpp:51 <libclang_rt.asan.so>+0x3d77f #1 0x00002348b567277f in ~scoped_report() compiler-rt/lib/ubsan/ubsan_diag.cpp:387 <libclang_rt.asan.so>+0x3d77f #2 0x00002348b5673385 in handletype_mismatch_impl() compiler-rt/lib/ubsan/ubsan_handlers.cpp:137 <libclang_rt.asan.so>+0x3e385 #3 0x00002348b5672ead in compiler-rt/lib/ubsan/ubsan_handlers.cpp:142 <libclang_rt.asan.so>+0x3dead #4 0x000020d00518f81a in acpi_rs_convert_aml_to_resources(u8*, u32, u32, u8, void**) ../../third_party/acpica/source/components/resources/rslist.c:104 <platform-bus-x86.so>+0x2cd81a #5 0x000020d0051b8ea9 in acpi_ut_walk_aml_resources(struct acpi_walk_state*, u8*, acpi_size, acpi_walk_aml_callback, void**) ../../third_party/acpica/source/components/utilities/utresrc.c:234 <platform-bus-x86.so>+0x2f6ea9 #6 0x000020d00518a806 in acpi_rs_create_resource_list(union acpi_operand_object*, struct acpi_buffer*) ../../third_party/acpica/source/components/resources/rscreate.c:199 <platform-bus-x86.so>+0x2c8806 #7 0x000020d005195ff2 in acpi_rs_get_method_data(acpi_handle, const char*, struct acpi_buffer*) ../../third_party/acpica/source/components/resources/rsutils.c:770 <platform-bus-x86.so>+0x2d3ff2 #8 0x000020d00519636d in acpi_walk_resources(acpi_handle, char*, acpi_walk_resource_callback, void*) ../../third_party/acpica/source/components/resources/rsxface.c:731 <platform-bus-x86.so>+0x2d436d #9 0x000020d004fadd48 in acpi::acpi_impl::walk_resources(acpi::acpi_impl*, acpi_handle, const char*, acpi::Acpi::resources_callable) ../../src/devices/board/lib/acpi/acpi-impl.cc:41 <platform-bus-x86.so>+0xebd48 #10 0x000020d004fb394d in acpi::device_builder::gather_resources(acpi::device_builder*, acpi::Acpi*, fidl::any_arena&, acpi::Manager*, acpi::device_builder::gather_resources_callback) ../../src/devices/board/lib/acpi/device-builder.cc:52 <platform-bus-x86.so>+0xf194d #11 0x000020d00503faf2 in acpi::Manager::configure_discovered_devices(acpi::Manager*) ../../src/devices/board/lib/acpi/manager.cc:75 <platform-bus-x86.so>+0x17daf2 #12 0x000020d004f67b44 in publish_acpi_devices(acpi::Manager*, zx_device_t*, zx_device_t*) ../../src/devices/board/drivers/x86/acpi-nswalk.cc:102 <platform-bus-x86.so>+0xa5b44 #13 0x000020d004f796f7 in x86::X86::do_init(x86::X86*) ../../src/devices/board/drivers/x86/x86.cc:65 <platform-bus-x86.so>+0xb76f7 #14.1 0x000020d004f838ea in λ(x86::X86::ddk_init::(anon class)*) ../../src/devices/board/drivers/x86/x86.cc:82 <platform-bus-x86.so>+0xc18ea #14 0x000020d004f838ea in fit::internal::target<(lambda at../../src/devices/board/drivers/x86/x86.cc:81:19), false, false, void>::invoke(void*) ../../sdk/lib/fit/include/lib/fit/internal/function.h:181 <platform-bus-x86.so>+0xc18ea #15.2 0x000020d0051c896c in fit::internal::function_base<16UL, false, void()>::invoke(const fit::internal::function_base<16UL, false, void ()>*) ../../sdk/lib/fit/include/lib/fit/internal/function.h:505 <platform-bus-x86.so>+0x30696c #15.1 0x000020d0051c896c in fit::function_impl<16UL, false, void()>::operator()(const fit::function_impl<16UL, false, void ()>*) ../../sdk/lib/fit/include/lib/fit/function.h:300 <platform-bus-x86.so>+0x30696c #15 0x000020d0051c896c in async::internal::retained_task::Handler(async_dispatcher_t*, async_task_t*, zx_status_t) ../../zircon/system/ulib/async/task.cc:25 <platform-bus-x86.so>+0x30696c #16.1 0x00002061a33d3d91 in λ(const driver_runtime::Dispatcher::post_task::(anon class)*, std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request> >, zx_status_t) ../../src/devices/bin/driver_runtime/dispatcher.cc:715 <libdriver_runtime.so>+0x4bd91 #16 0x00002061a33d3d91 in fit::internal::target<(lambda at../../src/devices/bin/driver_runtime/dispatcher.cc:714:7), true, false, void, std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request>>, int>::invoke(void*, std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request> >, int) ../../sdk/lib/fit/include/lib/fit/internal/function.h:128 <libdriver_runtime.so>+0x4bd91 #17 0x00002061a33ccbc9 in fit::internal::function_base<24UL, true, void(std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request>>, int)>::invoke(const fit::internal::function_base<24UL, true, void (std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request> >, int)>*, std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request> >, int) ../../sdk/lib/fit/include/lib/fit/internal/function.h:505 <libdriver_runtime.so>+0x44bc9 #18 0x00002061a33cc8dd in fit::callback_impl<24UL, true, void(std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request>>, int)>::operator()(fit::callback_impl<24UL, true, void (std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request> >, int)>*, std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request> >, int) ../../sdk/lib/fit/include/lib/fit/function.h:451 <libdriver_runtime.so>+0x448dd #19 0x00002061a33bd6a6 in driver_runtime::callback_request::Call(driver_runtime::callback_request*, std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request> >, zx_status_t) ../../src/devices/bin/driver_runtime/callback_request.h:67 <libdriver_runtime.so>+0x356a6 #20 0x00002061a33c44c8 in driver_runtime::Dispatcher::dispatch_callback(driver_runtime::Dispatcher*, std::__2::unique_ptr<driver_runtime::callback_request, std::__2::default_delete<driver_runtime::callback_request> >) ../../src/devices/bin/driver_runtime/dispatcher.cc:1093 <libdriver_runtime.so>+0x3c4c8 #21 0x00002061a33c52c1 in driver_runtime::Dispatcher::dispatch_callbacks(driver_runtime::Dispatcher*, std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter> >, fbl::ref_ptr<driver_runtime::Dispatcher>) ../../src/devices/bin/driver_runtime/dispatcher.cc:1169 <libdriver_runtime.so>+0x3d2c1 #22.1 0x00002061a33d081e in λ(std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter> >, fbl::ref_ptr<driver_runtime::Dispatcher>, const driver_runtime::Dispatcher::create_with_adder::(anon class)*) ../../src/devices/bin/driver_runtime/dispatcher.cc:338 <libdriver_runtime.so>+0x4881e #22 0x00002061a33d081e in fit::internal::target<(lambda at../../src/devices/bin/driver_runtime/dispatcher.cc:337:7), true, false, void, std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter>>, fbl::ref_ptr<driver_runtime::Dispatcher>>::invoke(void*, std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter> >, fbl::ref_ptr<driver_runtime::Dispatcher>) ../../sdk/lib/fit/include/lib/fit/internal/function.h:128 <libdriver_runtime.so>+0x4881e #23 0x00002061a33cce7e in fit::internal::function_base<8UL, true, void(std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter>>, fbl::ref_ptr<driver_runtime::Dispatcher>)>::invoke(const fit::internal::function_base<8UL, true, void (std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter> >, fbl::ref_ptr<driver_runtime::Dispatcher>)>*, std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter> >, fbl::ref_ptr<driver_runtime::Dispatcher>) ../../sdk/lib/fit/include/lib/fit/internal/function.h:505 <libdriver_runtime.so>+0x44e7e #24.1 0x00002061a33c6964 in fit::function_impl<8UL, true, void(std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter>>, fbl::ref_ptr<driver_runtime::Dispatcher>)>::operator()(const fit::function_impl<8UL, true, void (std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter> >, fbl::ref_ptr<driver_runtime::Dispatcher>)>*, std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter> >, fbl::ref_ptr<driver_runtime::Dispatcher>) ../../sdk/lib/fit/include/lib/fit/function.h:300 <libdriver_runtime.so>+0x3e964 #24 0x00002061a33c6964 in driver_runtime::Dispatcher::event_waiter::invoke_callback(driver_runtime::Dispatcher::event_waiter*, std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter> >, fbl::ref_ptr<driver_runtime::Dispatcher>) ../../src/devices/bin/driver_runtime/dispatcher.h:299 <libdriver_runtime.so>+0x3e964 #25 0x00002061a33c635d in driver_runtime::Dispatcher::event_waiter::handle_event(std::__2::unique_ptr<driver_runtime::Dispatcher::event_waiter, std::__2::default_delete<driver_runtime::Dispatcher::event_waiter> >, async_dispatcher_t*, async::wait_base*, zx_status_t, zx_packet_signal_t const*) ../../src/devices/bin/driver_runtime/dispatcher.cc:1259 <libdriver_runtime.so>+0x3e35d #26.1 0x00002061a33d0c00 in async_loop_owned_event_handler<driver_runtime::Dispatcher::event_waiter>::handle_event(async_loop_owned_event_handler<driver_runtime::Dispatcher::event_waiter>*, zx_status_t, zx_packet_signal_t const*, async_dispatcher_t*, async::wait_base*) ../../src/devices/bin/driver_runtime/async_loop_owned_event_handler.h:59 <libdriver_runtime.so>+0x48c00 #26 0x00002061a33d0c00 in async::wait_method<async_loop_owned_event_handler<driver_runtime::Dispatcher::event_waiter>, &async_loop_owned_event_handler<driver_runtime::Dispatcher::event_waiter>::handle_event>::call_handler(async_dispatcher_t*, async_wait_t*, zx_status_t, zx_packet_signal_t const*) ../../zircon/system/ulib/async/include/lib/async/cpp/wait.h:201 <libdriver_runtime.so>+0x48c00 #27.1 0x00002061a33f2ead in async_loop_run_once(async_loop_t*, zx_time_t) ../../zircon/system/ulib/async-loop/loop.c:415 <libdriver_runtime.so>+0x6aead #27 0x00002061a33f2ead in async_loop_run(async_loop_t*, zx_time_t, _Bool) ../../zircon/system/ulib/async-loop/loop.c:288 <libdriver_runtime.so>+0x6aead #28 0x00002061a33f478f in async_loop_run_thread(void*) ../../zircon/system/ulib/async-loop/loop.c:840 <libdriver_runtime.so>+0x6c78f #29 0x00004262135b7edc in start_c11(void*) ../../zircon/third_party/ulib/musl/pthread/pthread_create.c:55 <libc.so>+0xd7edc #30 0x00004262136e896d in thread_trampoline(uintptr_t, uintptr_t) ../../zircon/system/ulib/runtime/thread.cc:100 <libc.so>+0x20896d Link: https://github.com/acpica/acpica/commit/8ea5ada6 Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
236 lines
7.0 KiB
C
236 lines
7.0 KiB
C
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
|
|
/*******************************************************************************
|
|
*
|
|
* Module Name: rslist - Linked list utilities
|
|
*
|
|
******************************************************************************/
|
|
|
|
#include <acpi/acpi.h>
|
|
#include "accommon.h"
|
|
#include "acresrc.h"
|
|
|
|
#define _COMPONENT ACPI_RESOURCES
|
|
ACPI_MODULE_NAME("rslist")
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* FUNCTION: acpi_rs_convert_aml_to_resources
|
|
*
|
|
* PARAMETERS: acpi_walk_aml_callback
|
|
* resource_ptr - Pointer to the buffer that will
|
|
* contain the output structures
|
|
*
|
|
* RETURN: Status
|
|
*
|
|
* DESCRIPTION: Convert an AML resource to an internal representation of the
|
|
* resource that is aligned and easier to access.
|
|
*
|
|
******************************************************************************/
|
|
acpi_status
|
|
acpi_rs_convert_aml_to_resources(u8 * aml,
|
|
u32 length,
|
|
u32 offset, u8 resource_index, void **context)
|
|
{
|
|
struct acpi_resource **resource_ptr =
|
|
ACPI_CAST_INDIRECT_PTR(struct acpi_resource, context);
|
|
struct acpi_resource *resource;
|
|
union aml_resource *aml_resource;
|
|
struct acpi_rsconvert_info *conversion_table;
|
|
acpi_status status;
|
|
|
|
ACPI_FUNCTION_TRACE(rs_convert_aml_to_resources);
|
|
|
|
/*
|
|
* Check that the input buffer and all subsequent pointers into it
|
|
* are aligned on a native word boundary. Most important on IA64
|
|
*/
|
|
resource = *resource_ptr;
|
|
if (ACPI_IS_MISALIGNED(resource)) {
|
|
ACPI_WARNING((AE_INFO,
|
|
"Misaligned resource pointer %p", resource));
|
|
}
|
|
|
|
/* Get the appropriate conversion info table */
|
|
|
|
aml_resource = ACPI_CAST_PTR(union aml_resource, aml);
|
|
|
|
if (acpi_ut_get_resource_type(aml) == ACPI_RESOURCE_NAME_SERIAL_BUS) {
|
|
|
|
/* Avoid undefined behavior: member access within misaligned address */
|
|
|
|
struct aml_resource_common_serialbus common_serial_bus;
|
|
memcpy(&common_serial_bus, aml_resource,
|
|
sizeof(common_serial_bus));
|
|
|
|
if (common_serial_bus.type > AML_RESOURCE_MAX_SERIALBUSTYPE) {
|
|
conversion_table = NULL;
|
|
} else {
|
|
/* This is an I2C, SPI, UART, or CSI2 serial_bus descriptor */
|
|
|
|
conversion_table =
|
|
acpi_gbl_convert_resource_serial_bus_dispatch
|
|
[common_serial_bus.type];
|
|
}
|
|
} else {
|
|
conversion_table =
|
|
acpi_gbl_get_resource_dispatch[resource_index];
|
|
}
|
|
|
|
if (!conversion_table) {
|
|
ACPI_ERROR((AE_INFO,
|
|
"Invalid/unsupported resource descriptor: Type 0x%2.2X",
|
|
resource_index));
|
|
return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
|
|
}
|
|
|
|
/* Convert the AML byte stream resource to a local resource struct */
|
|
|
|
status =
|
|
acpi_rs_convert_aml_to_resource(resource, aml_resource,
|
|
conversion_table);
|
|
if (ACPI_FAILURE(status)) {
|
|
ACPI_EXCEPTION((AE_INFO, status,
|
|
"Could not convert AML resource (Type 0x%X)",
|
|
*aml));
|
|
return_ACPI_STATUS(status);
|
|
}
|
|
|
|
if (!resource->length) {
|
|
ACPI_EXCEPTION((AE_INFO, status,
|
|
"Zero-length resource returned from RsConvertAmlToResource"));
|
|
}
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
"Type %.2X, AmlLength %.2X InternalLength %.2X\n",
|
|
acpi_ut_get_resource_type(aml), length,
|
|
resource->length));
|
|
|
|
/* Point to the next structure in the output buffer */
|
|
|
|
*resource_ptr = ACPI_NEXT_RESOURCE(resource);
|
|
return_ACPI_STATUS(AE_OK);
|
|
}
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* FUNCTION: acpi_rs_convert_resources_to_aml
|
|
*
|
|
* PARAMETERS: resource - Pointer to the resource linked list
|
|
* aml_size_needed - Calculated size of the byte stream
|
|
* needed from calling acpi_rs_get_aml_length()
|
|
* The size of the output_buffer is
|
|
* guaranteed to be >= aml_size_needed
|
|
* output_buffer - Pointer to the buffer that will
|
|
* contain the byte stream
|
|
*
|
|
* RETURN: Status
|
|
*
|
|
* DESCRIPTION: Takes the resource linked list and parses it, creating a
|
|
* byte stream of resources in the caller's output buffer
|
|
*
|
|
******************************************************************************/
|
|
|
|
acpi_status
|
|
acpi_rs_convert_resources_to_aml(struct acpi_resource *resource,
|
|
acpi_size aml_size_needed, u8 * output_buffer)
|
|
{
|
|
u8 *aml = output_buffer;
|
|
u8 *end_aml = output_buffer + aml_size_needed;
|
|
struct acpi_rsconvert_info *conversion_table;
|
|
acpi_status status;
|
|
|
|
ACPI_FUNCTION_TRACE(rs_convert_resources_to_aml);
|
|
|
|
/* Walk the resource descriptor list, convert each descriptor */
|
|
|
|
while (aml < end_aml) {
|
|
|
|
/* Validate the (internal) Resource Type */
|
|
|
|
if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
|
|
ACPI_ERROR((AE_INFO,
|
|
"Invalid descriptor type (0x%X) in resource list",
|
|
resource->type));
|
|
return_ACPI_STATUS(AE_BAD_DATA);
|
|
}
|
|
|
|
/* Sanity check the length. It must not be zero, or we loop forever */
|
|
|
|
if (!resource->length) {
|
|
ACPI_ERROR((AE_INFO,
|
|
"Invalid zero length descriptor in resource list\n"));
|
|
return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
|
|
}
|
|
|
|
/* Perform the conversion */
|
|
|
|
if (resource->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
|
|
if (resource->data.common_serial_bus.type >
|
|
AML_RESOURCE_MAX_SERIALBUSTYPE) {
|
|
conversion_table = NULL;
|
|
} else {
|
|
/* This is an I2C, SPI, UART or CSI2 serial_bus descriptor */
|
|
|
|
conversion_table =
|
|
acpi_gbl_convert_resource_serial_bus_dispatch
|
|
[resource->data.common_serial_bus.type];
|
|
}
|
|
} else {
|
|
conversion_table =
|
|
acpi_gbl_set_resource_dispatch[resource->type];
|
|
}
|
|
|
|
if (!conversion_table) {
|
|
ACPI_ERROR((AE_INFO,
|
|
"Invalid/unsupported resource descriptor: Type 0x%2.2X",
|
|
resource->type));
|
|
return_ACPI_STATUS(AE_AML_INVALID_RESOURCE_TYPE);
|
|
}
|
|
|
|
status = acpi_rs_convert_resource_to_aml(resource,
|
|
ACPI_CAST_PTR(union
|
|
aml_resource,
|
|
aml),
|
|
conversion_table);
|
|
if (ACPI_FAILURE(status)) {
|
|
ACPI_EXCEPTION((AE_INFO, status,
|
|
"Could not convert resource (type 0x%X) to AML",
|
|
resource->type));
|
|
return_ACPI_STATUS(status);
|
|
}
|
|
|
|
/* Perform final sanity check on the new AML resource descriptor */
|
|
|
|
status =
|
|
acpi_ut_validate_resource(NULL,
|
|
ACPI_CAST_PTR(union aml_resource,
|
|
aml), NULL);
|
|
if (ACPI_FAILURE(status)) {
|
|
return_ACPI_STATUS(status);
|
|
}
|
|
|
|
/* Check for end-of-list, normal exit */
|
|
|
|
if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
|
|
|
|
/* An End Tag indicates the end of the input Resource Template */
|
|
|
|
return_ACPI_STATUS(AE_OK);
|
|
}
|
|
|
|
/*
|
|
* Extract the total length of the new descriptor and set the
|
|
* Aml to point to the next (output) resource descriptor
|
|
*/
|
|
aml += acpi_ut_get_descriptor_length(aml);
|
|
|
|
/* Point to the next input resource descriptor */
|
|
|
|
resource = ACPI_NEXT_RESOURCE(resource);
|
|
}
|
|
|
|
/* Completed buffer, but did not find an end_tag resource descriptor */
|
|
|
|
return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
|
|
}
|