Module origin::program

source ·
Expand description

Program startup and shutdown.

To use origin’s program startup, define a function named origin_main like this:

/// This function is called by Origin.
///
/// SAFETY: `argc`, `argv`, and `envp` describe incoming program
/// command-line arguments and environment variables.
#[no_mangle]
unsafe fn origin_main(argc: usize, argv: *mut *mut u8, envp: *mut *mut u8) -> i32 {
    todo!("Run the program and return the program exit status.")
}

Origin will call this function after starting up the program and running the constructors. argc is the number of command-line arguments with a value of at most c_int::MAX, and argv is a pointer to a NULL-terminated array of pointers to NUL-terminated C strings. argc and argv describe the command-line arguments. envp is a pointer to a NULL-terminated array of pointers to NUL-terminated C strings containing a key followed by b'=' followed by a value. It describes the environment variables. The function should return a value for the program exit status.

This is a low-level and somewhat C-flavored interface, which is in tension with origin’s goal of providing Rust-idiomatic interfaces, however it does mean that origin can avoid doing any work that users might not need.

Functions§

  • at_exitalloc
    Register a function to be called when exit is called.
  • Call all the functions registered with at_exit or with the .fini_array section, and exit the program.
  • Exit the program without calling functions registered with at_exit or with the .fini_array section.