#![cfg_attr(not(feature = "std"), no_std)]
#![deny(rustdoc::broken_intra_doc_links)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#[macro_use]
extern crate alloc;
#[cfg(target_os = "zkvm")]
use core::arch::asm;
pub use openvm_platform as platform;
#[cfg(target_os = "zkvm")]
#[allow(unused_imports)]
use openvm_platform::rust_rt;
#[cfg(target_os = "zkvm")]
pub use openvm_rv32im_guest::*;
#[cfg(target_os = "zkvm")]
mod getrandom;
pub mod io;
#[cfg(all(feature = "std", target_os = "zkvm"))]
pub mod pal_abi;
pub mod process;
pub mod serde;
#[cfg(not(target_os = "zkvm"))]
pub mod utils;
#[cfg(not(target_os = "zkvm"))]
pub mod host;
#[cfg(target_os = "zkvm")]
core::arch::global_asm!(include_str!("memset.s"));
#[cfg(target_os = "zkvm")]
core::arch::global_asm!(include_str!("memcpy.s"));
fn _fault() -> ! {
#[cfg(target_os = "zkvm")]
unsafe {
asm!("sw x0, 1(x0)")
};
unreachable!();
}
#[cfg(all(not(feature = "std"), target_os = "zkvm"))]
#[macro_export]
macro_rules! entry {
($path:path) => {
const ZKVM_ENTRY: fn() = $path;
mod zkvm_generated_main {
#[no_mangle]
fn main() {
super::ZKVM_ENTRY()
}
}
};
}
#[cfg(any(feature = "std", not(target_os = "zkvm")))]
#[macro_export]
macro_rules! entry {
($path:path) => {};
}
#[cfg(target_os = "zkvm")]
#[no_mangle]
unsafe extern "C" fn __start() -> ! {
#[cfg(feature = "heap-embedded-alloc")]
openvm_platform::heap::embedded::init();
{
extern "C" {
fn main();
}
main()
}
process::exit();
unreachable!()
}
#[cfg(target_os = "zkvm")]
static STACK_TOP: u32 = openvm_platform::memory::STACK_TOP;
#[cfg(target_os = "zkvm")]
core::arch::global_asm!(
r#"
.section .text._start;
.globl _start;
_start:
.option push;
.option norelax;
la gp, __global_pointer$;
.option pop;
la sp, {0};
lw sp, 0(sp);
call __start;
"#,
sym STACK_TOP
);
#[allow(unused_variables)]
pub fn memory_barrier<T>(ptr: *const T) {
#[cfg(target_os = "zkvm")]
unsafe {
asm!("/* {0} */", in(reg) (ptr))
}
#[cfg(not(target_os = "zkvm"))]
core::sync::atomic::fence(core::sync::atomic::Ordering::SeqCst)
}
#[cfg(all(target_os = "zkvm", not(feature = "std")))]
#[panic_handler]
fn panic_impl(panic_info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;
let mut writer = crate::io::Writer;
let _ = write!(writer, "{}\n", panic_info);
openvm_platform::rust_rt::terminate::<1>();
unreachable!()
}
#[macro_export]
macro_rules! init {
() => {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/openvm_init.rs"));
};
($name:expr) => {
include!(concat!(env!("CARGO_MANIFEST_DIR"), concat!("/", $name)));
};
}