Skip to content
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

Implement FromStr / something that allows storing byte slices / yoke for KernelObject #36

Open
n0toose opened this issue Jul 24, 2024 · 1 comment

Comments

@n0toose
Copy link

n0toose commented Jul 24, 2024

Currently, KernelObject could be used like this:

let elf = fs::read(&kernel_path)?;
let object =
	KernelObject::parse(&elf).map_err(...)?;

However, I asked around (after having worked on hermit-os/uhyve#725) as to how I could prevent the "use-after-free" warning that prevented me from storing the object object in the UhyveVm struct - and the problem seems to be that we depend on references that get "destroyed" soon afterwards:

hermit-entry/src/elf.rs

Lines 32 to 35 in 5c87198

/// A parsed kernel object ready for loading.
pub struct KernelObject<'a> {
/// The raw bytes of the parsed ELF file.
elf: &'a [u8],

A potential solution could be implementing something similar to the following trait: https://doc.rust-lang.org/std/str/trait.FromStr.html

@n0toose n0toose changed the title Implement FromStr for KernelObject Implement FromStr / something that allows storing byte slices / yoke for KernelObject Jul 24, 2024
@mkroening
Copy link
Member

This is not yet possible without using raw pointer manually (which we should not do):

We can keep this issue open for the future, but currently there is nothing we can do. I'd suggest keeping only the Vec around and reparsing it if necessary. The overhead should not be too bad.

In Uhyve, parsing ahead of time should also become unnecessary once C applications become relocatable.

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

No branches or pull requests

2 participants