Skip to content

Commit 0b6032b

Browse files
committed
feat: misc improvements
1 parent 34be7d8 commit 0b6032b

File tree

4 files changed

+14
-45
lines changed

4 files changed

+14
-45
lines changed

library/panic_abort/src/zkvm.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ pub(crate) unsafe fn zkvm_set_abort_message(payload: &mut dyn PanicPayload) {
1212
None => &[],
1313
},
1414
};
15-
if msg.is_empty() {
16-
return;
17-
}
18-
15+
1916
extern "C" {
17+
fn syscall_halt(exit_code: u8) -> !;
2018
fn sys_panic(msg_ptr: *const u8, len: usize) -> !;
2119
}
2220

21+
if msg.is_empty() {
22+
syscall_halt(1);
23+
}
24+
2325
sys_panic(msg.as_ptr(), msg.len());
2426
}

library/std/src/sys/pal/zkvm/abi.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,16 @@ pub mod fileno {
2020

2121
extern "C" {
2222
// Wrappers around syscalls provided by sp1-zkvm-platform:
23-
pub fn sys_halt();
24-
pub fn sys_output(output_id: u32, output_value: u32);
25-
pub fn sys_sha_compress(
26-
out_state: *mut [u32; DIGEST_WORDS],
27-
in_state: *const [u32; DIGEST_WORDS],
28-
block1_ptr: *const [u32; DIGEST_WORDS],
29-
block2_ptr: *const [u32; DIGEST_WORDS],
30-
);
31-
pub fn sys_sha_buffer(
32-
out_state: *mut [u32; DIGEST_WORDS],
33-
in_state: *const [u32; DIGEST_WORDS],
34-
buf: *const u8,
35-
count: u32,
36-
);
3723
pub fn sys_rand(recv_buf: *mut u8, words: usize);
3824
pub fn sys_panic(msg_ptr: *const u8, len: usize) -> !;
39-
pub fn sys_log(msg_ptr: *const u8, len: usize);
40-
pub fn sys_cycle_count() -> usize;
41-
pub fn sys_read(fd: u32, recv_buf: *mut u8, nrequested: usize) -> usize;
4225
pub fn sys_write(fd: u32, write_buf: *const u8, nbytes: usize);
4326
pub fn sys_getenv(
4427
recv_buf: *mut u32,
4528
words: usize,
4629
varname: *const u8,
4730
varname_len: usize,
4831
) -> usize;
49-
pub fn sys_argc() -> usize;
50-
pub fn sys_argv(out_words: *mut u32, out_nwords: usize, arg_index: usize) -> usize;
51-
32+
5233
// Allocate memory from global HEAP.
5334
pub fn sys_alloc_words(nwords: usize) -> *mut u32;
5435
pub fn sys_alloc_aligned(nwords: usize, align: usize) -> *mut u8;

library/std/src/sys/pal/zkvm/args.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,13 @@ pub struct Args {
1111
}
1212

1313
pub fn args() -> Args {
14-
let count = unsafe { abi::sys_argc() };
15-
Args { i_forward: 0, i_back: 0, count }
14+
Args { i_forward: 0, i_back: 0, count: 0 }
1615
}
1716

1817
impl Args {
19-
/// Use sys_argv to get the arg at the requested index. Does not check that i is less than argc
20-
/// and will not return if the index is out of bounds.
18+
/// Args::argv is currently not implemented.
2119
fn argv(i: usize) -> OsString {
22-
let arg_len = unsafe { abi::sys_argv(crate::ptr::null_mut(), 0, i) };
23-
24-
let arg_len_words = (arg_len + WORD_SIZE - 1) / WORD_SIZE;
25-
let words = unsafe { abi::sys_alloc_words(arg_len_words) };
26-
27-
let arg_len2 = unsafe { abi::sys_argv(words, arg_len_words, i) };
28-
debug_assert_eq!(arg_len, arg_len2);
29-
30-
// Convert to OsString.
31-
//
32-
// FIXME: We can probably get rid of the extra copy here if we
33-
// reimplement "os_str" instead of just using the generic unix
34-
// "os_str".
35-
let arg_bytes: &[u8] =
36-
unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, arg_len) };
37-
OsString::from_inner(os_str::Buf { inner: arg_bytes.to_vec() })
20+
panic!("Args::argv is currently not implemented");
3821
}
3922
}
4023

library/std/src/sys/pal/zkvm/stdio.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ impl Stdin {
1414

1515
impl io::Read for Stdin {
1616
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
17-
Ok(unsafe { abi::sys_read(fileno::STDIN, buf.as_mut_ptr(), buf.len()) })
17+
return Err(io::Error::new(
18+
io::ErrorKind::Other,
19+
"io::Read for Stdin is currently not implemented",
20+
));
1821
}
1922
}
2023

0 commit comments

Comments
 (0)