pub fn new(
        executable: &'a dyn Executable<E, I>,
        mem: &mut [u8],
        granted_regions: &[MemoryRegion],
    ) -> Result<EbpfVm<'a, E, I>, EbpfError<E>> {
        let config = executable.get_config();
        let const_data_regions: Vec<MemoryRegion> =
            if let Ok(sections) = executable.get_ro_sections() {
                sections
                    .iter()
                    .map(|(addr, slice)| MemoryRegion::new_from_slice(slice, *addr, 0, false))
                    .collect()
            } else {
                Vec::new()
            };
        let mut regions: Vec<MemoryRegion> =
            Vec::with_capacity(granted_regions.len() + const_data_regions.len() + 3);
        regions.extend(granted_regions.iter().cloned());
        let frames = CallFrames::new(config.max_call_depth, config.stack_frame_size);
        regions.push(frames.get_region().clone());
        regions.extend(const_data_regions);
        regions.push(MemoryRegion::new_from_slice(
            &mem,
            ebpf::MM_INPUT_START,
            0,
            true,
        ));
        let (program_vm_addr, program) = executable.get_text_bytes()?;
        regions.push(MemoryRegion::new_from_slice(
            program,
            program_vm_addr,
            0,
            false,
        ));
        let number_of_syscalls = executable.get_syscall_registry().get_number_of_syscalls();
        let mut vm = EbpfVm {
            executable,
            program,
            program_vm_addr,
            memory_mapping: MemoryMapping::new(regions, &config),
            tracer: Tracer::default(),
            syscall_context_objects: vec![
                std::ptr::null_mut();
                SYSCALL_CONTEXT_OBJECTS_OFFSET + number_of_syscalls
            ],
            syscall_context_object_pool: Vec::with_capacity(number_of_syscalls),
            frames,
            last_insn_count: 0,
            total_insn_count: 0,
        };
        unsafe {
            libc::memcpy(
                vm.syscall_context_objects.as_mut_ptr() as _,
                std::mem::transmute::<_, _>(&vm.memory_mapping),
                std::mem::size_of::<MemoryMapping>(),
            );
        }
        Ok(vm)
    }
/// Create a new virtual machine instance, and load an eBPF program into that instance.
/// When attempting to load the program, it passes through a simple verifier.
///
/// # Examples
///
/// ```
/// use solana_rbpf::{vm::{Config, Executable, EbpfVm, DefaultInstructionMeter}, user_error::UserError};
///
/// let prog = &[
///     0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  // exit
/// ];
///
/// // Instantiate a VM.
/// let executable = Executable::<UserError, DefaultInstructionMeter>::from_text_bytes(prog, None, Config::default()).unwrap();
/// let mut vm = EbpfVm::<UserError, DefaultInstructionMeter>::new(executable.as_ref(), &mut [], &[]).unwrap();
/// ```
Create a new virtual machine instance, and load an eBPF program into that instance.
When attempting to load the program, it passes through a simple verifier.
Create a new virtual machine instance and load an eBPF program into that instance . When attempting to load the program it passes through a simple verifier .
pub fn new(
        executable: &'a dyn Executable<E, I>,
        mem: &mut [u8],
        granted_regions: &[MemoryRegion],
    ) -> Result<EbpfVm<'a, E, I>, EbpfError<E>> {
        let config = executable.get_config();
        let const_data_regions: Vec<MemoryRegion> =
            if let Ok(sections) = executable.get_ro_sections() {
                sections
                    .iter()
                    .map(|(addr, slice)| MemoryRegion::new_from_slice(slice, *addr, 0, false))
                    .collect()
            } else {
                Vec::new()
            };
        let mut regions: Vec<MemoryRegion> =
            Vec::with_capacity(granted_regions.len() + const_data_regions.len() + 3);
        regions.extend(granted_regions.iter().cloned());
        let frames = CallFrames::new(config.max_call_depth, config.stack_frame_size);
        regions.push(frames.get_region().clone());
        regions.extend(const_data_regions);
        regions.push(MemoryRegion::new_from_slice(
            &mem,
            ebpf::MM_INPUT_START,
            0,
            true,
        ));
        let (program_vm_addr, program) = executable.get_text_bytes()?;
        regions.push(MemoryRegion::new_from_slice(
            program,
            program_vm_addr,
            0,
            false,
        ));
        let number_of_syscalls = executable.get_syscall_registry().get_number_of_syscalls();
        let mut vm = EbpfVm {
            executable,
            program,
            program_vm_addr,
            memory_mapping: MemoryMapping::new(regions, &config),
            tracer: Tracer::default(),
            syscall_context_objects: vec![
                std::ptr::null_mut();
                SYSCALL_CONTEXT_OBJECTS_OFFSET + number_of_syscalls
            ],
            syscall_context_object_pool: Vec::with_capacity(number_of_syscalls),
            frames,
            last_insn_count: 0,
            total_insn_count: 0,
        };
        unsafe {
            libc::memcpy(
                vm.syscall_context_objects.as_mut_ptr() as _,
                std::mem::transmute::<_, _>(&vm.memory_mapping),
                std::mem::size_of::<MemoryMapping>(),
            );
        }
        Ok(vm)
    }
pub fn new ( executable : & ' a dyn Executable < E , I > , mem : & mut [ u8 ] , granted_regions : & [ MemoryRegion ] , ) -> Result < EbpfVm < ' a , E , I > , EbpfError < E > > { let config = executable . get_config ( ) ; let const_data_regions : Vec < MemoryRegion > = if let Ok ( sections ) = executable . get_ro_sections ( ) { sections . iter ( ) . map ( | ( addr , slice ) | MemoryRegion :: new_from_slice ( slice , * addr , 0 , false ) ) . collect ( ) } else { Vec :: new ( ) } ; let mut regions : Vec < MemoryRegion > = Vec :: with_capacity ( granted_regions . len ( ) + const_data_regions . len ( ) + 3 ) ; regions . extend ( granted_regions . iter ( ) . cloned ( ) ) ; let frames = CallFrames :: new ( config . max_call_depth , config . stack_frame_size ) ; regions . push ( frames . get_region ( ) . clone ( ) ) ; regions . extend ( const_data_regions ) ; regions . push ( MemoryRegion :: new_from_slice ( & mem , ebpf :: MM_INPUT_START , 0 , true , ) ) ; let ( program_vm_addr , program ) = executable . get_text_bytes ( ) ? ; regions . push ( MemoryRegion :: new_from_slice ( program , program_vm_addr , 0 , false , ) ) ; let number_of_syscalls = executable . get_syscall_registry ( ) . get_number_of_syscalls ( ) ; let mut vm = EbpfVm { executable , program , program_vm_addr , memory_mapping : MemoryMapping :: new ( regions , & config ) , tracer : Tracer :: default ( ) , syscall_context_objects : vec ! [ std ptr null_mut ( ) SYSCALL_CONTEXT_OBJECTS_OFFSET number_of_syscalls ] , syscall_context_object_pool : Vec :: with_capacity ( number_of_syscalls ) , frames , last_insn_count : 0 , total_insn_count : 0 , } ; unsafe { libc :: memcpy ( vm . syscall_context_objects . as_mut_ptr ( ) as _ , std :: mem :: transmute :: < _ , _ > ( & vm . memory_mapping ) , std :: mem :: size_of :: < MemoryMapping > ( ) , ) ; } Ok ( vm ) }
Create a new virtual machine instance, and load an eBPF program into that instance.
Create a new virtual machine instance and load an eBPF program into that instance .
executable
&'a dyn Executable<E, I>
mem
&mut [u8]
granted_regions
&[MemoryRegion]
examples
```
use solana_rbpf::{vm::{Config, Executable, EbpfVm, DefaultInstructionMeter}, user_error::UserError}.



Instantiate a VM.
let executable = Executable::::from_text_bytes(prog, None, Config::default()).unwrap();
let mut vm = EbpfVm::::new(executable.as_ref(), &mut [], &[]).unwrap();
```
` ` ` use solana_rbpf :: { vm :: { Config Executable EbpfVm DefaultInstructionMeter } user_error :: UserError } . Instantiate a VM . let executable = Executable :::: from_text_bytes ( prog None Config :: default () ) . unwrap () ; let mut vm = EbpfVm :::: new ( executable . as_ref () &mut [] & [] ) . unwrap () ; ` ` `