risc0_zkvm_platform/
lib.rs

1// Copyright 2024 RISC Zero, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![doc = include_str!("../README.md")]
16#![no_std]
17#![allow(unused_variables)]
18#![deny(rustdoc::broken_intra_doc_links)]
19#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
20
21pub mod memory;
22#[macro_use]
23pub mod syscall;
24#[cfg(all(feature = "export-getrandom", target_os = "zkvm"))]
25mod getrandom;
26#[cfg(all(feature = "rust-runtime", target_os = "zkvm"))]
27pub mod heap;
28#[cfg(all(feature = "export-libm", target_os = "zkvm"))]
29mod libm_extern;
30#[cfg(all(feature = "rust-runtime", target_os = "zkvm"))]
31pub mod rust_rt;
32
33/// Size of a zkVM machine word in bytes.
34/// 4 bytes (i.e. 32 bits) as the zkVM is an implementation of the rv32im ISA.
35pub const WORD_SIZE: usize = core::mem::size_of::<u32>();
36
37/// Size of a zkVM memory page.
38pub const PAGE_SIZE: usize = 1024;
39
40/// Standard IO file descriptors for use with sys_read and sys_write.
41pub mod fileno {
42    pub const STDIN: u32 = 0;
43    pub const STDOUT: u32 = 1;
44    pub const STDERR: u32 = 2;
45    pub const JOURNAL: u32 = 3;
46}
47
48/// Align address upwards.
49///
50/// Returns the smallest `x` with alignment `align` so that `x >= addr`.
51///
52/// `align` must be a power of 2.
53pub const fn align_up(addr: usize, align: usize) -> usize {
54    let mask = align - 1;
55    (addr + mask) & !mask
56}