• Stars
    star
    166
  • Rank 227,748 (Top 5 %)
  • Language
    Rust
  • License
    Other
  • Created over 1 year ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Program startup and thread support written in Rust

Origin

Program and thread startup and shutdown in Rust

Github Actions CI Status zulip chat crates.io page docs.rs docs

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 Mustang and Eyra in their libc implementations, and in the Origin Studio project in its std implementation, which are three different ways to support building Rust programs written entirely in Rust.

Example crates

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. Origin handles program and thread startup and shutdown and no part of libc is used. This is the approach that Origin Studio uses.

  • The origin-start-no-alloc example is like origin-start, but disables the "alloc" and "thread" features, since Origin's "thread" feature currently depends on "alloc". Without "alloc", functions that return owned strings or Vecs are not available. In this mode, Origin avoids using a global allocator entirely.

  • The origin-start-lto example is like origin-start, but builds with LTO.

  • The tiny example is like origin-start, but builds with optimization flags, disables features, and adds an objcopy trick to produce a very small binaryโ€”408 bytes on x86-64!

Fully static linking

The resulting executables in the origin-start, origin-start-no-alloc, and origin-start-lto examples don't depend on any dynamic libraries, however by default they do still depend on a dynamic linker.

For fully static linking, there are two options:

  • Build with RUSTFLAGS=-C target-feature=+crt-static -C relocation-model=static. This disables PIE mode, which is safer in terms of Origin's code, but loses the security benefits of Address-Space Layout Randomization (ASLR).

  • Build with RUSTFLAGS=-C target-feature=+crt-static and enable Origin's experimental-relocate feature. This allows PIE mode to work, however it does so by enabling some experimental code in Origin for performing relocations.

More Repositories

1

mustang

Rust programs written entirely in Rust
Rust
828
star
2

eyra

Rust programs written entirely in Rust
Rust
765
star
3

wasm-reference-manual

WebAssembly Reference Manual
564
star
4

c-ward

An implementation of libc written in Rust
Rust
199
star
5

io-lifetimes

A low-level I/O ownership and borrowing library
Rust
94
star
6

hello-world-vs-io-errors

A repository about "Hello, World" programs and I/O errors
62
star
7

hello-wasi-http

Rust
57
star
8

nameless

Full-service command-line parsing
Rust
52
star
9

is-terminal

Test whether a given stream is a terminal
Rust
49
star
10

linux-raw-sys

Generated bindings for Linux's userspace API
Rust
39
star
11

llvm2cranelift

LLVM IR to Cranelift IR translator
Rust
30
star
12

origin-studio

An alternative `std`-like implementation built on origin
Rust
24
star
13

io-streams

Unbuffered and unlocked I/O streams
Rust
24
star
14

world-of-wasi-demo

A demo for my talk The World of WASI
Rust
21
star
15

hello-embedded

Hello Embedded!
Rust
21
star
16

io-extras

Non-owning unsafe I/O
Rust
20
star
17

ambient-authority

Ambient Authority
Rust
19
star
18

duplex

The Duplex trait: interactive streams
Rust
17
star
19

atomic-dbg

Atomic `dbg`/`eprintln`/`eprint` macros
Rust
17
star
20

eyra-c

Support for compiling C programs with Eyra
Rust
13
star
21

socketpair

Cross-platform socketpair functionality
Rust
10
star
22

office-hours

Open office hours
10
star
23

wasm-collection

A collection of miscellaenous valid wasm modules
8
star
24

mir2cranelift

Rust MIR to Cranelift IL translator (inactive; soon to be replaced)
Rust
8
star
25

rustix-futex-sync

Linux futex-based synchronization
Rust
8
star
26

utf8-io

Traits and types for UTF-8 I/O
Rust
6
star
27

io-arrays

Random-access I/O
Rust
6
star
28

basic-text

Basic Text strings and I/O streams
Rust
5
star
29

rustix-openpty

Rust
5
star
30

open-ambient

Open files and directories with constant paths
Rust
4
star
31

winx

A collection of miscellaneous Windows API utilities
Rust
4
star
32

linux-mount-api-documentation

Formatted copies of the Linux mount API manual page drafts
3
star
33

rustix-linux-procfs

Utilities for opening Linux procfs files and directories
Rust
3
star
34

terminal-io

Utilities for reading and writing on terminals
Rust
3
star
35

rustix-is-terminal

Test whether a given stream is a terminal, using rustix
Rust
2
star
36

dir-view

Views of cap-std's Dir
Rust
2
star
37

rustix-testing

Extra testing for rustix
Rust
2
star
38

cap-std-testing

Extra testing for cap-std
Rust
2
star
39

rustix-bench

Rust
2
star
40

char-device

Character Device I/O
Rust
2
star
41

nuttx-sys

Raw bindings to NuttX APIs
Rust
2
star
42

wasi-filesystem.wit

1
star
43

wasi-preview2

WASI Preview2 Proposal
1
star
44

intercomm

experiments in passing handles to std::process::Command
Rust
1
star
45

wasi-filesystem-presentation

1
star
46

codeexpr

Rust
1
star
47

windows-hello

Rust
1
star
48

wasi-random-presentation

Rust
1
star
49

layered-io

I/O traits extending Read and Write
Rust
1
star
50

annotated-types

An experiment which may turn into a WASI proposal
1
star
51

wasi-common-test

Rust
1
star
52

import-export-demo

Rust
1
star
53

sunfishcode.github.io

HTML
1
star
54

wasi-wiki

A Wiki for WASI designs
1
star