Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mismatch method signature of libc's calloc #201

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions provers/risc0/guest/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use std::{
ffi::c_void,
};

/// This is a basic implementation of custom memory allocation functions that mimic C-style memory management.
/// This implementation is designed to be used in ZkVM where we cross-compile Rust code with C
/// This is a basic implementation of custom memory allocation functions that mimic C-style memory management.
/// This implementation is designed to be used in ZkVM where we cross-compile Rust code with C
/// due to the dependency of c-kzg. This modification also requires env var:
/// $ CC="gcc"
/// $ CC_riscv32im-risc0-zkvm-elf="/opt/riscv/bin/riscv32-unknown-elf-gcc"
/// which is set in the build pipeline


#[no_mangle]
// TODO ideally this is c_size_t, but not stabilized (not guaranteed to be usize on all archs)
pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void {
Expand All @@ -26,8 +25,8 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void {

#[no_mangle]
// TODO shouldn't need to zero allocated bytes since the zkvm memory is zeroed, might want to zero anyway
pub unsafe extern "C" fn calloc(size: usize) -> *mut c_void {
malloc(size)
pub unsafe extern "C" fn calloc(nobj: usize, size: usize) -> *mut c_void {
malloc(nobj * size)
}

#[no_mangle]
Expand Down
4 changes: 2 additions & 2 deletions provers/sp1/guest/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void {

#[no_mangle]
// TODO shouldn't need to zero allocated bytes since the zkvm memory is zeroed, might want to zero anyway
pub unsafe extern "C" fn calloc(size: usize) -> *mut c_void {
malloc(size)
pub unsafe extern "C" fn calloc(nobj: usize, size: usize) -> *mut c_void {
malloc(nobj * size)
}

#[no_mangle]
Expand Down
Loading