Origin implements program startup and shutdown, as well as thread startup and shutdown, for Linux, implemented in Rust.
Program startup and shutdown for Linux is traditionally implemented in crt1.o,
and the libc functions exit
, atexit
, and _exit
. And thread startup and
shutdown are traditionally implemented in libpthread functions
pthread_create
, pthread_join
, pthread_detach
, and so on. Origin provides
its own implementations of this functionality, written in Rust.
For a C-ABI-compatible interface to this functionality, see [c-scape].
This is used by the [Mustang] project in its libc implementation, and in the [origin-studio] project in its std implementation, which are two different ways to support building Rust programs written entirely in Rust.
Origin can also be used on its own, in several different configurations:
The [basic example] shows a simple example of using origin as a simple library. In this configuration, libc is doing most of the work.
The [no-std example] uses no_std
and starts the program using Rust's
#[start]
feature, and then hands control to origin. libc is still
doing most of the work here.
The [external-start example] uses no_std
and no_main
, and starts the
program by taking over control from libc as soon as possible, and then
hands control to origin. origin handles program and thread startup and
shutdown once it takes control.
The [origin-start example] uses no_std
and no_main
, and lets origin
start the program using its own program entrypoint. This version must be
compiled with an explicit --target=
flag, even if it's the same as the
host, because it uses special RUSTFLAGS, and an explicit --target
flag
prevents those flags from being passed to build scripts. origin handles
program and thread startup and shutdown and no part of libc is used.
The [origin-start-no-alloc example] is like origin-start, but disables the "alloc" and "thread" features, so that it doesn't need to pull in a global allocator.