openvm_platform/
lib.rs

1#![doc = include_str!("../README.md")]
2#![cfg_attr(not(feature = "std"), no_std)]
3#![allow(unused_variables)]
4#![deny(rustdoc::broken_intra_doc_links)]
5#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
6
7#[cfg(target_os = "zkvm")]
8pub use openvm_custom_insn::{custom_insn_i, custom_insn_r};
9#[cfg(target_os = "zkvm")]
10pub mod alloc;
11#[cfg(all(feature = "rust-runtime", target_os = "zkvm"))]
12pub mod heap;
13#[cfg(all(feature = "export-libm", target_os = "zkvm"))]
14mod libm_extern;
15
16pub mod memory;
17pub mod print;
18#[cfg(feature = "rust-runtime")]
19pub mod rust_rt;
20
21/// Size of a zkVM machine word in bytes.
22/// 4 bytes (i.e. 32 bits) as the zkVM is an implementation of the rv32im ISA.
23pub const WORD_SIZE: usize = core::mem::size_of::<u32>();
24
25/// Standard IO file descriptors for use with sys_read and sys_write.
26pub mod fileno {
27    pub const STDIN: u32 = 0;
28    pub const STDOUT: u32 = 1;
29    pub const STDERR: u32 = 2;
30    pub const JOURNAL: u32 = 3;
31}
32
33/// Align address upwards.
34///
35/// Returns the smallest `x` with alignment `align` so that `x >= addr`.
36///
37/// `align` must be a power of 2.
38pub const fn align_up(addr: usize, align: usize) -> usize {
39    let mask = align - 1;
40    (addr + mask) & !mask
41}