-
Notifications
You must be signed in to change notification settings - Fork 236
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 #4785 from libraries/args_reader
Improving spawn and exec syscalls
- Loading branch information
Showing
11 changed files
with
260 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::syscalls::{EXEC, INDEX_OUT_OF_BOUND}; | ||
use crate::types::{DataLocation, DataPieceId, ExecV2Args, Message, VmId}; | ||
use ckb_vm::{ | ||
registers::{A0, A1, A2, A3, A4, A5, A7}, | ||
Error as VMError, Register, SupportMachine, Syscalls, | ||
}; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
pub struct ExecV2 { | ||
id: VmId, | ||
message_box: Arc<Mutex<Vec<Message>>>, | ||
} | ||
|
||
impl ExecV2 { | ||
pub fn new(id: VmId, message_box: Arc<Mutex<Vec<Message>>>) -> ExecV2 { | ||
ExecV2 { id, message_box } | ||
} | ||
} | ||
|
||
impl<Mac> Syscalls<Mac> for ExecV2 | ||
where | ||
Mac: SupportMachine, | ||
{ | ||
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() != EXEC { | ||
return Ok(false); | ||
} | ||
let index = machine.registers()[A0].to_u64(); | ||
let source = machine.registers()[A1].to_u64(); | ||
let place = machine.registers()[A2].to_u64(); | ||
let data_piece_id = match DataPieceId::try_from((source, index, place)) { | ||
Ok(id) => id, | ||
Err(_) => { | ||
machine.set_register(A0, Mac::REG::from_u8(INDEX_OUT_OF_BOUND)); | ||
return Ok(true); | ||
} | ||
}; | ||
let bounds = machine.registers()[A3].to_u64(); | ||
let offset = bounds >> 32; | ||
let length = bounds as u32 as u64; | ||
|
||
let argc = machine.registers()[A4].to_u64(); | ||
let argv = machine.registers()[A5].to_u64(); | ||
self.message_box | ||
.lock() | ||
.map_err(|e| VMError::Unexpected(e.to_string()))? | ||
.push(Message::ExecV2( | ||
self.id, | ||
ExecV2Args { | ||
location: DataLocation { | ||
data_piece_id, | ||
offset, | ||
length, | ||
}, | ||
argc, | ||
argv, | ||
}, | ||
)); | ||
Err(VMError::Yield) | ||
} | ||
} |
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
Oops, something went wrong.