Skip to content

Commit

Permalink
Don't leak table mappings from LoadTable
Browse files Browse the repository at this point in the history
Preserve the index of the table that we originally used to execute the
load and unmap once we're done with it.

Signed-off-by: Daniil Tatianin <99danilt@gmail.com>
  • Loading branch information
d-tatianin committed Oct 25, 2024
1 parent 2fe17a8 commit 5f518fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
24 changes: 15 additions & 9 deletions source/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1291,18 +1291,23 @@ static uacpi_status handle_load_table(struct execution_context *ctx)
* new AML GPE handlers that might've been loaded, as well as potentially
* remove the target.
*/
if (item_array_size(items) == 11) {
if (item_array_size(items) == 12) {
uacpi_size idx;

idx = item_array_at(items, 2)->immediate;
uacpi_table_unref(&(struct uacpi_table) { .index = idx });

/*
* If this load failed, remove the target that was provided via
* ParameterPathString so that it doesn't get stored to.
*/
if (uacpi_unlikely(item_array_at(items, 10)->obj->integer == 0)) {
if (uacpi_unlikely(item_array_at(items, 11)->obj->integer == 0)) {
uacpi_object *target;

target = item_array_at(items, 2)->obj;
target = item_array_at(items, 3)->obj;
if (target != UACPI_NULL) {
uacpi_object_unref(target);
item_array_at(items, 2)->obj = UACPI_NULL;
item_array_at(items, 3)->obj = UACPI_NULL;
}

return UACPI_STATUS_OK;
Expand All @@ -1314,15 +1319,15 @@ static uacpi_status handle_load_table(struct execution_context *ctx)

ret = build_table_id(
"LoadTable", &table_id,
item_array_at(items, 4)->obj->buffer,
item_array_at(items, 5)->obj->buffer,
item_array_at(items, 6)->obj->buffer
item_array_at(items, 6)->obj->buffer,
item_array_at(items, 7)->obj->buffer
);
if (uacpi_unlikely_error(ret))
return ret;

root_path = item_array_at(items, 7)->obj->buffer;
param_path = item_array_at(items, 8)->obj->buffer;
root_path = item_array_at(items, 8)->obj->buffer;
param_path = item_array_at(items, 9)->obj->buffer;

if (root_path->size > 1) {
root_node = uacpi_namespace_node_resolve_from_aml_namepath(
Expand All @@ -1348,7 +1353,7 @@ static uacpi_status handle_load_table(struct execution_context *ctx)
);
}

param_item = item_array_at(items, 2);
param_item = item_array_at(items, 3);
param_item->obj = param_node->object;
uacpi_object_ref(param_item->obj);
param_item->type = ITEM_OBJECT;
Expand All @@ -1361,6 +1366,7 @@ static uacpi_status handle_load_table(struct execution_context *ctx)
}
uacpi_table_mark_as_loaded(table.index);

item_array_at(items, 2)->immediate = table.index;
method = item_array_at(items, 1)->obj->method;
prepare_table_load(table.hdr, UACPI_TABLE_LOAD_CAUSE_LOAD_TABLE_OP, method);

Expand Down
12 changes: 7 additions & 5 deletions source/opcodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,16 @@ uacpi_u8 uacpi_load_table_op_decode_ops[] = {
// Storage for the scope pointer, this is left as 0 in case of errors
UACPI_PARSE_OP_LOAD_ZERO_IMM,
UACPI_PARSE_OP_OBJECT_ALLOC_TYPED, UACPI_OBJECT_METHOD,
// Index of the table we are going to be loaded to unref it later
UACPI_PARSE_OP_LOAD_ZERO_IMM,
// Storage for the target pointer, this is left as 0 if none was requested
UACPI_PARSE_OP_LOAD_ZERO_IMM,

UACPI_PARSE_OP_LOAD_INLINE_IMM, 1, 5,
UACPI_PARSE_OP_IF_NOT_NULL, 3, 5,
UACPI_PARSE_OP_IF_NOT_NULL, 4, 5,
UACPI_PARSE_OP_STRING,
UACPI_PARSE_OP_IMM_DECREMENT, 3,
UACPI_PARSE_OP_JMP, 7,
UACPI_PARSE_OP_IMM_DECREMENT, 4,
UACPI_PARSE_OP_JMP, 8,
UACPI_PARSE_OP_TERM_ARG_UNWRAP_INTERNAL,

/*
Expand All @@ -182,8 +184,8 @@ uacpi_u8 uacpi_load_table_op_decode_ops[] = {
UACPI_PARSE_OP_INVOKE_HANDLER,

// If we were given a target to store to, do the store
UACPI_PARSE_OP_IF_NOT_NULL, 2, 3,
UACPI_PARSE_OP_STORE_TO_TARGET_INDIRECT, 2, 9,
UACPI_PARSE_OP_IF_NOT_NULL, 3, 3,
UACPI_PARSE_OP_STORE_TO_TARGET_INDIRECT, 3, 10,

UACPI_PARSE_OP_OBJECT_TRANSFER_TO_PREV,
UACPI_PARSE_OP_END,
Expand Down

0 comments on commit 5f518fd

Please sign in to comment.