Hello everyone, I would like to propose changing the function signature of the lang_start
function from:
fn lang_start<T: crate::process::Termination + 'static>(main: fn() -> T, argc: isize, argv: *const *const u8) -> size;
To
fn lang_start<T: crate::process::Termination + 'static>(main: fn() -> T, argc: isize, argv: *const *const core::ffi::c_void) -> size;
Rational:
I am trying to port Rust std to UEFI targets. During this endeavor, I wanted to allow the users to use the normal main
function rather than using no_main
feature.
However, this posed a few problems. Firstly, the efi entry point function has a function signature completely different from C main
or Rust lang_start
:
type SystemHandle = *mut c_void;
type Status = u32;
fn(_: SystemHandle, _: *mut SystemTable) -> Status;
I came up with a bit of a hack to make everything play nicely for now. The hack basically looks like this:
extern "C" main(argc: isize, argv: *const *const i8) -> isize;
fn efi_main(sh: SystemHandle, st: *mut SystemTable) -> Status {
// Do not run. The actual code is a bit different. This is just to give a general idea about what I am doing.
let argv = [sh, st as *mut i8].as_ptr();
main(2, argv)
}
As most people will be aware the rustc
automatically generates the C main
for us, so I am just hooking into it. It is a bit of a roundabout way, but I wasn't sure how I could avoid the C trip (or if I even should) so I have left it for now.
As you can see through, while this works (and I can access the SystemTable pointer from sys::int()
, it would make much more sense to cast to c_void
pointers instead of i8
pointers.
Since Rust targets a lot of embedded systems and environments where arguments aren't or can't be passed, wouldn't it make more sense to not use a c_void
pointer in the signature instead? Functionally, it shouldn't change a whole lot since a manual casting will be needed in the init
or any other function where the platform does its initialization. However, having c_void
will make it more clear that expected arguments can be things other than CLI arguments.
There, is an issue open which might allow avoiding the whole trip to C that I am currently taking, so having a void signature will make even more sense then.