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

Add load_extension syscall #65

Merged
merged 1 commit into from
Jul 11, 2023
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
2 changes: 2 additions & 0 deletions src/ckb_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub const SYS_GET_MEMORY_LIMIT: u64 = 2102;
#[cfg(feature = "ckb2023")]
pub const SYS_SET_CONTENT: u64 = 2103;
#[cfg(feature = "ckb2023")]
pub const SYS_LOAD_EXTENSION: u64 = 2104;
#[cfg(feature = "ckb2023")]
pub const SYS_CURRENT_MEMORY: u64 = 2105;

pub const CKB_SUCCESS: u64 = 0;
Expand Down
30 changes: 30 additions & 0 deletions src/syscalls/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,33 @@ pub fn set_content(buf: &[u8]) -> Result<u64, SysError> {
pub fn current_memory() -> u64 {
unsafe { syscall(0, 0, 0, 0, 0, 0, 0, SYS_CURRENT_MEMORY) }
}

/// Load extension field associated either with an input cell, a dep cell, or
/// a header dep based on source and index value.
///
/// # Arguments
///
/// * `buf` - a writable buf used to receive the data
/// * `offset` - offset
/// * `index` - index of cell
/// * `source` - source of cell
///
/// Note: available after ckb2023.
#[cfg(feature = "ckb2023")]
pub fn load_extension(
buf: &mut [u8],
offset: usize,
index: usize,
source: Source,
) -> Result<usize, SysError> {
syscall_load(
buf.as_mut_ptr(),
buf.len(),
offset,
index as u64,
source as u64,
0,
0,
SYS_LOAD_EXTENSION,
)
}