bjorn3 opened Issue #1856:
object::elf
export type definitions for all important structs used here. You can useobject::pod::from_bytes
andobject::pos::bytes_of
to convert between a slice and these structs. Afrom_bytes_mut
method would be useful for this though. You should be able to create one by adaptingfrom_bytes
._Originally posted by @bjorn3 in https://github.com/bytecodealliance/wasmtime/pull/1848_
yurydelendik commented on Issue #1856:
I created #1860 to partially address the issue. Though I had a little success with the object v0.19's pod API to refactor convert_object_elf_to_loadable_file. There are gaps in this API to make it simple.
philipc commented on Issue #1856:
@yurydelendik What is missing besides
from_bytes_mut
? Some of what you have done can be simplified already. For example:- let header: &FileHeader64<LittleEndian> = - unsafe { &*(bytes.as_mut_ptr() as *const FileHeader64<_>) }; + let header = from_bytes::<FileHeader64<LittleEndian>>(&bytes).unwrap().0;
I thought about adding a
&mut [u8]
equivalent ofBytes
, but I think it would be unusable with rust's borrowing rules.
philipc edited a comment on Issue #1856:
@yurydelendik What is missing besides
from_bytes_mut
? Some of what you have done can be simplified already. For example:- let header: &FileHeader64<LittleEndian> = - unsafe { &*(bytes.as_mut_ptr() as *const FileHeader64<_>) }; + let header = from_bytes::<FileHeader64<LittleEndian>>(&bytes).unwrap().0;
(Note that this is for the use that doesn't need to be mutable.)
I thought about adding a
&mut [u8]
equivalent ofBytes
, but I think it would be unusable with rust's borrowing rules.
yurydelendik commented on Issue #1856:
Yes, the immutable/reading part worked. Once I started patching, it all felt apart (including borrowing rules you mentioned).
bjorn3 commented on Issue #1856:
I think this is fixed since #1860.
bjorn3 closed Issue #1856:
object::elf
export type definitions for all important structs used here. You can useobject::pod::from_bytes
andobject::pos::bytes_of
to convert between a slice and these structs. Afrom_bytes_mut
method would be useful for this though. You should be able to create one by adaptingfrom_bytes
._Originally posted by @bjorn3 in https://github.com/bytecodealliance/wasmtime/pull/1848_
Last updated: Dec 23 2024 at 13:07 UTC