logo
pub struct BpfStrCmp {}
Expand description

C-like strcmp, return 0 if the strings are equal, and a non-null value otherwise.

Examples

use solana_rbpf::syscalls::{BpfStrCmp, Result};
use solana_rbpf::memory_region::{MemoryRegion, MemoryMapping};
use solana_rbpf::vm::{Config, SyscallObject};

let foo = "This is a string.";
let bar = "This is another sting.";
let va_foo = 0x100000000;
let va_bar = 0x200000000;
use solana_rbpf::user_error::UserError;

let mut result: Result = Ok(0);
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(vec![MemoryRegion::default(), MemoryRegion::new_from_slice(foo.as_bytes(), va_foo, 0, false)], &config).unwrap();
BpfStrCmp::call(&mut BpfStrCmp {}, va_foo, va_foo, 0, 0, 0, &memory_mapping, &mut result);
assert!(result.unwrap() == 0);
let mut result: Result = Ok(0);
let memory_mapping = MemoryMapping::new::<UserError>(vec![MemoryRegion::default(), MemoryRegion::new_from_slice(foo.as_bytes(), va_foo, 0, false), MemoryRegion::new_from_slice(bar.as_bytes(), va_bar, 0, false)], &config).unwrap();
BpfStrCmp::call(&mut BpfStrCmp {}, va_foo, va_bar, 0, 0, 0, &memory_mapping, &mut result);
assert!(result.unwrap() != 0);

Trait Implementations

Call the syscall function

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.