mirror of
https://github.com/Noratrieb/libuwuc.git
synced 2026-01-14 19:55:07 +01:00
c test program
This commit is contained in:
parent
54e0e7604e
commit
1baf8df4a8
18 changed files with 150 additions and 68 deletions
13
rawc/Cargo.toml
Normal file
13
rawc/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "rawc"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib", "rlib"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
libuwuc = { path = "../libuwuc" }
|
||||
25
rawc/src/lib.rs
Normal file
25
rawc/src/lib.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#![no_std]
|
||||
#![feature(panic_info_message)]
|
||||
|
||||
mod stdio;
|
||||
mod string;
|
||||
|
||||
// libcore seems to require this symbol, even though it's unused.
|
||||
#[no_mangle]
|
||||
fn rust_eh_personality() {
|
||||
unsafe {
|
||||
libuwuc::trap!();
|
||||
}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
#[cfg(not(test))]
|
||||
fn handler(arg: &core::panic::PanicInfo) -> ! {
|
||||
let args = format_args!("<no message>");
|
||||
let payload = arg.message().unwrap_or(&args);
|
||||
libuwuc::io::println!("panicked: {payload}");
|
||||
if let Some(loc) = arg.location() {
|
||||
libuwuc::io::println!(" at {}:{}:{}", loc.file(), loc.line(), loc.column());
|
||||
}
|
||||
libuwuc::start::exit(1);
|
||||
}
|
||||
6
rawc/src/stdio.rs
Normal file
6
rawc/src/stdio.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use core::ffi::c_char;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn puts(s: *const c_char) -> i32 {
|
||||
libuwuc::io::puts(s)
|
||||
}
|
||||
25
rawc/src/string.rs
Normal file
25
rawc/src/string.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memset(ptr: *mut u8, constant: u8, len: usize) {
|
||||
libuwuc::mem::memset(ptr, constant, len)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, size: usize) -> *mut u8 {
|
||||
libuwuc::mem::memcpy(dest, src, size)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe fn memcmp(s1: *const u8, s2: *const u8, size: usize) -> i32 {
|
||||
libuwuc::mem::memcmp(s1, s2, size)
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe fn bcmp(s1: *const u8, s2: *const u8, size: usize) -> i32 {
|
||||
libuwuc::mem::memcmp(s1, s2, size)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn strlen(s: *const u8) -> usize {
|
||||
libuwuc::mem::strlen(s)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue