Make AML interpreter storage allocator-api compatible#306
Conversation
Fix: Add allocator to registers across 2 files. ### Changes - [`src/lib.rs`] Support `aml` feature: Enable the `aml` feature in the library - [`src/platform/mod.rs`] Add allocator to registers: Use the provided `allocator` for `registers` to avoid potential memory issues ### Version Bumps - [`Cargo.toml`] Rust / Cargo: 6.1.1 -> 6.1.2 (patch); code changes detected; suggest a patch project version bump ### Risk - Level: low
### Changes - [`src/platform/numa.rs`] Use &AcpiTables: Allow passing `AcpiTables` as a reference to the `new` method ### Risk - Level: low
This commit introduces `AmlString` for string handling and parses `_SI` within the `namespace` to improve string manipulation capabilities. ### Changes - [`src/aml/mod.rs`] Use AmlString for string handling: Introduce `AmlString` for safer string handling and improve error reporting - [`src/aml/namespace.rs`] Parse `_SI` in namespace: Allow parsing of `_SI` in namespaces using `AmlName::parse_in` for improved flexibility - [`src/aml/mod.rs`] Implement push method in AmlString: Add `push` method to `AmlString` to support allocator-parameterized string manipulation - [`src/aml/mod.rs`] Use Allocator for generic resource handling: Update `PciRouteType` to use `Allocator` for generic resource handling - [`src/lib.rs`] Enable allocator features: Enable `btreemap_alloc` and `allocator_api` for better memory management - [`tests/bank_fields.rs`] Update test infrastructure and files - [`tools/aml_test_tools/src/handlers/check_cmd_handler.rs`] Use Global allocator for interpreter: Use the global allocator for the interpreter to improve performance and avoid allocation issues ### Version Bumps - [`Cargo.toml`] Rust / Cargo: 6.1.2 -> 6.2.0 (minor); manifest changed without an explicit project version bump; suggest minor bump - [`tools/aml_test_tools/Cargo.toml`] Rust / Cargo: 0.1.0 -> 0.2.0 (minor); code changes detected; suggest a minor project version bump ### Risk - Level: low - No security risks are introduced by using `AmlString` and parsing `_SI`.
This commit introduces `MethodContext` to provide method arguments, improving code clarity and maintainability. ### Changes - [`src/aml/mod.rs`] Use MethodContext for method arguments: Use `MethodContext` to correctly pass method arguments to the interpreter - [`src/platform/interrupt.rs`] Add `hw_id` to Gic struct - [`tests/bank_fields.rs`] Update imports: Refactor imports to align with updated dependencies and improve code clarity - [`tools/aml_test_tools/src/handlers/check_cmd_handler.rs`] Prevent null check when handler is null: Ensure the `check_cmd_handler` function doesn't panic when passed a null handler ### Risk - Level: low - No new security risks introduced. - No data loss or corruption is expected.
…sourceDescriptor Update formatting of `AmlString` and add IRQ information to `ResourceDescriptor` in `aml` module ### Changes - [`src/aml/mod.rs`] Update AmlString formatting: Change `AmlString` to use `A: Allocator + Clone` for formatting, improving flexibility and avoiding dynamic context info loss - [`src/aml/resource.rs`] Add IRQ information to ResourceDescriptor - [`src/lib.rs`] Remove unused comment: Remove a comment that discusses unused code and potential future changes ### Version Bumps - [`Cargo.toml`] Rust / Cargo: 6.2.0 -> 6.2.1 (patch); manifest changed without an explicit project version bump; suggest patch bump ### Risk - Level: low - No security implications. - Formatting changes are for code consistency. - IRQ information is for debugging and monitoring purposes.
# Conflicts: # src/aml/mod.rs # src/aml/object.rs # src/aml/resource.rs # tools/aml_test_tools/src/lib.rs
|
Nice one @SnowCheetos - I hope you and @IsaacWoods won't mind me jumping in with a few thoughts? Lots of words here - I don't mean to detract from your work. It is definitely worthy of more discussion! Big thoughts:
Smaller thoughts:
Obviously this is Isaac's crate so hopefully none of that is out of line! |
### Changes - [`.gitignore`] Add `.DS_Store` and .rs.bk to: Exclude unnecessary files from Git tracking - [`src/aml/mod.rs`] Use Global allocator for Interpreter: Change `Interpreter`'s default allocator to `Global` for better portability and performance ### Risk - Level: low - No immediate risk identified. - Global allocator usage is generally safe. - Potential for increased memory usage if not managed carefully.
Thanks for the feedback. Fully agreed on the global allocator default, I made a patch that ensures both My bad on the confusing commit messages, I use autocommit for essentially 100% of my commits (I was notoriously bad at writing commit messages manually and didn't want to waste AI tokens on such a simple task...), sometimes they can be a bit... wrong, to say the least. Also agreed that this is quite massive of a PR, happy to break it down into smaller pieces to make it easier for reviews if needed. |
Summary
This ports the AML interpreter and related AML data structures to support allocator-aware storage.
The main change is threading an allocator through AML-owned objects and namespace structures so callers can use allocator-backed
Vec,Arc,BTreeMap, and string storage instead of relying on global allocation in the interpreter core. It also applies a patch for #305Changes
AmlString<A>.*_inconstructors where AML structures need an explicit allocator.aml_tester,aml_test_tools, anduacpi_test_adapterbuild together.acquire_global_locknow reacquires global_lock_mutex before retrying after firmware contention.release_global_locknow releases global_lock_mutex, balancing the acquire path.tests/global_lock.rsto assert acquire/release balances handler mutex calls.Notes