Skip to content

Commit c929f7d

Browse files
authored
Minor cleanups. (#144)
1 parent 22ec7fc commit c929f7d

File tree

9 files changed

+22
-10
lines changed

9 files changed

+22
-10
lines changed

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ smallvec = { version = "1.11.1", optional = true, features = ["const_new"] }
2828
# before `origin_main` is called.
2929

3030
# Enable `env_logger`; eg. recognizing `RUST_LOG=trace`. This requires `std`.
31-
env_logger = { version = "0.11.0", optional = true, default-features = false }
31+
env_logger = { version = "0.11.0", default-features = false, optional = true }
3232

3333
# Enable `atomic-dbg`'s simple logger. This doesn't require `std`.
3434
atomic-dbg = { version = "0.1", default-features = false, optional = true }
@@ -168,7 +168,10 @@ panic-handler = ["unwinding?/panic-handler"]
168168
# if you know your program will never panic and don't want any extra code.
169169
panic-handler-abort = ["unwinding?/panic-handler-dummy"]
170170

171-
# Enable this to define the `getauxval` function.
171+
# Enable this to define a C ABI-compatible `getauxval` function. Most Rust code
172+
# should use functions in [`rustix::param`] instead.
173+
#
174+
# [`rustix::param`]: https://docs.rs/rustix/latest/rustix/param/index.html
172175
getauxval = ["rustix/param"]
173176

174177
# Enable features which depend on Rust's std.

src/mem/fast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! `memcpy` etc. implementations with performance optimizations.
2+
//!
13
//! The following is derived from src/mem/mod.rs in Rust's
24
//! [compiler_builtins library] at revision
35
//! cb060052ab7e4bad408c85d44be7e60096e93e38.

src/mem/small.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//! `memcpy` etc. implementations with small code size.
2+
//!
3+
//! This code uses `core::arch::asm!("")` to try to discourage optimizers from
4+
//! vectorizing or pattern-matching these loops.
5+
16
#[cfg(not(feature = "nightly"))]
27
use crate::ptr::Polyfill as _;
38
use core::ffi::{c_char, c_int, c_void};

src/program/linux_raw.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ pub(super) unsafe extern "C" fn entry(mem: *mut usize) -> ! {
119119
static __init_array_end: c_void;
120120
}
121121

122-
// Call the `.init_array` functions. As GLIBC does, pass argc, argv,
123-
// and envp as extra arguments. In addition to GLIBC ABI compatibility,
122+
// Call the `.init_array` functions. As glibc does, pass argc, argv,
123+
// and envp as extra arguments. In addition to glibc ABI compatibility,
124124
// c-scape relies on this.
125-
type InitFn = extern "C" fn(c_int, *mut *mut u8, *mut *mut u8);
125+
type InitFn = unsafe extern "C" fn(c_int, *mut *mut u8, *mut *mut u8);
126126
let mut init = core::ptr::addr_of!(__init_array_start).cast::<InitFn>();
127127
let init_end = core::ptr::addr_of!(__init_array_end).cast::<InitFn>();
128128
// Prevent the optimizer from optimizing the `!=` comparison to true;

src/relocate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ macro_rules! debug_assert_eq {
7676
/// In practice, things work if we don't make any calls to functions outside
7777
/// of this crate, not counting functions directly implemented by the compiler.
7878
/// So we can do eg. `x == null()` but we can't do `x.is_null()`, because
79-
/// `null` is directly implemented by the compiler, while `is_null` is not.
79+
/// `null` is directly implemented by the compiler, while `is_null` is not 🙃.
8080
///
8181
/// We do all the relocation memory accesses using `asm`, as they happen
8282
/// outside the Rust memory model. They read and write and `mprotect` memory

src/thread/libc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ pub unsafe fn create(
109109
stack_size: usize,
110110
guard_size: usize,
111111
) -> io::Result<Thread> {
112+
// This should really be an `unsafe` function, but `libc::pthread_create`
113+
// doesn't have `unsafe` in its signature.
112114
extern "C" fn start(thread_arg_ptr: *mut c_void) -> *mut c_void {
113115
unsafe {
114116
// Unpack the thread arguments.
@@ -213,7 +215,7 @@ pub unsafe fn join(thread: Thread) -> Option<NonNull<c_void>> {
213215
/// Registers a function to call when the current thread exits.
214216
#[cfg(feature = "thread-at-exit")]
215217
pub fn at_exit(func: Box<dyn FnOnce()>) {
216-
extern "C" fn call(arg: *mut c_void) {
218+
unsafe extern "C" fn call(arg: *mut c_void) {
217219
unsafe {
218220
let arg = arg.cast::<Box<dyn FnOnce()>>();
219221
let arg = Box::from_raw(arg);

src/thread/linux_raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub(super) unsafe fn initialize_main(mem: *mut c_void) {
339339
// the effective stack size. Linux sets up inaccessible memory at the end
340340
// of the stack.
341341
let stack_map_size = getrlimit(Resource::Stack).current.unwrap() as usize;
342-
let stack_least = stack_base.cast::<u8>().sub(stack_map_size);
342+
let stack_least = stack_base.sub(stack_map_size);
343343
let stack_size = stack_least.offset_from(mem.cast::<u8>()) as usize;
344344
let guard_size = page_size();
345345

test-crates/origin-start/src/bin/canary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
extern crate alloc;
88

9-
use core::cell::UnsafeCell;
109
use core::arch::asm;
10+
use core::cell::UnsafeCell;
1111
use origin::{program, thread};
1212

1313
#[global_allocator]

test-crates/origin-start/src/bin/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
extern crate alloc;
1010

1111
use alloc::boxed::Box;
12-
use core::cell::UnsafeCell;
1312
use core::arch::asm;
13+
use core::cell::UnsafeCell;
1414
use core::ptr::{addr_of_mut, without_provenance_mut};
1515
use origin::{program, thread};
1616

0 commit comments

Comments
 (0)