这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@SimonSapin
Copy link
Contributor

@SimonSapin SimonSapin commented Jun 29, 2022

This involves breaking API changes:

  • The lifetime parameter of FwCfgFile was removed. Having files own the buffer for their name makes iter_files easier (which would otherwise need scratch space for names or something like that).
  • FwCfg methods were changed to take &mut self since they rely on a global shared resource. (For example interleaving two iterations would give incorrect results.)

The fw_cfg device is a shared resource: there’s only one per QEMU guest.
And it is stateful: when happens when accessing an I/O port depends
on previous accesses.
This means that concurrent access would behave incorectly
(though probably not cause memory unsafety, as long as DMA is not used).

To fix this, require of users (through `unsafe fn new`) to only have
one `FwCfg` value at a time, and change methods to take `&mut self`
instead of `&self`.

This is a breaking API change, update the version number accordingly.
The name string is now kept in a byte buffer inside `FwCfgFile`
instead of externally and referenced through that lifetime.

Upside:

* Manipulating values of this type is now more flexible,
  since we don’t need to manage name string buffers separately.

Downsides:

* The type is bigger: from 16 bytes on 32-bit targets to 64 bytes
* Calling `.name()` repeatedly will iterate bytes repeatedly
  to find the null terminator,
  instead of only once was `FwCfgFile` is first created.
@lion328 lion328 merged commit 4ea0360 into lion328:master Jul 16, 2022
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