Struct solana_rbpf::syscalls::BpfTracePrintf [−][src]
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}; let mut result: Result = Ok(0); let memory_mapping = [MemoryRegion::default()]; BpfTracePrintf::call(&mut BpfTracePrintf {}, 0, 0, 1, 15, 32, &MemoryMapping::new(memory_mapping.to_vec(), &Config::default()), &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
impl RefUnwindSafe for BpfTracePrintf
impl Send for BpfTracePrintf
impl Sync for BpfTracePrintf
impl Unpin for BpfTracePrintf
impl UnwindSafe for BpfTracePrintf
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,