Open phip1611 opened 10 months ago
I wrote a macro for my own project here feel free to use it. There are examples in the tests
module and documentation in lib.rs
. It does have a couple of quirks and issues, some that can be fixed easily and one which is a huge pain to deal with.
TagName{fields}
will not work, you must use TagName::new(args)
#[repr(align(8))]
, currently some tags need to be padded manually, which is a bit of a pain because of how the macro resolves type names.Multiboot2BasicHeader
doesn't have a public constructor, probably because of the size
argument so the macro must define it's own.rustc
managed to foil all of my attempts to get a truncated pointer. There are ways to work around this, firstly store pointers using *const ()
on 32bit targets. 64bit targets are kinda SOL for this method, the way I'm working around this is just specifying addresses in in a linker script and giving the same address to tag constructors. I did notice that you can get a truncated pointer using inline asm but I'm pretty sure that exploiting this requires writing the entire header in an asm block.I did also consider adding a "native" argument for the architecture to get the macro to resolve the arch itself, but with the huge selection of i386 or MIPS I think the user can handle this themselves.
Thanks @an-owl - that's awesome!
It would be awesome to construct multiboot2-headers at runtime with macros.
For reference: That's how you write a header in assembly language: https://github.com/rust-osdev/multiboot2/blob/main/integration-test/bins/multiboot2_payload/src/multiboot2_header.S