-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stub: load companions #306
base: master
Are you sure you want to change the base?
Conversation
9ffa3ba
to
5f00edb
Compare
Signed-off-by: Raito Bezarius <[email protected]>
As soon as we open in exclusive our own image, we will not be able easily to re-open it because of the locking mechanism. Therefore, we should use the opportunity to get information we may be interested in and avoid us re-opening the loaded image protocol. This is useful to know from where you were loaded for example, e.g. filesystem path.
This comment was marked as outdated.
This comment was marked as outdated.
0f463e4
to
a47f0c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks fine, didn't look into it in too in depth because it's new functionality. I'll defer the final review to @blitz.
rust/uefi/stub/src/thin.rs
Outdated
|
||
/// Compute the necessary padding based on the provided length | ||
/// It returns None if no padding is necessary. | ||
fn compute_pad4(len: usize) -> Option<Vec<u8>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs some more context, for example why is it called pad4
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it could just return Vec<u8>
, because this can already represent not having to add padding by returning an empty vector and thus simplifying calling code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done for returning just a Vec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code has lots of panics. Is it possible to have warnings instead and return Err
?
Feel free to ignore the code suggestions, if they don't make sense to you or result in too much refactoring.
) -> uefi::Result<Vec<PathBuf>> { | ||
let mut results = Vec::new(); | ||
|
||
for maybe_entry in fs.read_dir(search_path).unwrap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this propagate the error instead of panicking?
nit: This would be easier to read as read_dir().iter().filter().map().collect()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So re-encoding the FileSystemError into uefi::Result
is quite difficult because the enum is Io, Path or Utf8Encoding and it's probably going to be very unhelpful to eat the low level errors into high level errors that will produce difficult to debug code IMHO. A better solution would be to have ways to propagate the original error up but there's impedence mismatch with our error management here.
let mut credentials_measured = 0; | ||
let mut sysext_measured = false; | ||
|
||
for initrd in companions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: If you filter the irrelevant initds from the vector before iterating, you can simplify this a bit. measurements
doesn't have to be imperatively computed, but is then just relevant_initrds.len()
. Might not be worth it, but maybe there is a way to make this function less C-like and remove the mutable state for easier reading.
rust/uefi/stub/src/thin.rs
Outdated
|
||
/// Compute the necessary padding based on the provided length | ||
/// It returns None if no padding is necessary. | ||
fn compute_pad4(len: usize) -> Option<Vec<u8>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it could just return Vec<u8>
, because this can already represent not having to add padding by returning an empty vector and thus simplifying calling code.
- implements discovery of companions - implements a thin wrapper on the top of `pio` for our packing operations - implements measurements operations on the new entities in this PR
And offer a way to debug CPIO representations just with your eyes, Here's a useful snippet to transform that representation into a proper binary CPIO using Python: >>> raw = "<insert the string representation with the proper escaping>" >>> open("/tmp/cpio", "wb").write(bytes(raw.replace("\\x00", "\x00"), "ascii")) Then, you can poke the cpio using `cpio -t < /tmp/cpio` or extract it and `cpio` should complain accordingly.
Signed-off-by: Raito Bezarius <[email protected]>
And do not panic upon them. Signed-off-by: Raito Bezarius <[email protected]>
Make the stub even more graceful than ever. Signed-off-by: Raito Bezarius <[email protected]>
0f463e4
to
507adab
Compare
And add a warning. Signed-off-by: Raito Bezarius <[email protected]>
Hopefully, compiler optimizations will avoid the vector allocation path for already-aligned buffers. Signed-off-by: Raito Bezarius <[email protected]>
This makes use of the pio library to discover, charge, measures companions.
Depends on the dynamic initrds PR: #305.