Skip to content
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description = "CKB's Virtual machine"
version = "0.24.0"
license = "MIT"
authors = ["Nervos Core Dev <dev@nervos.org>"]
edition = "2021"
rust-version = "1.81.0"
edition = "2024"
rust-version = "1.85.0"
build = "build.rs"
exclude = ["/benches", "/tests"]
homepage = "https://github.com/nervosnetwork/ckb-vm"
Expand Down
8 changes: 4 additions & 4 deletions benches/vm_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ extern crate criterion;
use bytes::Bytes;
#[cfg(has_asm)]
use ckb_vm::{
ISA_B, ISA_IMC, ISA_MOP,
decoder::{DefaultDecoder, InstDecoder},
machine::{
AbstractDefaultMachineBuilder, DefaultMachineRunner, SupportMachine, VERSION0, VERSION2,
asm::{
traces::{MemoizedDynamicTraceDecoder, MemoizedFixedTraceDecoder},
AbstractAsmMachine, AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine,
traces::{MemoizedDynamicTraceDecoder, MemoizedFixedTraceDecoder},
},
AbstractDefaultMachineBuilder, DefaultMachineRunner, SupportMachine, VERSION0, VERSION2,
},
ISA_B, ISA_IMC, ISA_MOP,
};
use ckb_vm::{run, SparseMemory};
use ckb_vm::{SparseMemory, run};
use criterion::Criterion;
use std::fs;

Expand Down
4 changes: 2 additions & 2 deletions definitions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description = "Common definition files for CKB VM"
version = "0.24.0"
license = "MIT"
authors = ["Nervos Core Dev <dev@nervos.org>"]
edition = "2021"
rust-version = "1.81.0"
edition = "2024"
rust-version = "1.85.0"
autobins = false
homepage = "https://github.com/nervosnetwork/ckb-vm"
repository = "https://github.com/nervosnetwork/ckb-vm"
Expand Down
4 changes: 2 additions & 2 deletions definitions/src/asm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{instructions::Instruction, RISCV_GENERAL_REGISTER_NUMBER};
use std::alloc::{dealloc, Layout};
use crate::{RISCV_GENERAL_REGISTER_NUMBER, instructions::Instruction};
use std::alloc::{Layout, dealloc};

// The number of trace items to keep
pub const TRACE_SIZE: usize = 8192;
Expand Down
8 changes: 4 additions & 4 deletions definitions/src/generate_asm_constants.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use ckb_vm_definitions::{
MEMORY_FRAME_PAGE_SHIFTS, MEMORY_FRAME_SHIFTS, MEMORY_FRAMESIZE, RISCV_PAGE_SHIFTS,
RISCV_PAGESIZE,
asm::{
AsmCoreMachine, FixedTrace, InvokeData, RET_CYCLES_OVERFLOW, RET_DECODE_TRACE,
RET_DYNAMIC_JUMP, RET_EBREAK, RET_ECALL, RET_INVALID_PERMISSION, RET_MAX_CYCLES_EXCEEDED,
RET_OUT_OF_BOUND, RET_PAUSE, RET_SLOWPATH, TRACE_ITEM_LENGTH,
},
for_each_inst,
instructions::{instruction_opcode_name, MAXIMUM_OPCODE, MINIMAL_OPCODE},
instructions::{MAXIMUM_OPCODE, MINIMAL_OPCODE, instruction_opcode_name},
memory::{FLAG_DIRTY, FLAG_EXECUTABLE, FLAG_FREEZED, FLAG_WRITABLE, FLAG_WXORX_BIT},
registers::{RA, SP},
MEMORY_FRAMESIZE, MEMORY_FRAME_PAGE_SHIFTS, MEMORY_FRAME_SHIFTS, RISCV_PAGESIZE,
RISCV_PAGE_SHIFTS,
};
use std::alloc::{alloc, Layout};
use std::alloc::{Layout, alloc};
use std::mem::{size_of, zeroed};

macro_rules! print_inst_label {
Expand Down
8 changes: 4 additions & 4 deletions examples/check_real_memory.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// This example is mainly to test whether there is memory overflow.
// Under linux, we choose to use smem, which can monitor memory changes more accurately

use ckb_vm::{run_with_memory, Bytes, FlatMemory, SparseMemory};
use std::process::{id, Command};
use ckb_vm::{Bytes, FlatMemory, SparseMemory, run_with_memory};
use std::process::{Command, id};

#[cfg(has_asm)]
use ckb_vm::{
ISA_IMC,
machine::{
asm::{AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine},
DefaultMachineRunner, SupportMachine, VERSION0,
asm::{AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine},
},
ISA_IMC,
};

#[cfg(has_asm)]
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.81.0
1.85.0
2 changes: 1 addition & 1 deletion src/cost_model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
instructions::{extract_opcode, insts},
Instruction,
instructions::{extract_opcode, insts},
};

