-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3908 from mohanson/script_version_2
script: Add script version 2
- Loading branch information
Showing
74 changed files
with
1,743 additions
and
219 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::syscalls::GET_MEMORY_LIMIT; | ||
use ckb_vm::{ | ||
registers::{A0, A7}, | ||
Error as VMError, Register, SupportMachine, Syscalls, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct GetMemoryLimit { | ||
memory_limit: u64, | ||
} | ||
|
||
impl GetMemoryLimit { | ||
pub fn new(memory_limit: u64) -> Self { | ||
Self { memory_limit } | ||
} | ||
} | ||
|
||
impl<Mac: SupportMachine> Syscalls<Mac> for GetMemoryLimit { | ||
fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { | ||
Ok(()) | ||
} | ||
|
||
fn ecall(&mut self, machine: &mut Mac) -> Result<bool, VMError> { | ||
if machine.registers()[A7].to_u64() != GET_MEMORY_LIMIT { | ||
return Ok(false); | ||
} | ||
machine.set_register(A0, Mac::REG::from_u64(self.memory_limit)); | ||
Ok(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::cost_model::transferred_byte_cycles; | ||
use crate::syscalls::utils::load_bytes; | ||
use crate::syscalls::SET_CONTENT; | ||
use ckb_vm::{ | ||
registers::{A0, A1, A7}, | ||
Error as VMError, Memory, Register, SupportMachine, Syscalls, | ||
}; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
#[derive(Debug)] | ||
pub struct SetContent { | ||
content: Arc<Mutex<Vec<u8>>>, | ||
content_size: u64, | ||
} | ||
|
||
impl SetContent { | ||
pub fn new(content: Arc<Mutex<Vec<u8>>>, content_size: u64) -> Self { | ||
Self { | ||
content, | ||
content_size, | ||
} | ||
} | ||
} | ||
|
||
impl<Mac: SupportMachine> Syscalls<Mac> for SetContent { | ||
fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> { | ||
Ok(()) | ||
} | ||
|
||
fn ecall(&mut self, machine: &mut Mac) -> Result<bool, VMError> { | ||
if machine.registers()[A7].to_u64() != SET_CONTENT { | ||
return Ok(false); | ||
} | ||
let content_addr = machine.registers()[A0].to_u64(); | ||
let request_size_addr = machine.registers()[A1].to_u64(); | ||
let request_size = machine | ||
.memory_mut() | ||
.load64(&Mac::REG::from_u64(request_size_addr))?; | ||
let size = std::cmp::min(self.content_size, request_size.to_u64()); | ||
self.content.lock().unwrap().resize(size as usize, 0); | ||
let content = load_bytes(machine, content_addr, size)?; | ||
self.content.lock().unwrap().copy_from_slice(&content); | ||
machine.memory_mut().store64( | ||
&Mac::REG::from_u64(request_size_addr), | ||
&Mac::REG::from_u64(size), | ||
)?; | ||
machine.add_cycles_no_checking(transferred_byte_cycles(size))?; | ||
machine.set_register(A0, Mac::REG::from_u64(0)); | ||
Ok(true) | ||
} | ||
} |
Oops, something went wrong.