|
| 1 | +//! System bindings for the risc0 zkvm platform |
| 2 | +//! |
| 3 | +//! This module contains the facade (aka platform-specific) implementations of |
| 4 | +//! OS level functionality for zkvm. |
| 5 | +//! |
| 6 | +//! This is all super highly experimental and not actually intended for |
| 7 | +//! wide/production use yet, it's still all in the experimental category. This |
| 8 | +//! will likely change over time. |
| 9 | +
|
| 10 | +const WORD_SIZE: usize = core::mem::size_of::<u32>(); |
| 11 | + |
| 12 | +pub mod alloc; |
| 13 | +#[path = "../zkvm/args.rs"] |
| 14 | +pub mod args; |
| 15 | +#[path = "../unix/cmath.rs"] |
| 16 | +pub mod cmath; |
| 17 | +pub mod env; |
| 18 | +#[path = "../unsupported/fs.rs"] |
| 19 | +pub mod fs; |
| 20 | +#[path = "../unsupported/io.rs"] |
| 21 | +pub mod io; |
| 22 | +#[path = "../unsupported/net.rs"] |
| 23 | +pub mod net; |
| 24 | +#[path = "../unsupported/once.rs"] |
| 25 | +pub mod once; |
| 26 | +pub mod os; |
| 27 | +#[path = "../unix/os_str.rs"] |
| 28 | +pub mod os_str; |
| 29 | +#[path = "../unix/path.rs"] |
| 30 | +pub mod path; |
| 31 | +#[path = "../unsupported/pipe.rs"] |
| 32 | +pub mod pipe; |
| 33 | +#[path = "../unsupported/process.rs"] |
| 34 | +pub mod process; |
| 35 | +pub mod stdio; |
| 36 | +pub mod thread_local_key; |
| 37 | +#[path = "../unsupported/time.rs"] |
| 38 | +pub mod time; |
| 39 | + |
| 40 | +#[path = "../unsupported/locks/mod.rs"] |
| 41 | +pub mod locks; |
| 42 | +#[path = "../unsupported/thread.rs"] |
| 43 | +pub mod thread; |
| 44 | + |
| 45 | +#[path = "../unsupported/thread_parking.rs"] |
| 46 | +pub mod thread_parking; |
| 47 | + |
| 48 | +mod abi; |
| 49 | + |
| 50 | +use crate::io as std_io; |
| 51 | + |
| 52 | +pub mod memchr { |
| 53 | + pub use core::slice::memchr::{memchr, memrchr}; |
| 54 | +} |
| 55 | + |
| 56 | +// SAFETY: must be called only once during runtime initialization. |
| 57 | +// NOTE: this is not guaranteed to run, for example when Rust code is called externally. |
| 58 | +pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {} |
| 59 | + |
| 60 | +// SAFETY: must be called only once during runtime cleanup. |
| 61 | +// NOTE: this is not guaranteed to run, for example when the program aborts. |
| 62 | +pub unsafe fn cleanup() {} |
| 63 | + |
| 64 | +pub fn unsupported<T>() -> std_io::Result<T> { |
| 65 | + Err(unsupported_err()) |
| 66 | +} |
| 67 | + |
| 68 | +pub fn unsupported_err() -> std_io::Error { |
| 69 | + std_io::const_io_error!( |
| 70 | + std_io::ErrorKind::Unsupported, |
| 71 | + "operation not supported on this platform", |
| 72 | + ) |
| 73 | +} |
| 74 | + |
| 75 | +pub fn is_interrupted(_code: i32) -> bool { |
| 76 | + false |
| 77 | +} |
| 78 | + |
| 79 | +pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind { |
| 80 | + crate::io::ErrorKind::Uncategorized |
| 81 | +} |
| 82 | + |
| 83 | +pub fn abort_internal() -> ! { |
| 84 | + core::intrinsics::abort(); |
| 85 | +} |
| 86 | + |
| 87 | +pub fn hashmap_random_keys() -> (u64, u64) { |
| 88 | + let mut buf = [0u32; 4]; |
| 89 | + unsafe { |
| 90 | + abi::sys_rand(buf.as_mut_ptr(), 4); |
| 91 | + }; |
| 92 | + ((buf[0] as u64) << 32 + buf[1] as u64, (buf[2] as u64) << 32 + buf[3] as u64) |
| 93 | +} |
0 commit comments