Sync computers
This commit is contained in:
54
crates/std/src/prelude.rs
Normal file
54
crates/std/src/prelude.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
pub mod rust_2024 {
|
||||
pub use crate::print;
|
||||
pub use crate::println;
|
||||
pub use alloc::borrow::ToOwned;
|
||||
pub use alloc::format;
|
||||
pub use alloc::string::String;
|
||||
pub use alloc::vec;
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
struct GlobalAllocator;
|
||||
|
||||
#[core::prelude::v1::global_allocator]
|
||||
static GLOBAL_ALLOCATOR: GlobalAllocator = GlobalAllocator;
|
||||
|
||||
unsafe impl core::alloc::GlobalAlloc for GlobalAllocator {
|
||||
unsafe fn alloc(&self, layout: core::alloc::Layout) -> *mut u8 {
|
||||
crate::syscall::alloc(layout)
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: core::alloc::Layout) {
|
||||
crate::syscall::dealloc(ptr, layout)
|
||||
}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_panic_info: &core::panic::PanicInfo) -> ! {
|
||||
// TODO print
|
||||
loop {}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// `argc` and `argv` are passed by the kernel
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn _start(argc: isize, argv: *const *const u8) -> isize {
|
||||
unsafe extern "Rust" {
|
||||
fn main(argc: isize, argv: *const *const u8) -> isize;
|
||||
}
|
||||
|
||||
unsafe { main(argc, argv) }
|
||||
}
|
||||
|
||||
#[lang = "start"]
|
||||
pub fn lang_start<T: crate::process::Termination + 'static>(
|
||||
main: fn() -> T,
|
||||
argc: isize,
|
||||
argv: *const *const u8,
|
||||
_sigpipe: u8,
|
||||
) -> isize {
|
||||
println!("{}", argc);
|
||||
println!("{:?}", argv);
|
||||
main().report().to_isize()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user