// Returns the spent cycles to execute the specific instruction.
Expand Down
2 changes: 1 addition & 1 deletion src/debugger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{machine::SupportMachine, Error};
use crate::{Error, machine::SupportMachine};

pub trait Debugger<Mac: SupportMachine>: Send + Sync {
fn initialize(&mut self, machine: &mut Mac) -> Result<(), Error>;
Expand Down
4 changes: 2 additions & 2 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use ckb_vm_definitions::registers::{RA, ZERO};

use crate::error::OutOfBoundKind;
use crate::instructions::{
a, b, extract_opcode, i, instruction_length, m, rvc, set_instruction_length_n, Instruction,
InstructionFactory, Itype, R4type, R5type, Register, Rtype, Utype,
Instruction, InstructionFactory, Itype, R4type, R5type, Register, Rtype, Utype, a, b,
extract_opcode, i, instruction_length, m, rvc, set_instruction_length_n,
};
use crate::machine::VERSION2;
use crate::memory::Memory;
Expand Down
6 changes: 3 additions & 3 deletions src/elf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This module maps the data structure of different versions of goblin to the
// same internal structure.
use crate::machine::VERSION1;
use crate::memory::{round_page_down, round_page_up, FLAG_EXECUTABLE, FLAG_FREEZED};
use crate::memory::{FLAG_EXECUTABLE, FLAG_FREEZED, round_page_down, round_page_up};
use crate::{Error, Register};
use bytes::Bytes;
use scroll::Pread;
Expand Down Expand Up @@ -137,7 +137,7 @@ pub fn parse_elf<R: Register>(program: &Bytes, version: u32) -> Result<ProgramMe
// * https://github.com/nervosnetwork/ckb-vm/issues/143
let (entry, program_headers): (u64, Vec<ProgramHeader>) = if version < VERSION1 {
use goblin_v023::container::Ctx;
use goblin_v023::elf::{program_header::ProgramHeader as GoblinProgramHeader, Header};
use goblin_v023::elf::{Header, program_header::ProgramHeader as GoblinProgramHeader};
let header = program.pread::<Header>(0)?;
let container = header.container().map_err(|_e| Error::ElfBits)?;
let endianness = header.endianness().map_err(|_e| Error::ElfBits)?;
Expand All @@ -157,7 +157,7 @@ pub fn parse_elf<R: Register>(program: &Bytes, version: u32) -> Result<ProgramMe
(header.e_entry, program_headers)
} else {
use goblin_v040::container::Ctx;
use goblin_v040::elf::{program_header::ProgramHeader as GoblinProgramHeader, Header};
use goblin_v040::elf::{Header, program_header::ProgramHeader as GoblinProgramHeader};
let header = program.pread::<Header>(0)?;
let container = header.container().map_err(|_e| Error::ElfBits)?;
let endianness = header.endianness().map_err(|_e| Error::ElfBits)?;
Expand Down
2 changes: 1 addition & 1 deletion src/instructions/a.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ckb_vm_definitions::instructions as insts;

use super::utils::{funct3, funct7, opcode, rd, rs1, rs2};
use super::{set_instruction_length_4, Instruction, Register, Rtype};
use super::{Instruction, Register, Rtype, set_instruction_length_4};

pub fn factory<R: Register>(instruction_bits: u32, _: u32) -> Option<Instruction> {
let bit_length = R::BITS;
Expand Down
2 changes: 1 addition & 1 deletion src/instructions/b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use ckb_vm_definitions::instructions as insts;

use super::utils::{self, funct3, funct7, opcode, rd, rs1, rs2};
use super::{set_instruction_length_4, Instruction, Itype, Register, Rtype};
use super::{Instruction, Itype, Register, Rtype, set_instruction_length_4};

pub fn factory<R: Register>(instruction_bits: u32, _: u32) -> Option<Instruction> {
let bit_length = R::BITS;
Expand Down
6 changes: 3 additions & 3 deletions src/instructions/execute.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{
super::{machine::Machine, Error},
common, extract_opcode, instruction_length,
super::{Error, machine::Machine},
Instruction, InstructionOpcode, Itype, R4type, R5type, Register, Rtype, Stype, Utype, common,
extract_opcode, instruction_length,
utils::update_register,
Instruction, InstructionOpcode, Itype, R4type, R5type, Register, Rtype, Stype, Utype,
};
use crate::memory::Memory;
use ckb_vm_definitions::{
Expand Down
2 changes: 1 addition & 1 deletion src/instructions/i.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::utils::{
lw, lwu, opcode, rd, rs1, rs2, stype_immediate, utype_immediate,
};
use super::{
blank_instruction, set_instruction_length_4, Instruction, Itype, Register, Rtype, Stype, Utype,
Instruction, Itype, Register, Rtype, Stype, Utype, blank_instruction, set_instruction_length_4,
};

// The FENCE instruction is used to order device I/O and memory accesses
Expand Down
2 changes: 1 addition & 1 deletion src/instructions/m.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ckb_vm_definitions::instructions as insts;

use super::utils::{funct3, funct7, opcode, rd, rs1, rs2};
use super::{set_instruction_length_4, Instruction, Register, Rtype};
use super::{Instruction, Register, Rtype, set_instruction_length_4};

pub fn factory<R: Register>(instruction_bits: u32, _: u32) -> Option<Instruction> {
let bit_length = R::BITS;
Expand Down
6 changes: 3 additions & 3 deletions src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ pub use self::register::Register;
use super::Error;
pub use ckb_vm_definitions::{
instructions::{
self as insts, instruction_opcode_name, Instruction, InstructionOpcode,
MAXIMUM_BASIC_BLOCK_END_OPCODE, MINIMAL_BASIC_BLOCK_END_OPCODE, MINIMAL_OPCODE,
self as insts, Instruction, InstructionOpcode, MAXIMUM_BASIC_BLOCK_END_OPCODE,
MINIMAL_BASIC_BLOCK_END_OPCODE, MINIMAL_OPCODE, instruction_opcode_name,
},
registers::REGISTER_ABI_NAMES,
};
use core::fmt;
pub use execute::{
execute, execute_instruction, execute_with_thread, handle_invalid_op, Thread, ThreadFactory,
Thread, ThreadFactory, execute, execute_instruction, execute_with_thread, handle_invalid_op,
};

pub type RegisterIndex = usize;
Expand Down
12 changes: 2 additions & 10 deletions src/instructions/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ impl Register for u32 {
*self
} else {
let (v, o) = (*self as i32).overflowing_rem(*rhs as i32);
if o {
0
} else {
v as u32
}
if o { 0 } else { v as u32 }
}
}

Expand Down Expand Up @@ -501,11 +497,7 @@ impl Register for u64 {
*self
} else {
let (v, o) = (*self as i64).overflowing_rem(*rhs as i64);
if o {
0
} else {
v as u64
}
if o { 0 } else { v as u64 }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/instructions/rvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ckb_vm_definitions::registers::SP;
use super::i::nop;
use super::register::Register;
use super::utils::{jalr, ld, lw, rd, x, xs};
use super::{blank_instruction, set_instruction_length_2, Instruction, Itype, Rtype, Stype, Utype};
use super::{Instruction, Itype, Rtype, Stype, Utype, blank_instruction, set_instruction_length_2};

// Notice the location of rs2 in RVC encoding is different from full encoding
#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/instructions/tagged.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
error::Error,
instructions::{
extract_opcode, insts, Instruction, Itype, R4type, R5type, Rtype, Stype, Utype,
Instruction, Itype, R4type, R5type, Rtype, Stype, Utype, extract_opcode, insts,
},
};
use core::convert::TryFrom;
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ pub use crate::{
debugger::Debugger,
instructions::{Instruction, Register},
machine::{
trace::TraceMachine, CoreMachine, DefaultCoreMachine, DefaultMachine, DefaultMachineRunner,
FlattenedArgsReader, InstructionCycleFunc, Machine, RustDefaultMachineBuilder,
SupportMachine,
CoreMachine, DefaultCoreMachine, DefaultMachine, DefaultMachineRunner, FlattenedArgsReader,
InstructionCycleFunc, Machine, RustDefaultMachineBuilder, SupportMachine,
trace::TraceMachine,
},
memory::{flat::FlatMemory, sparse::SparseMemory, wxorx::WXorXMemory, Memory},
memory::{Memory, flat::FlatMemory, sparse::SparseMemory, wxorx::WXorXMemory},
syscalls::Syscalls,
};
pub use bytes::Bytes;

pub use ckb_vm_definitions::{
registers, DEFAULT_MEMORY_SIZE, ISA_A, ISA_B, ISA_IMC, ISA_MOP, MEMORY_FRAMESIZE,
MEMORY_FRAME_SHIFTS, RISCV_GENERAL_REGISTER_NUMBER, RISCV_PAGESIZE, RISCV_PAGE_SHIFTS,
DEFAULT_MEMORY_SIZE, ISA_A, ISA_B, ISA_IMC, ISA_MOP, MEMORY_FRAME_SHIFTS, MEMORY_FRAMESIZE,
RISCV_GENERAL_REGISTER_NUMBER, RISCV_PAGE_SHIFTS, RISCV_PAGESIZE, registers,
};

pub use error::Error;
Expand Down
Loading
Loading