Repository navigation
Improve CopyObject handling. - #382
Conversation
Some relatively small tweaks to match the behaviour defined in the ACPI spec - see https://uefi.org/specs/ACPI/6.6/19_ASL_Reference.html#object-storing-and-copying-rules Tested against uACPI and Windows.
Specifically, CopyObject operations to an ArgX variable that isn't a reference should not be visible to the caller. This was tricky as the `inner` field for an Arg was originally a clone of a `WrappedObject` stored in `MethodContext::args`. Thus, if the pointed-to object is modified, the results are seen in the caller. Also: if the `inner` field of a single Arg ref is rebound to point at a different object (to prevent the caller seeing the result), then the next time the same Arg is referenced by an `Arg` instruction the original `WrappedObject` from the `args` array is cloned, and the result of the `CopyObject` call is essentially lost. The fix is to make the object stored in the `args` array be an `Arg` reference itself, rather than creating a new `Arg` reference when the `Arg` instruction is called. Then all uses of the same argument within a callee function point at the same `inner` `WrappedObject`. At which point, a `CopyObject` operation can simply rebind one `WrappedObject` and have the result be visible in the caller, but not the callee. There are a bunch of new unit tests to validate behaviour here - these were AI-generated to cover most obvious cases.
Rather than expecting `do_copy_object` to deal with the specific rule that Args that don't contain references are rebound before the CopyObject operation, get `unwrap_ref_for_copyobject` to do it. That keeps the logic all in one place and allows improved testability. Also fix the actual tests - references can't be given to logical ops directly.
| operand.to_integer(self.integer_size)? | ||
| } | ||
| _ => Err(AmlError::ObjectNotOfExpectedType { expected: ObjectType::Integer, got: operand.typ() })? | ||
| Object::Integer(operand) => *operand, |
There was a problem hiding this comment.
This is a formatting change that seems to have been missed previously
| } | ||
| Object::FieldUnit(ref field_unit) => self.do_field_write(field_unit, object.clone())?, | ||
| _ => { | ||
| // TODO: This is definitively *unsound* if dst and object are one and the same... |
There was a problem hiding this comment.
I've put this as TODO, but I actually don't think it's a bit deal - I'd be very surprised if any Rust implementation did something stupid here.
|
During some playing I noticed that CopyObject to a "plain" Arg (i.e. one not containing a reference) wasn't working properly - within the callee function, the Arg essentially didn't store the copied object. As such, I've changed I think this commit message explains why, but do ask if you want a bit more info: Notes on testing: the ASL tests were tested against the Windows interpreter. The unit tests were LLM-generated to cover all the obvious cases. There's also a formatting change in this PR that snuck into the @IsaacWoods would you mind taking a look? |
|
Thanks @martin-hughes! This looks very sensible to me (albeit not with any further testing by myself), and handling arg references like this is definitely a little cleaner. |
Some relatively small tweaks to match the behaviour defined in the ACPI spec - see
https://uefi.org/specs/ACPI/6.6/19_ASL_Reference.html#object-storing-and-copying-rules
Tested against uACPI and Windows.
I'd like to add a few more tests, but @IsaacWoods would you take a look for any obvious holes? No rush, just when you have a chance