Struct solana_rbpf::syscalls::BpfTracePrintf[][src]

pub struct BpfTracePrintf {}

Prints its last three arguments to standard output. The first two arguments are unused. Returns the number of bytes written.

By ignoring the first two arguments, it creates a syscall that will have a behavior similar to the one of the equivalent syscall bpf_trace_printk() from Linux kernel.

Examples

use solana_rbpf::syscalls::{BpfTracePrintf, Result};
use solana_rbpf::memory_region::{MemoryRegion, MemoryMapping};
use solana_rbpf::vm::{Config, SyscallObject};
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()], &config).unwrap();
BpfTracePrintf::call(&mut BpfTracePrintf {}, 0, 0, 1, 15, 32, &memory_mapping, &mut result);
assert_eq!(result.unwrap() as usize, "BpfTracePrintf: 0x1, 0xf, 0x20\n".len());

This will print BpfTracePrintf: 0x1, 0xf, 0x20.

The eBPF code needed to perform the call in this example would be nearly identical to the code obtained by compiling the following code from C to eBPF with clang:

#include <linux/bpf.h>
#include "path/to/linux/samples/bpf/bpf_syscalls.h"

int main(struct __sk_buff *skb)
{
    // Only %d %u %x %ld %lu %lx %lld %llu %llx %p %s conversion specifiers allowed.
    // See <https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/kernel/trace/bpf_trace.c>.
    char *fmt = "bpf_trace_printk %llx, %llx, %llx\n";
    return bpf_trace_printk(fmt, sizeof(fmt), 1, 15, 32);
}

This would equally print the three numbers in /sys/kernel/debug/tracing file each time the program is run.

Trait Implementations

impl SyscallObject<UserError> for BpfTracePrintf[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,