Skip to content

Commit f035b7a

Browse files
Erik KanedaflaubUrgau
committed
rustc: implement support for riscv32im_risc0_zkvm_elf
This also adds changes in the rust test suite in order to get a few of them to pass. Co-authored-by: Frank Laub <[email protected]> Co-authored-by: Urgau <[email protected]>
1 parent da395c8 commit f035b7a

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

panic_abort/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#[cfg(target_os = "android")]
2020
mod android;
2121

22+
#[cfg(target_os = "zkvm")]
23+
mod zkvm;
24+
2225
use core::any::Any;
2326
use core::panic::PanicPayload;
2427

@@ -34,6 +37,8 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
3437
// Android has the ability to attach a message as part of the abort.
3538
#[cfg(target_os = "android")]
3639
android::android_set_abort_message(_payload);
40+
#[cfg(target_os = "zkvm")]
41+
zkvm::zkvm_set_abort_message(_payload);
3742

3843
abort();
3944

panic_abort/src/zkvm.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use alloc::string::String;
2+
use core::panic::PanicPayload;
3+
4+
// Forward the abort message to zkVM's sys_panic. This is implemented by RISC Zero's
5+
// platform crate which exposes system calls specifically for the zkVM.
6+
pub(crate) unsafe fn zkvm_set_abort_message(payload: &mut dyn PanicPayload) {
7+
let payload = payload.get();
8+
let msg = match payload.downcast_ref::<&'static str>() {
9+
Some(msg) => msg.as_bytes(),
10+
None => match payload.downcast_ref::<String>() {
11+
Some(msg) => msg.as_bytes(),
12+
None => &[],
13+
},
14+
};
15+
if msg.is_empty() {
16+
return;
17+
}
18+
19+
extern "C" {
20+
fn sys_panic(msg_ptr: *const u8, len: usize) -> !;
21+
}
22+
23+
sys_panic(msg.as_ptr(), msg.len());
24+
}

test/src/console.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
323323
// Prevent the usage of `Instant` in some cases:
324324
// - It's currently not supported for wasm targets.
325325
// - We disable it for miri because it's not available when isolation is enabled.
326-
let is_instant_supported = !cfg!(target_family = "wasm") && !cfg!(miri);
326+
let is_instant_supported =
327+
!cfg!(target_family = "wasm") && !cfg!(target_os = "zkvm") && !cfg!(miri);
327328

328329
let start_time = is_instant_supported.then(Instant::now);
329330
run_tests(opts, tests, |x| on_test_event(&x, &mut st, &mut *out))?;

test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ pub fn run_test(
540540

541541
// Emscripten can catch panics but other wasm targets cannot
542542
let ignore_because_no_process_support = desc.should_panic != ShouldPanic::No
543-
&& cfg!(target_family = "wasm")
543+
&& (cfg!(target_family = "wasm") || cfg!(target_os = "zkvm"))
544544
&& !cfg!(target_os = "emscripten");
545545

546546
if force_ignore || desc.ignore || ignore_because_no_process_support {

0 commit comments

Comments
 (0)