Skip to content

Commit

Permalink
More standard library functions (#784)
Browse files Browse the repository at this point in the history
More standard library functions for sproll.

Works with scroll-tech/sproll-evm#65
  • Loading branch information
matthiasgoergens authored Dec 29, 2024
1 parent f1de609 commit 97237a1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ceno_rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ repository = "https://github.com/scroll-tech/ceno"
version = "0.1.0"

[dependencies]
getrandom = { version = "*", features = ["custom"], default-features = false }
rkyv = { version = "0.8", features = ["pointer_width_32"] }
25 changes: 25 additions & 0 deletions ceno_rt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(clippy::cargo)]
#![feature(strict_overflow_ops)]
#![feature(linkage)]
use getrandom::{Error, register_custom_getrandom};

#[cfg(target_arch = "riscv32")]
use core::arch::{asm, global_asm};
Expand All @@ -23,6 +24,18 @@ pub extern "C" fn sys_write(_fd: i32, _buf: *const u8, _count: usize) -> isize {
unimplemented!();
}

#[no_mangle]
#[linkage = "weak"]
pub extern "C" fn sys_alloc_words(_nwords: usize) -> *mut u32 {
unimplemented!();
}

#[no_mangle]
#[linkage = "weak"]
pub extern "C" fn sys_getenv(_name: *const u8) -> *const u8 {
unimplemented!();
}

/// Generates random bytes.
///
/// # Safety
Expand Down Expand Up @@ -51,6 +64,18 @@ pub unsafe extern "C" fn sys_rand(recv_buf: *mut u8, words: usize) {
}
}

/// Custom random number generator for getrandom
///
/// One of sproll's dependencies uses the getrandom crate,
/// and it will only build, if we provide a custom random number generator.
///
/// Otherwise, it'll complain about an unsupported target.
pub fn my_get_random(buf: &mut [u8]) -> Result<(), Error> {
unsafe { sys_rand(buf.as_mut_ptr(), buf.len()) };
Ok(())
}
register_custom_getrandom!(my_get_random);

pub fn halt(exit_code: u32) -> ! {
#[cfg(target_arch = "riscv32")]
unsafe {
Expand Down
38 changes: 34 additions & 4 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 97237a1

Please sign in to comment.