c1b8c3b4cf
- abort() body: use signal::sys::SIGABRT (the platform-independent name
the signal module uses for both linux and redox submodules)
- call sites: wrap abort() in unsafe { } blocks (Rust 2024 edition's
unsafe_op_in_unsafe_fn lint makes this mandatory inside unsafe fns)
- stdlib/mod.rs, start.rs: drop now-unused 'intrinsics' import
118 lines
2.6 KiB
Rust
118 lines
2.6 KiB
Rust
//! POSIX C library, implemented in Rust.
|
|
//!
|
|
//! This crate exists to provide a standard libc as its public API. This is
|
|
//! largely provided by automatically generated bindings to the functions and
|
|
//! data structures in the [`header`] module.
|
|
//!
|
|
//! Currently, Linux and Redox syscall backends are supported.
|
|
|
|
#![no_std]
|
|
#![feature(alloc_error_handler)]
|
|
#![feature(allocator_api)]
|
|
#![feature(c_variadic)]
|
|
#![feature(core_intrinsics)]
|
|
#![feature(macro_derive)]
|
|
#![feature(maybe_uninit_slice)]
|
|
#![feature(lang_items)]
|
|
#![feature(linkage)]
|
|
#![feature(pointer_is_aligned_to)]
|
|
#![feature(ptr_as_uninit)]
|
|
#![feature(slice_ptr_get)]
|
|
#![feature(stmt_expr_attributes)]
|
|
#![feature(sync_unsafe_cell)]
|
|
#![feature(thread_local)]
|
|
#![feature(vec_into_raw_parts)]
|
|
#![feature(negative_impls)]
|
|
|
|
#[macro_use]
|
|
extern crate alloc;
|
|
extern crate cbitset;
|
|
extern crate memchr;
|
|
extern crate posix_regex;
|
|
extern crate rand;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
#[macro_use]
|
|
extern crate sc;
|
|
|
|
#[cfg(target_os = "redox")]
|
|
extern crate syscall;
|
|
|
|
#[macro_use]
|
|
mod macros;
|
|
pub mod c_str;
|
|
pub mod c_vec;
|
|
pub mod cxa;
|
|
pub mod db;
|
|
pub mod error;
|
|
pub mod fs;
|
|
pub mod header;
|
|
pub mod io;
|
|
pub mod iter;
|
|
pub mod ld_so;
|
|
pub mod out;
|
|
pub mod platform;
|
|
pub mod pthread;
|
|
pub mod raw_cell;
|
|
pub mod start;
|
|
pub mod sync;
|
|
|
|
use crate::platform::{Allocator, NEWALLOCATOR};
|
|
|
|
#[global_allocator]
|
|
static ALLOCATOR: Allocator = NEWALLOCATOR;
|
|
|
|
#[unsafe(no_mangle)]
|
|
pub extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! {
|
|
use core::fmt::Write;
|
|
|
|
let mut w = platform::FileWriter::new(2);
|
|
let _ = w.write_fmt(format_args!("RELIBC PANIC: {}\n", pi));
|
|
|
|
unsafe { crate::header::stdlib::abort() };
|
|
}
|
|
|
|
#[cfg(not(test))]
|
|
#[panic_handler]
|
|
#[linkage = "weak"]
|
|
pub fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
|
|
relibc_panic(pi)
|
|
}
|
|
|
|
#[cfg(not(test))]
|
|
#[lang = "eh_personality"]
|
|
#[linkage = "weak"]
|
|
pub extern "C" fn rust_eh_personality() {}
|
|
|
|
#[cfg(not(test))]
|
|
#[alloc_error_handler]
|
|
#[linkage = "weak"]
|
|
#[allow(improper_ctypes_definitions)]
|
|
#[unsafe(no_mangle)]
|
|
pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! {
|
|
// Layout not FFI-safe?
|
|
use core::fmt::Write;
|
|
|
|
let mut w = platform::FileWriter::new(2);
|
|
let _ = w.write_fmt(format_args!(
|
|
"RELIBC OOM: {} bytes aligned to {} bytes\n",
|
|
layout.size(),
|
|
layout.align()
|
|
));
|
|
|
|
unsafe { crate::header::stdlib::abort() };
|
|
}
|
|
|
|
#[cfg(not(test))]
|
|
#[allow(non_snake_case)]
|
|
#[linkage = "weak"]
|
|
#[unsafe(no_mangle)]
|
|
pub extern "C" fn _Unwind_Resume() -> ! {
|
|
use core::fmt::Write;
|
|
|
|
let mut w = platform::FileWriter::new(2);
|
|
let _ = w.write_str("_Unwind_Resume\n");
|
|
|
|
unsafe { crate::header::stdlib::abort() };
|
|
}
|