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