From eac7684220c1858abe45d7561cf2595680102fe9 Mon Sep 17 00:00:00 2001 From: mohanson Date: Mon, 31 Mar 2025 15:05:07 +0800 Subject: [PATCH 1/3] Use rust edition 2024 --- Cargo.toml | 4 +- benches/vm_benchmark.rs | 8 ++-- definitions/Cargo.toml | 4 +- definitions/src/asm.rs | 4 +- definitions/src/generate_asm_constants.rs | 8 ++-- examples/check_real_memory.rs | 8 ++-- rust-toolchain | 2 +- src/cost_model.rs | 2 +- src/debugger.rs | 2 +- src/decoder.rs | 4 +- src/elf.rs | 6 +-- src/instructions/a.rs | 2 +- src/instructions/b.rs | 2 +- src/instructions/execute.rs | 6 +-- src/instructions/i.rs | 2 +- src/instructions/m.rs | 2 +- src/instructions/mod.rs | 6 +-- src/instructions/register.rs | 12 +----- src/instructions/rvc.rs | 2 +- src/instructions/tagged.rs | 2 +- src/lib.rs | 12 +++--- src/machine/asm/mod.rs | 31 ++++++++------- src/machine/asm/traces.rs | 8 ++-- src/machine/mod.rs | 10 ++--- src/machine/trace.rs | 6 +-- src/memory/flat.rs | 4 +- src/memory/mod.rs | 4 +- src/memory/sparse.rs | 4 +- src/memory/wxorx.rs | 6 +-- src/snapshot.rs | 4 +- src/snapshot2.rs | 4 +- tests/machine_build.rs | 2 +- tests/test_a_extension.rs | 2 +- tests/test_asm.rs | 4 +- tests/test_auipc_fusion.rs | 10 ++--- tests/test_b_extension.rs | 2 +- tests/test_dy_memory.rs | 6 +-- tests/test_minimal.rs | 2 +- tests/test_misc.rs | 10 ++--- tests/test_mop.rs | 8 ++-- tests/test_reset.rs | 4 +- tests/test_resume.rs | 4 +- tests/test_resume2.rs | 8 ++-- tests/test_signal_pause.rs | 48 ++++++++++++----------- tests/test_simple.rs | 4 +- tests/test_spawn.rs | 6 +-- tests/test_versions.rs | 6 +-- 47 files changed, 153 insertions(+), 154 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1db71c14..63824653 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,8 @@ description = "CKB's Virtual machine" version = "0.24.0" license = "MIT" authors = ["Nervos Core Dev "] -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" diff --git a/benches/vm_benchmark.rs b/benches/vm_benchmark.rs index e9db7cc3..ac4b9761 100644 --- a/benches/vm_benchmark.rs +++ b/benches/vm_benchmark.rs @@ -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; diff --git a/definitions/Cargo.toml b/definitions/Cargo.toml index ced08fbb..f09d98ab 100644 --- a/definitions/Cargo.toml +++ b/definitions/Cargo.toml @@ -4,8 +4,8 @@ description = "Common definition files for CKB VM" version = "0.24.0" license = "MIT" authors = ["Nervos Core Dev "] -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" diff --git a/definitions/src/asm.rs b/definitions/src/asm.rs index 5fd5084d..08e8a841 100644 --- a/definitions/src/asm.rs +++ b/definitions/src/asm.rs @@ -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; diff --git a/definitions/src/generate_asm_constants.rs b/definitions/src/generate_asm_constants.rs index 4e8fe2b0..372add70 100644 --- a/definitions/src/generate_asm_constants.rs +++ b/definitions/src/generate_asm_constants.rs @@ -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 { diff --git a/examples/check_real_memory.rs b/examples/check_real_memory.rs index a2ee6ef4..b6d0a9fd 100644 --- a/examples/check_real_memory.rs +++ b/examples/check_real_memory.rs @@ -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)] diff --git a/rust-toolchain b/rust-toolchain index dbd41264..f288d111 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.81.0 +1.85.0 diff --git a/src/cost_model.rs b/src/cost_model.rs index d2acb0bd..4d2ead0e 100644 --- a/src/cost_model.rs +++ b/src/cost_model.rs @@ -1,6 +1,6 @@ use crate::{ - instructions::{extract_opcode, insts}, Instruction, + instructions::{extract_opcode, insts}, }; // Returns the spent cycles to execute the specific instruction. diff --git a/src/debugger.rs b/src/debugger.rs index 4d7348f9..77cb95b7 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -1,4 +1,4 @@ -use crate::{machine::SupportMachine, Error}; +use crate::{Error, machine::SupportMachine}; pub trait Debugger: Send + Sync { fn initialize(&mut self, machine: &mut Mac) -> Result<(), Error>; diff --git a/src/decoder.rs b/src/decoder.rs index 45ccf016..ef6ef06c 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -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; diff --git a/src/elf.rs b/src/elf.rs index 8d537492..083a2f52 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -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; @@ -137,7 +137,7 @@ pub fn parse_elf(program: &Bytes, version: u32) -> Result) = 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::
(0)?; let container = header.container().map_err(|_e| Error::ElfBits)?; let endianness = header.endianness().map_err(|_e| Error::ElfBits)?; @@ -157,7 +157,7 @@ pub fn parse_elf(program: &Bytes, version: u32) -> Result(0)?; let container = header.container().map_err(|_e| Error::ElfBits)?; let endianness = header.endianness().map_err(|_e| Error::ElfBits)?; diff --git a/src/instructions/a.rs b/src/instructions/a.rs index be581a97..3e86c8e4 100644 --- a/src/instructions/a.rs +++ b/src/instructions/a.rs @@ -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(instruction_bits: u32, _: u32) -> Option { let bit_length = R::BITS; diff --git a/src/instructions/b.rs b/src/instructions/b.rs index 7410c02d..920c9451 100644 --- a/src/instructions/b.rs +++ b/src/instructions/b.rs @@ -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(instruction_bits: u32, _: u32) -> Option { let bit_length = R::BITS; diff --git a/src/instructions/execute.rs b/src/instructions/execute.rs index 35e4465d..fe03edec 100644 --- a/src/instructions/execute.rs +++ b/src/instructions/execute.rs @@ -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::{ diff --git a/src/instructions/i.rs b/src/instructions/i.rs index 7e8014a8..a7b9a27a 100644 --- a/src/instructions/i.rs +++ b/src/instructions/i.rs @@ -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 diff --git a/src/instructions/m.rs b/src/instructions/m.rs index feb441e2..546249dd 100644 --- a/src/instructions/m.rs +++ b/src/instructions/m.rs @@ -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(instruction_bits: u32, _: u32) -> Option { let bit_length = R::BITS; diff --git a/src/instructions/mod.rs b/src/instructions/mod.rs index 6cc88423..43fbec16 100644 --- a/src/instructions/mod.rs +++ b/src/instructions/mod.rs @@ -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; diff --git a/src/instructions/register.rs b/src/instructions/register.rs index 2ae50c85..e79d8c67 100644 --- a/src/instructions/register.rs +++ b/src/instructions/register.rs @@ -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 } } } @@ -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 } } } diff --git a/src/instructions/rvc.rs b/src/instructions/rvc.rs index 7a69be36..d10b2ae3 100644 --- a/src/instructions/rvc.rs +++ b/src/instructions/rvc.rs @@ -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)] diff --git a/src/instructions/tagged.rs b/src/instructions/tagged.rs index 39dff710..14af48bf 100644 --- a/src/instructions/tagged.rs +++ b/src/instructions/tagged.rs @@ -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; diff --git a/src/lib.rs b/src/lib.rs index 06608028..88c20306 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/machine/asm/mod.rs b/src/machine/asm/mod.rs index 5c277833..7f555ef7 100644 --- a/src/machine/asm/mod.rs +++ b/src/machine/asm/mod.rs @@ -4,33 +4,34 @@ use byteorder::{ByteOrder, LittleEndian}; use bytes::Bytes; pub use ckb_vm_definitions::asm::AsmCoreMachine; use ckb_vm_definitions::{ + ISA_MOP, MEMORY_FRAME_PAGE_SHIFTS, MEMORY_FRAMESIZE, RISCV_GENERAL_REGISTER_NUMBER, + RISCV_PAGE_SHIFTS, asm::{ 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, }, - ISA_MOP, MEMORY_FRAMESIZE, MEMORY_FRAME_PAGE_SHIFTS, RISCV_GENERAL_REGISTER_NUMBER, - RISCV_PAGE_SHIFTS, }; -use rand::{prelude::RngCore, SeedableRng}; -use std::alloc::{alloc, alloc_zeroed, Layout}; +use rand::{SeedableRng, prelude::RngCore}; +use std::alloc::{Layout, alloc, alloc_zeroed}; use std::mem::MaybeUninit; use std::os::raw::c_uchar; use crate::{ + CoreMachine, DefaultMachine, DefaultMachineRunner, Error, MEMORY_FRAME_SHIFTS, Machine, Memory, + RISCV_PAGESIZE, SupportMachine, elf::ProgramMetadata, error::OutOfBoundKind, instructions::execute_instruction, machine::{ - asm::traces::{decode_fixed_trace, SimpleFixedTraceDecoder, TraceDecoder}, AbstractDefaultMachineBuilder, VERSION0, + asm::traces::{SimpleFixedTraceDecoder, TraceDecoder, decode_fixed_trace}, }, memory::{ + FLAG_DIRTY, FLAG_EXECUTABLE, FLAG_FREEZED, FLAG_WRITABLE, FLAG_WXORX_BIT, check_no_overflow, fill_page_data, get_page_indices, memset, round_page_down, - round_page_up, FLAG_DIRTY, FLAG_EXECUTABLE, FLAG_FREEZED, FLAG_WRITABLE, FLAG_WXORX_BIT, + round_page_up, }, - CoreMachine, DefaultMachine, DefaultMachineRunner, Error, Machine, Memory, SupportMachine, - MEMORY_FRAME_SHIFTS, RISCV_PAGESIZE, }; pub trait AsmCoreMachineRevealer: AsRef + AsMut { @@ -134,9 +135,9 @@ pub extern "C" fn inited_memory(frame_index: u64, machine: &mut AsmCoreMachine) 1 << MEMORY_FRAME_SHIFTS, ); if is_chaos_mode { - let mut gen = rand::rngs::StdRng::seed_from_u64(chaos_seed); - gen.fill_bytes(slice); - machine.chaos_seed = gen.next_u32(); + let mut rgen = rand::rngs::StdRng::seed_from_u64(chaos_seed); + rgen.fill_bytes(slice); + machine.chaos_seed = rgen.next_u32(); } else { memset(slice, 0); } @@ -785,12 +786,12 @@ impl DefaultMachineRunner for Abstra return Err(Error::MemOutOfBound( self.machine.inner.as_ref().error_arg0, OutOfBoundKind::Memory, - )) + )); } RET_INVALID_PERMISSION => { return Err(Error::MemWriteOnExecutablePage( self.machine.inner.as_ref().error_arg0, - )) + )); } RET_SLOWPATH => { let pc = *self.machine.pc() - 4; @@ -852,12 +853,12 @@ impl AbstractAsmMachine { return Err(Error::MemOutOfBound( self.machine.inner.as_ref().error_arg0, OutOfBoundKind::Memory, - )) + )); } RET_INVALID_PERMISSION => { return Err(Error::MemWriteOnExecutablePage( self.machine.inner.as_ref().error_arg0, - )) + )); } RET_SLOWPATH => { let pc = *self.machine.pc() - 4; diff --git a/src/machine/asm/traces.rs b/src/machine/asm/traces.rs index bbc9ada4..c91f730c 100644 --- a/src/machine/asm/traces.rs +++ b/src/machine/asm/traces.rs @@ -1,6 +1,7 @@ use crate::{ + Register, ckb_vm_definitions::{ - asm::{calculate_slot, FixedTrace, TRACE_ITEM_LENGTH, TRACE_SIZE}, + asm::{FixedTrace, TRACE_ITEM_LENGTH, TRACE_SIZE, calculate_slot}, instructions::{ Instruction, InstructionOpcode, OP_CUSTOM_ASM_TRACE_JUMP, OP_CUSTOM_TRACE_END, }, @@ -12,13 +13,12 @@ use crate::{ is_slowpath_instruction, }, machine::{ - asm::{ckb_vm_asm_labels, AsmCoreMachineRevealer}, CoreMachine, DefaultMachine, + asm::{AsmCoreMachineRevealer, ckb_vm_asm_labels}, }, memory::Memory, - Register, }; -use std::alloc::{alloc, alloc_zeroed, Layout}; +use std::alloc::{Layout, alloc, alloc_zeroed}; use std::collections::HashMap; pub trait TraceDecoder: InstDecoder { diff --git a/src/machine/mod.rs b/src/machine/mod.rs index 7145cb23..a4f04008 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -4,20 +4,20 @@ pub mod trace; use std::fmt::{self, Display}; use std::marker::PhantomData; -use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicU8, Ordering}; use bytes::Bytes; use super::debugger::Debugger; use super::decoder::{DefaultDecoder, InstDecoder}; -use super::elf::{parse_elf, LoadingAction, ProgramMetadata}; -use super::instructions::{execute, Instruction, Register}; -use super::memory::{load_c_string_byte_by_byte, Memory}; +use super::elf::{LoadingAction, ProgramMetadata, parse_elf}; +use super::instructions::{Instruction, Register, execute}; +use super::memory::{Memory, load_c_string_byte_by_byte}; use super::syscalls::Syscalls; use super::{ + DEFAULT_MEMORY_SIZE, Error, ISA_MOP, RISCV_GENERAL_REGISTER_NUMBER, registers::{A0, A7, REGISTER_ABI_NAMES, SP}, - Error, DEFAULT_MEMORY_SIZE, ISA_MOP, RISCV_GENERAL_REGISTER_NUMBER, }; // Version 0 is the initial launched CKB VM, it is used in CKB Lina mainnet diff --git a/src/machine/trace.rs b/src/machine/trace.rs index 769896e3..7b0b0136 100644 --- a/src/machine/trace.rs +++ b/src/machine/trace.rs @@ -1,12 +1,12 @@ use super::{ super::{ + Error, decoder::{DefaultDecoder, InstDecoder}, elf::ProgramMetadata, instructions::{ - execute_with_thread, extract_opcode, handle_invalid_op, instruction_length, - is_basic_block_end_instruction, Instruction, Register, Thread, ThreadFactory, + Instruction, Register, Thread, ThreadFactory, execute_with_thread, extract_opcode, + handle_invalid_op, instruction_length, is_basic_block_end_instruction, }, - Error, }, CoreMachine, DefaultMachine, DefaultMachineRunner, Machine, SupportMachine, VERSION2, }; diff --git a/src/memory/flat.rs b/src/memory/flat.rs index b7d6f541..c3440823 100644 --- a/src/memory/flat.rs +++ b/src/memory/flat.rs @@ -1,5 +1,5 @@ -use super::super::{error::OutOfBoundKind, Error, Register, RISCV_PAGESIZE, RISCV_PAGE_SHIFTS}; -use super::{check_no_overflow, fill_page_data, get_page_indices, memset, set_dirty, Memory}; +use super::super::{Error, RISCV_PAGE_SHIFTS, RISCV_PAGESIZE, Register, error::OutOfBoundKind}; +use super::{Memory, check_no_overflow, fill_page_data, get_page_indices, memset, set_dirty}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use bytes::Bytes; diff --git a/src/memory/mod.rs b/src/memory/mod.rs index d72349d0..382b430d 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -1,7 +1,7 @@ use super::{ + Error, RISCV_PAGESIZE, Register, bits::{rounddown, roundup}, error::OutOfBoundKind, - Error, Register, RISCV_PAGESIZE, }; use bytes::Bytes; use std::cmp::min; @@ -12,8 +12,8 @@ pub mod sparse; pub mod wxorx; pub use ckb_vm_definitions::{ - memory::{FLAG_DIRTY, FLAG_EXECUTABLE, FLAG_FREEZED, FLAG_WRITABLE, FLAG_WXORX_BIT}, DEFAULT_MEMORY_SIZE, MEMORY_FRAME_PAGE_SHIFTS, RISCV_PAGE_SHIFTS, + memory::{FLAG_DIRTY, FLAG_EXECUTABLE, FLAG_FREEZED, FLAG_WRITABLE, FLAG_WXORX_BIT}, }; #[inline(always)] diff --git a/src/memory/sparse.rs b/src/memory/sparse.rs index 8c4d54ba..50a5f0e0 100644 --- a/src/memory/sparse.rs +++ b/src/memory/sparse.rs @@ -1,5 +1,5 @@ -use super::super::{error::OutOfBoundKind, Error, Register, RISCV_PAGESIZE, RISCV_PAGE_SHIFTS}; -use super::{check_no_overflow, fill_page_data, memset, round_page_down, Memory, Page, FLAG_DIRTY}; +use super::super::{Error, RISCV_PAGE_SHIFTS, RISCV_PAGESIZE, Register, error::OutOfBoundKind}; +use super::{FLAG_DIRTY, Memory, Page, check_no_overflow, fill_page_data, memset, round_page_down}; use bytes::Bytes; use std::cmp::min; diff --git a/src/memory/wxorx.rs b/src/memory/wxorx.rs index e1993c25..9ae90619 100644 --- a/src/memory/wxorx.rs +++ b/src/memory/wxorx.rs @@ -1,7 +1,7 @@ -use super::super::{error::OutOfBoundKind, Error, Register, RISCV_PAGESIZE}; +use super::super::{Error, RISCV_PAGESIZE, Register, error::OutOfBoundKind}; use super::{ - check_no_overflow, check_permission, get_page_indices, round_page_down, round_page_up, Memory, - FLAG_EXECUTABLE, FLAG_FREEZED, FLAG_WRITABLE, + FLAG_EXECUTABLE, FLAG_FREEZED, FLAG_WRITABLE, Memory, check_no_overflow, check_permission, + get_page_indices, round_page_down, round_page_up, }; use bytes::Bytes; diff --git a/src/snapshot.rs b/src/snapshot.rs index ec42379d..4936cff3 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -1,7 +1,7 @@ use crate::instructions::Register; -use crate::memory::Memory; use crate::memory::FLAG_DIRTY; -use crate::{CoreMachine, Error, RISCV_GENERAL_REGISTER_NUMBER, RISCV_PAGESIZE, RISCV_PAGE_SHIFTS}; +use crate::memory::Memory; +use crate::{CoreMachine, Error, RISCV_GENERAL_REGISTER_NUMBER, RISCV_PAGE_SHIFTS, RISCV_PAGESIZE}; use serde::{Deserialize, Serialize}; // Snapshot provides a mechanism for suspending and resuming a virtual machine. diff --git a/src/snapshot2.rs b/src/snapshot2.rs index d5dd77d6..c20855a5 100644 --- a/src/snapshot2.rs +++ b/src/snapshot2.rs @@ -1,9 +1,9 @@ use crate::{ + Error, RISCV_GENERAL_REGISTER_NUMBER, RISCV_PAGESIZE, Register, bits::roundup, elf::{LoadingAction, ProgramMetadata}, machine::SupportMachine, - memory::{get_page_indices, Memory, FLAG_DIRTY}, - Error, Register, RISCV_GENERAL_REGISTER_NUMBER, RISCV_PAGESIZE, + memory::{FLAG_DIRTY, Memory, get_page_indices}, }; use bytes::Bytes; use serde::{Deserialize, Serialize}; diff --git a/tests/machine_build.rs b/tests/machine_build.rs index 00742108..37488597 100644 --- a/tests/machine_build.rs +++ b/tests/machine_build.rs @@ -2,7 +2,7 @@ use bytes::Bytes; use ckb_vm::cost_model::constant_cycles; #[cfg(has_asm)] use ckb_vm::machine::asm::{AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine}; -use ckb_vm::machine::{trace::TraceMachine, DefaultCoreMachine}; +use ckb_vm::machine::{DefaultCoreMachine, trace::TraceMachine}; use ckb_vm::registers::{A0, A7}; use ckb_vm::{ DefaultMachineRunner, Error, Register, RustDefaultMachineBuilder, SparseMemory, SupportMachine, diff --git a/tests/test_a_extension.rs b/tests/test_a_extension.rs index 1e8afe41..cfa7f568 100644 --- a/tests/test_a_extension.rs +++ b/tests/test_a_extension.rs @@ -1,6 +1,6 @@ -use ckb_vm::{machine::VERSION2, DefaultMachineRunner, Error, ISA_A, ISA_IMC}; #[cfg(has_asm)] use ckb_vm::{CoreMachine, Memory}; +use ckb_vm::{DefaultMachineRunner, Error, ISA_A, ISA_IMC, machine::VERSION2}; pub mod machine_build; #[test] diff --git a/tests/test_asm.rs b/tests/test_asm.rs index f6a8586b..05dffbf8 100644 --- a/tests/test_asm.rs +++ b/tests/test_asm.rs @@ -11,10 +11,10 @@ use ckb_vm::machine::asm::{ use ckb_vm::machine::{AbstractDefaultMachineBuilder, CoreMachine, VERSION0, VERSION1, VERSION2}; use ckb_vm::memory::Memory; use ckb_vm::registers::{A0, A1, A2, A3, A4, A5, A7}; -use ckb_vm::{Debugger, DefaultMachineRunner, Error, Register, SupportMachine, Syscalls, ISA_IMC}; +use ckb_vm::{Debugger, DefaultMachineRunner, Error, ISA_IMC, Register, SupportMachine, Syscalls}; use std::fs; -use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicU8, Ordering}; use std::thread; pub mod machine_build; diff --git a/tests/test_auipc_fusion.rs b/tests/test_auipc_fusion.rs index b8723a6e..17d739a8 100644 --- a/tests/test_auipc_fusion.rs +++ b/tests/test_auipc_fusion.rs @@ -1,13 +1,13 @@ use ckb_vm::decoder::{DefaultDecoder, InstDecoder}; use ckb_vm::instructions::{ - extract_opcode, instruction_length, set_instruction_length_n, Instruction, Utype, + Instruction, Utype, extract_opcode, instruction_length, set_instruction_length_n, }; -#[cfg(has_asm)] -use ckb_vm::machine::asm::{traces::SimpleFixedTraceDecoder, AbstractAsmMachine, AsmCoreMachine}; use ckb_vm::machine::VERSION1; +#[cfg(has_asm)] +use ckb_vm::machine::asm::{AbstractAsmMachine, AsmCoreMachine, traces::SimpleFixedTraceDecoder}; use ckb_vm::{ - machine::AbstractDefaultMachineBuilder, CoreMachine, DefaultCoreMachine, DefaultMachineRunner, - Error, Memory, Register, SparseMemory, SupportMachine, ISA_IMC, + CoreMachine, DefaultCoreMachine, DefaultMachineRunner, Error, ISA_IMC, Memory, Register, + SparseMemory, SupportMachine, machine::AbstractDefaultMachineBuilder, }; use ckb_vm_definitions::instructions as insts; use std::fs; diff --git a/tests/test_b_extension.rs b/tests/test_b_extension.rs index 346ee31f..78685e46 100644 --- a/tests/test_b_extension.rs +++ b/tests/test_b_extension.rs @@ -1,4 +1,4 @@ -use ckb_vm::{machine::VERSION1, ISA_B, ISA_IMC}; +use ckb_vm::{ISA_B, ISA_IMC, machine::VERSION1}; pub mod machine_build; diff --git a/tests/test_dy_memory.rs b/tests/test_dy_memory.rs index 81a83b2a..3dbbc635 100644 --- a/tests/test_dy_memory.rs +++ b/tests/test_dy_memory.rs @@ -1,12 +1,12 @@ -use ckb_vm::{error::OutOfBoundKind, run_with_memory, FlatMemory, SparseMemory}; #[cfg(has_asm)] use ckb_vm::{ + DefaultMachineRunner, ISA_B, ISA_IMC, ISA_MOP, SupportMachine, machine::{ - asm::{AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine}, VERSION0, VERSION2, + asm::{AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine}, }, - DefaultMachineRunner, SupportMachine, ISA_B, ISA_IMC, ISA_MOP, }; +use ckb_vm::{FlatMemory, SparseMemory, error::OutOfBoundKind, run_with_memory}; use std::fs; fn run_memory_suc(memory_size: usize, bin_path: String, bin_name: String) { diff --git a/tests/test_minimal.rs b/tests/test_minimal.rs index 7da3a881..62001a56 100644 --- a/tests/test_minimal.rs +++ b/tests/test_minimal.rs @@ -1,4 +1,4 @@ -use ckb_vm::{run, SparseMemory}; +use ckb_vm::{SparseMemory, run}; use std::fs; #[test] diff --git a/tests/test_misc.rs b/tests/test_misc.rs index dad1cb00..2fda049c 100644 --- a/tests/test_misc.rs +++ b/tests/test_misc.rs @@ -3,16 +3,16 @@ use ckb_vm::error::OutOfBoundKind; use ckb_vm::machine::{VERSION0, VERSION1, VERSION2}; use ckb_vm::registers::{A0, A1, A2, A3, A4, A5, A7}; use ckb_vm::{ - run, CoreMachine, Debugger, DefaultCoreMachine, DefaultMachineRunner, Error, FlatMemory, - Memory, Register, RustDefaultMachineBuilder, SparseMemory, SupportMachine, Syscalls, - WXorXMemory, DEFAULT_MEMORY_SIZE, ISA_B, ISA_IMC, RISCV_PAGESIZE, + CoreMachine, DEFAULT_MEMORY_SIZE, Debugger, DefaultCoreMachine, DefaultMachineRunner, Error, + FlatMemory, ISA_B, ISA_IMC, Memory, RISCV_PAGESIZE, Register, RustDefaultMachineBuilder, + SparseMemory, SupportMachine, Syscalls, WXorXMemory, run, }; #[cfg(has_asm)] use ckb_vm_definitions::asm::AsmCoreMachine; -use rand::{thread_rng, Rng}; +use rand::{Rng, thread_rng}; use std::fs; -use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicU8, Ordering}; pub mod machine_build; #[test] diff --git a/tests/test_mop.rs b/tests/test_mop.rs index 1cd39ab9..d84c9d8e 100644 --- a/tests/test_mop.rs +++ b/tests/test_mop.rs @@ -3,8 +3,8 @@ use bytes::Bytes; use ckb_vm::error::OutOfBoundKind; use ckb_vm::machine::{VERSION1, VERSION2}; use ckb_vm::{ - registers::A0, CoreMachine, DefaultMachineRunner, Error, SupportMachine, ISA_B, ISA_IMC, - ISA_MOP, + CoreMachine, DefaultMachineRunner, Error, ISA_B, ISA_IMC, ISA_MOP, SupportMachine, + registers::A0, }; #[test] @@ -165,7 +165,9 @@ pub fn test_mop_ld_32_constants() { pub fn test_mop_secp256k1() { let args = vec![ Bytes::from("033f8cf9c4d51a33206a6c1c6b27d2cc5129daa19dbd1fc148d395284f6b26411f"), - Bytes::from("304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3"), + Bytes::from( + "304402203679d909f43f073c7c1dcf8468a485090589079ee834e6eed92fea9b09b06a2402201e46f1075afa18f306715e7db87493e7b7e779569aa13c64ab3d09980b3560a3", + ), Bytes::from("foo"), Bytes::from("bar"), ]; diff --git a/tests/test_reset.rs b/tests/test_reset.rs index 3ec60c2f..f56765b1 100644 --- a/tests/test_reset.rs +++ b/tests/test_reset.rs @@ -4,8 +4,8 @@ use ckb_vm::cost_model::constant_cycles; use ckb_vm::machine::asm::{AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine}; use ckb_vm::machine::{DefaultCoreMachine, RustDefaultMachineBuilder, VERSION1}; use ckb_vm::{ - registers::A7, DefaultMachineRunner, Error, Register, SparseMemory, SupportMachine, Syscalls, - TraceMachine, WXorXMemory, DEFAULT_MEMORY_SIZE, ISA_IMC, ISA_MOP, + DEFAULT_MEMORY_SIZE, DefaultMachineRunner, Error, ISA_IMC, ISA_MOP, Register, SparseMemory, + SupportMachine, Syscalls, TraceMachine, WXorXMemory, registers::A7, }; #[allow(dead_code)] diff --git a/tests/test_resume.rs b/tests/test_resume.rs index d7b32626..d71d4e92 100644 --- a/tests/test_resume.rs +++ b/tests/test_resume.rs @@ -9,8 +9,8 @@ use ckb_vm::machine::{ VERSION2, }; use ckb_vm::memory::{sparse::SparseMemory, wxorx::WXorXMemory}; -use ckb_vm::snapshot::{make_snapshot, resume, Snapshot}; -use ckb_vm::{Error, RustDefaultMachineBuilder, ISA_A, ISA_IMC}; +use ckb_vm::snapshot::{Snapshot, make_snapshot, resume}; +use ckb_vm::{Error, ISA_A, ISA_IMC, RustDefaultMachineBuilder}; use std::fs::File; use std::io::Read; diff --git a/tests/test_resume2.rs b/tests/test_resume2.rs index dfcb1510..1031a586 100644 --- a/tests/test_resume2.rs +++ b/tests/test_resume2.rs @@ -1,6 +1,8 @@ #![cfg(has_asm)] pub mod machine_build; use bytes::Bytes; +#[allow(unused_imports)] +use ckb_vm::Memory; use ckb_vm::cost_model::constant_cycles; use ckb_vm::elf::parse_elf; use ckb_vm::machine::asm::{AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine}; @@ -12,9 +14,7 @@ use ckb_vm::machine::{ use ckb_vm::memory::{sparse::SparseMemory, wxorx::WXorXMemory}; use ckb_vm::registers::{A0, A1, A7}; use ckb_vm::snapshot2::{DataSource, Snapshot2, Snapshot2Context}; -#[allow(unused_imports)] -use ckb_vm::Memory; -use ckb_vm::{Error, Register, RustDefaultMachineBuilder, Syscalls, ISA_A, ISA_IMC}; +use ckb_vm::{Error, ISA_A, ISA_IMC, Register, RustDefaultMachineBuilder, Syscalls}; use std::collections::HashMap; use std::fs::File; use std::io::Read; @@ -542,8 +542,8 @@ impl Machine { #[cfg(not(feature = "enable-chaos-mode-by-default"))] fn full_memory(&mut self) -> Result { - use ckb_vm::DEFAULT_MEMORY_SIZE; use Machine::*; + use ckb_vm::DEFAULT_MEMORY_SIZE; match self { Asm(inner, _) => inner .machine diff --git a/tests/test_signal_pause.rs b/tests/test_signal_pause.rs index 1b20ce63..8b47a48f 100644 --- a/tests/test_signal_pause.rs +++ b/tests/test_signal_pause.rs @@ -1,7 +1,7 @@ use ckb_vm::machine::VERSION2; -use ckb_vm::{DefaultMachineRunner, Error, SupportMachine, ISA_B, ISA_IMC}; -use std::sync::atomic::{AtomicU32, Ordering}; +use ckb_vm::{DefaultMachineRunner, Error, ISA_B, ISA_IMC, SupportMachine}; use std::sync::Arc; +use std::sync::atomic::{AtomicU32, Ordering}; pub mod machine_build; #[cfg(has_asm)] @@ -30,16 +30,18 @@ pub fn test_asm_pause() { let branch_pause_cnt_jh = branch_pause_cnt.clone(); let signal = machine.machine.pause(); - let jh = std::thread::spawn(move || loop { - let result = machine.run(); - if result == Err(Error::Pause) { - branch_pause_cnt_jh.fetch_add(1, Ordering::SeqCst); - continue; - } else { - assert!(result.is_ok()); - assert_eq!(result.unwrap(), 0); - assert_eq!(machine.machine.cycles(), expect_cycles); - break; + let jh = std::thread::spawn(move || { + loop { + let result = machine.run(); + if result == Err(Error::Pause) { + branch_pause_cnt_jh.fetch_add(1, Ordering::SeqCst); + continue; + } else { + assert!(result.is_ok()); + assert_eq!(result.unwrap(), 0); + assert_eq!(machine.machine.cycles(), expect_cycles); + break; + } } }); for _ in 0..10 { @@ -72,16 +74,18 @@ pub fn test_int_pause() { let branch_pause_cnt = Arc::new(AtomicU32::new(0)); let branch_pause_cnt_jh = branch_pause_cnt.clone(); let signal = machine.machine.pause(); - let jh = std::thread::spawn(move || loop { - let result = machine.run(); - if result == Err(Error::Pause) { - branch_pause_cnt_jh.fetch_add(1, Ordering::SeqCst); - continue; - } else { - assert!(result.is_ok()); - assert_eq!(result.unwrap(), 0); - assert_eq!(machine.machine.cycles(), expect_cycles); - break; + let jh = std::thread::spawn(move || { + loop { + let result = machine.run(); + if result == Err(Error::Pause) { + branch_pause_cnt_jh.fetch_add(1, Ordering::SeqCst); + continue; + } else { + assert!(result.is_ok()); + assert_eq!(result.unwrap(), 0); + assert_eq!(machine.machine.cycles(), expect_cycles); + break; + } } }); for _ in 0..10 { diff --git a/tests/test_simple.rs b/tests/test_simple.rs index 132d14f7..ac9f3775 100644 --- a/tests/test_simple.rs +++ b/tests/test_simple.rs @@ -1,7 +1,7 @@ use ckb_vm::machine::VERSION0; use ckb_vm::{ - run, DefaultCoreMachine, DefaultMachineRunner, Error, FlatMemory, Instruction, - RustDefaultMachineBuilder, SparseMemory, SupportMachine, ISA_IMC, + DefaultCoreMachine, DefaultMachineRunner, Error, FlatMemory, ISA_IMC, Instruction, + RustDefaultMachineBuilder, SparseMemory, SupportMachine, run, }; use std::fs; diff --git a/tests/test_spawn.rs b/tests/test_spawn.rs index f126af33..36183538 100644 --- a/tests/test_spawn.rs +++ b/tests/test_spawn.rs @@ -2,12 +2,12 @@ use bytes::Bytes; use ckb_vm::cost_model::constant_cycles; #[cfg(has_asm)] use ckb_vm::machine::asm::{AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine}; -use ckb_vm::machine::{trace::TraceMachine, DefaultCoreMachine, VERSION2}; +use ckb_vm::machine::{DefaultCoreMachine, VERSION2, trace::TraceMachine}; use ckb_vm::memory::load_c_string_byte_by_byte; use ckb_vm::registers::{A0, A1, A2, A7}; use ckb_vm::{ - DefaultMachineRunner, Error, FlattenedArgsReader, Register, RustDefaultMachineBuilder, - SparseMemory, SupportMachine, Syscalls, WXorXMemory, ISA_B, ISA_IMC, ISA_MOP, + DefaultMachineRunner, Error, FlattenedArgsReader, ISA_B, ISA_IMC, ISA_MOP, Register, + RustDefaultMachineBuilder, SparseMemory, SupportMachine, Syscalls, WXorXMemory, }; use std::sync::{Arc, Mutex}; diff --git a/tests/test_versions.rs b/tests/test_versions.rs index 6a24d360..74703dd0 100644 --- a/tests/test_versions.rs +++ b/tests/test_versions.rs @@ -5,9 +5,9 @@ use ckb_vm::machine::asm::{AsmCoreMachine, AsmDefaultMachineBuilder, AsmMachine} use ckb_vm::machine::{VERSION0, VERSION1, VERSION2}; use ckb_vm::memory::{FLAG_DIRTY, FLAG_FREEZED}; use ckb_vm::{ - CoreMachine, DefaultCoreMachine, DefaultMachine, DefaultMachineRunner, Error, Memory, - RustDefaultMachineBuilder, SparseMemory, SupportMachine, TraceMachine, WXorXMemory, ISA_B, - ISA_IMC, ISA_MOP, RISCV_PAGESIZE, + CoreMachine, DefaultCoreMachine, DefaultMachine, DefaultMachineRunner, Error, ISA_B, ISA_IMC, + ISA_MOP, Memory, RISCV_PAGESIZE, RustDefaultMachineBuilder, SparseMemory, SupportMachine, + TraceMachine, WXorXMemory, }; use std::fs; From 2fea1c46eddce053cd57ef55de0e46f6cc42f299 Mon Sep 17 00:00:00 2001 From: mohanson Date: Mon, 31 Mar 2025 15:11:06 +0800 Subject: [PATCH 2/3] Make no_mangle unsafe --- src/machine/asm/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/machine/asm/mod.rs b/src/machine/asm/mod.rs index 7f555ef7..55e055e8 100644 --- a/src/machine/asm/mod.rs +++ b/src/machine/asm/mod.rs @@ -122,7 +122,7 @@ where // but consider that in the asm machine, `frame_index` is stored in `rdi` and `machine` // is stored in `rsi`, there is no need to exchange the values in the two registers // in this way. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn inited_memory(frame_index: u64, machine: &mut AsmCoreMachine) { let addr_from = (frame_index << MEMORY_FRAME_SHIFTS) as usize; let is_chaos_mode = machine.chaos_mode != 0; @@ -723,7 +723,7 @@ where } } -extern "C" { +unsafe extern "C" { pub fn ckb_vm_x64_execute(m: *mut AsmCoreMachine, d: *const InvokeData) -> c_uchar; // We are keeping this as a function here, but at the bottom level this really // just points to an array of assembly label offsets for each opcode. From 983e642babe328bdf95dd29072658524585f0eb8 Mon Sep 17 00:00:00 2001 From: mohanson Date: Mon, 31 Mar 2025 15:17:38 +0800 Subject: [PATCH 3/3] Fix clippy --- src/machine/asm/mod.rs | 4 ++-- src/machine/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/machine/asm/mod.rs b/src/machine/asm/mod.rs index 55e055e8..c9213de9 100644 --- a/src/machine/asm/mod.rs +++ b/src/machine/asm/mod.rs @@ -262,7 +262,7 @@ fn check_memory_inited( // permission checking struct FastMemory<'a>(&'a mut AsmCoreMachine); -impl<'a> FastMemory<'a> { +impl FastMemory<'_> { fn prepare_memory(&mut self, addr: u64, size: u64) -> Result<(), Error> { check_no_overflow(addr, size, self.0.memory_size)?; let frame_start = addr >> MEMORY_FRAME_SHIFTS << MEMORY_FRAME_SHIFTS; @@ -295,7 +295,7 @@ impl<'a> FastMemory<'a> { } } -impl<'a> Memory for FastMemory<'a> { +impl Memory for FastMemory<'_> { type REG = u64; fn new(_memory_size: usize) -> Self { diff --git a/src/machine/mod.rs b/src/machine/mod.rs index a4f04008..8c35bba8 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -878,7 +878,7 @@ impl<'a, M: Memory> FlattenedArgsReader<'a, M> { } } -impl<'a, M: Memory> Iterator for FlattenedArgsReader<'a, M> { +impl Iterator for FlattenedArgsReader<'_, M> { type Item = Result; fn next(&mut self) -> Option { @@ -907,7 +907,7 @@ impl<'a, M: Memory> Iterator for FlattenedArgsReader<'a, M> { } } -impl<'a, M: Memory> ExactSizeIterator for FlattenedArgsReader<'a, M> { +impl ExactSizeIterator for FlattenedArgsReader<'_, M> { fn len(&self) -> usize { self.argc.to_u64() as usize }