Skip to content

Handle application initialisation #4

@tsoutsman

Description

@tsoutsman

This should be trivial to do (once libtheseus is sorted out).

We can define a function in std::sys::theseus as follows:

pub unsafe fn __theseus_start(args: Vec<String>) -> isize {
    let argc = args.len();
    let argv = args.as_ptr();

    extern "C" {
        // This function is exported by Rust (and all other language) binaries.
        fn main(argc: isize, argv: *const *const c_char) -> i32;
    }
    
    // Do initialisation.
    let result = unsafe { main(argc as size, argv) };
    // Do cleanup.
    result as isize
}

* This code is untested.

To run a crate we would then run __theseus_start similar to how we currently run main functions exported by applications. The process of finding the section and transmuting it to a function pointer would remain the same.

Hermit does a slightly similar thing.

I believe std::sys::theseus::init is called by the main function exported by binaries. E.g. Hermit's runtime_entry function doesn't initialise the network because it's done in init, which will be called by main.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🛑 Blocked

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions