Skip to content

aml: A store into a buffer keeps the buffer's length - #379

Merged
martin-hughes merged 1 commit into
rust-osdev:mainfrom
ogoffart:olivier/store-buffer-length
Nov 17, 2026
Merged

martin-hughes merged 1 commit into
rust-osdev:mainfrom
ogoffart:olivier/store-buffer-length

Conversation

@ogoffart

Copy link
Copy Markdown
Contributor

Storing a buffer into a buffer replaced it, length included. As in ACPICA, the source is now copied into the buffer, which keeps its length: the rest is zeroed, or the source cut. An empty buffer takes the source's length.

Found on a Dell XPS 13 7390, whose _BIF stores each text into a buffer one byte longer, then sets that last byte for its null: it failed with IndexOutOfBounds, and the battery read nothing.

Storing a buffer into a buffer replaced it, length included. As in
ACPICA, the source is now copied into the buffer, which keeps its length:
the rest is zeroed, or the source cut. An empty buffer takes the source's
length.

Found on a Dell XPS 13 7390, whose _BIF stores each text into a buffer one
byte longer, then sets that last byte for its null: it failed with
IndexOutOfBounds, and the battery read nothing.
@martin-hughes

Copy link
Copy Markdown
Contributor

This looks very sensible, thank you again! A couple of questions:

  1. Have you had a chance to check the behaviour Windows and / or uACPI interpreters? I'm away from home so won't be able to do this myself until at least Monday. (I expect Windows will match your PR, given that you're testing with a Dell laptop...)

  2. Have you checked or tested the behaviour of stores to buffers passed as arguments? The spec has this line in it, just under table 19.9: "Direct writes to buffer or package ArgX parameters will also simply overwrite ArgX" which suggests the buffer length would change if it is passed as an argument (possibly with the original buffer remaining unchanged?)


Aside: When you're writing tests, you might be interested to try my testing tool which has 3 choices of interpreter to use built in: this crate, uACPI, and ACPICA. Note that, for now, it uses AML rather than ASL files.

I've also written a Windows driver and tool to help with testing on Windows, but it's currently pretty fiddly to use! (And requires driver test-signing mode turned on, which I think doesn't work with Secure Boot)

@martin-hughes

Copy link
Copy Markdown
Contributor

Apologies it took a few days, I've done a bit of testing now.

tl;dr looks good, thanks!

More writing:

  1. I've tested with Windows, and for the tests you wrote, the behaviour matches 😄
  2. This is where there's a difference compared to the other interpreters.

For the following test:

Name(T12B, Buffer (4) { 0xff, 0xff, 0xff, 0xff })

Method (ABCD) {
    T12I(T12B)
    Return (T12B == Buffer () { 0xff, 0xff, 0xff, 0xff })
}

Method (T12I, 1) {
    Arg0 = Buffer () { 1, 2 }
}

All of ACPICA, uACPI and Windows return Ones from ABCD, whereas from this PR Zero is returned.

Your PR is a clear improvement over what came before, and I'm pretty sure this glitch is orthogonal to what you changed.

Therefore I'm OK with merging - I'll raise a separate issue for question 2.

@martin-hughes
martin-hughes merged commit ce17362 into rust-osdev:main Nov 17, 2026
6 checks passed
@martin-hughes

Copy link
Copy Markdown
Contributor

New issue covering question 2 is #383.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants