pub fn bind_syscall_context_object(
        &mut self,
        syscall_context_object: Box<dyn SyscallObject<E> + 'a>,
        hash: Option<u32>,
    ) -> Result<(), EbpfError<E>> {
        let fat_ptr: DynTraitFatPointer = unsafe { std::mem::transmute(&*syscall_context_object) };
        let syscall_registry = self.executable.get_syscall_registry();
        let slot = match hash {
            Some(hash) => {
                syscall_registry
                    .lookup_syscall(hash)
                    .unwrap()
                    .context_object_slot
            }
            None => syscall_registry
                .lookup_context_object_slot(fat_ptr.vtable.methods[0] as u64)
                .unwrap(),
        };
        if !self.syscall_context_objects[SYSCALL_CONTEXT_OBJECTS_OFFSET + slot].is_null() {
            Err(EbpfError::SycallAlreadyBound)
        } else {
            self.syscall_context_objects[SYSCALL_CONTEXT_OBJECTS_OFFSET + slot] = fat_ptr.data;
            // Keep the dyn trait objects so that they can be dropped properly later
            self.syscall_context_object_pool
                .push(syscall_context_object);
            Ok(())
        }
    }
/// Bind a context object instance to a previously registered syscall
///
/// # Examples
///
/// ```
/// use solana_rbpf::{vm::{Config, Executable, EbpfVm, SyscallObject, SyscallRegistry, DefaultInstructionMeter}, syscalls::BpfTracePrintf, user_error::UserError};
///
/// // This program was compiled with clang, from a C program containing the following single
/// // instruction: `return bpf_trace_printk("foo %c %c %c\n", 10, 1, 2, 3);`
/// let prog = &[
///     0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // load 0 as u64 into r1 (That would be
///     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // replaced by tc by the address of
///                                                     // the format string, in the .map
///                                                     // section of the ELF file).
///     0xb7, 0x02, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, // mov r2, 10
///     0xb7, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // mov r3, 1
///     0xb7, 0x04, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // mov r4, 2
///     0xb7, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // mov r5, 3
///     0x85, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, // call syscall with key 6
///     0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  // exit
/// ];
///
/// // Register a syscall.
/// // On running the program this syscall will print the content of registers r3, r4 and r5 to
/// // standard output.
/// let mut syscall_registry = SyscallRegistry::default();
/// syscall_registry.register_syscall_by_hash(6, BpfTracePrintf::call).unwrap();
/// // Instantiate an Executable and VM
/// let mut executable = Executable::<UserError, DefaultInstructionMeter>::from_text_bytes(prog, None, Config::default()).unwrap();
/// executable.set_syscall_registry(syscall_registry);
/// let mut vm = EbpfVm::<UserError, DefaultInstructionMeter>::new(executable.as_ref(), &mut [], &[]).unwrap();
/// // Bind a context object instance to the previously registered syscall
/// vm.bind_syscall_context_object(Box::new(BpfTracePrintf {}), None);
/// ```
Bind a context object instance to a previously registered syscall
Bind a context object instance to a previously registered syscall
pub fn bind_syscall_context_object(
        &mut self,
        syscall_context_object: Box<dyn SyscallObject<E> + 'a>,
        hash: Option<u32>,
    ) -> Result<(), EbpfError<E>> {
        let fat_ptr: DynTraitFatPointer = unsafe { std::mem::transmute(&*syscall_context_object) };
        let syscall_registry = self.executable.get_syscall_registry();
        let slot = match hash {
            Some(hash) => {
                syscall_registry
                    .lookup_syscall(hash)
                    .unwrap()
                    .context_object_slot
            }
            None => syscall_registry
                .lookup_context_object_slot(fat_ptr.vtable.methods[0] as u64)
                .unwrap(),
        };
        if !self.syscall_context_objects[SYSCALL_CONTEXT_OBJECTS_OFFSET + slot].is_null() {
            Err(EbpfError::SycallAlreadyBound)
        } else {
            self.syscall_context_objects[SYSCALL_CONTEXT_OBJECTS_OFFSET + slot] = fat_ptr.data;
            // Keep the dyn trait objects so that they can be dropped properly later
            self.syscall_context_object_pool
                .push(syscall_context_object);
            Ok(())
        }
    }
pub fn bind_syscall_context_object ( & mut self , syscall_context_object : Box < dyn SyscallObject < E > + ' a > , hash : Option < u32 > , ) -> Result < ( ) , EbpfError < E > > { let fat_ptr : DynTraitFatPointer = unsafe { std :: mem :: transmute ( & * syscall_context_object ) } ; let syscall_registry = self . executable . get_syscall_registry ( ) ; let slot = match hash { Some ( hash ) => { syscall_registry . lookup_syscall ( hash ) . unwrap ( ) . context_object_slot } None => syscall_registry . lookup_context_object_slot ( fat_ptr . vtable . methods [ 0 ] as u64 ) . unwrap ( ) , } ; if ! self . syscall_context_objects [ SYSCALL_CONTEXT_OBJECTS_OFFSET + slot ] . is_null ( ) { Err ( EbpfError :: SycallAlreadyBound ) } else { self . syscall_context_objects [ SYSCALL_CONTEXT_OBJECTS_OFFSET + slot ] = fat_ptr . data ; // Keep the dyn trait objects so that they can be dropped properly later self . syscall_context_object_pool . push ( syscall_context_object ) ; Ok ( ( ) ) } }
Bind a context object instance to a previously registered syscall
Bind a context object instance to a previously registered syscall
&mut self
syscall_context_object
Box<dyn SyscallObject<E> + 'a>
hash
Option<u32>
examples
```
use solana_rbpf::{vm::{Config, Executable, EbpfVm, SyscallObject, SyscallRegistry, DefaultInstructionMeter}, syscalls::BpfTracePrintf, user_error::UserError}.

This program was compiled with clang, from a C program containing the following single
instruction: `return bpf_trace_printk("foo %c %c %c\n", 10, 1, 2, 3);`
let prog = &[
0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // load 0 as u64 into r1 (That would be
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // replaced by tc by the address of
the format string, in the .map
section of the ELF file).

Register a syscall.
On running the program this syscall will print the content of registers r3, r4 and r5 to
standard output.
let mut syscall_registry = SyscallRegistry::default();
syscall_registry.register_syscall_by_hash(6, BpfTracePrintf::call).unwrap();
Instantiate an Executable and VM
let mut executable = Executable::::from_text_bytes(prog, None, Config::default()).unwrap();
executable.set_syscall_registry(syscall_registry);
let mut vm = EbpfVm::::new(executable.as_ref(), &mut [], &[]).unwrap();
Bind a context object instance to the previously registered syscall
vm.bind_syscall_context_object(Box::new(BpfTracePrintf {}), None);
```
` ` ` use solana_rbpf :: { vm :: { Config Executable EbpfVm SyscallObject SyscallRegistry DefaultInstructionMeter } syscalls :: BpfTracePrintf user_error :: UserError } . This program was compiled with clang from a C program containing the following single instruction : ` return bpf_trace_printk ( " foo %c %c %c \ n " 10 1 2 3 ) ; ` let prog = & [ 0x18 0x01 0x00 0x00 0x00 0x00 0x00 0x00 // load 0 as u64 into r1 ( That would be 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 // replaced by tc by the address of the format string in the . map section of the ELF file ) . Register a syscall . On running the program this syscall will print the content of registers r3 r4 and r5 to standard output . let mut syscall_registry = SyscallRegistry :: default () ; syscall_registry . register_syscall_by_hash ( 6 BpfTracePrintf :: call ) . unwrap () ; Instantiate an Executable and VM let mut executable = Executable :::: from_text_bytes ( prog None Config :: default () ) . unwrap () ; executable . set_syscall_registry ( syscall_registry ) ; let mut vm = EbpfVm :::: new ( executable . as_ref () &mut [] & [] ) . unwrap () ; Bind a context object instance to the previously registered syscall vm . bind_syscall_context_object ( Box :: new ( BpfTracePrintf {} ) None ) ; ` ` `