Expand description
This module implements some built-in helpers that can be called from within an eBPF program.
These helpers may originate from several places:
- Some of them mimic the helpers available in the Linux kernel.
- Some of them were proposed as example helpers in uBPF and they were adapted here.
- Other helpers may be specific to rbpf.
The prototype for helpers is always the same: five u64
as arguments, and a u64
as a return
value. Hence some helpers have unused arguments, or return a 0 value in all cases, in order to
respect this convention.
Constants§
- BPF_
KTIME_ GETNS_ IDX - Index of helper
bpf_ktime_getns()
, equivalent tobpf_time_getns()
, in Linux kernel, see https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/bpf.h. - BPF_
TRACE_ PRINTK_ IDX - Index of helper
bpf_trace_printk()
, equivalent tobpf_trace_printf()
, in Linux kernel, see https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/bpf.h.
Functions§
- bpf_
time_ getns - Get monotonic time (since boot time) in nanoseconds. All arguments are unused.
- bpf_
trace_ printf - Prints its last three arguments to standard output. The first two arguments are unused. Returns the number of bytes written.
- gather_
bytes - The idea is to assemble five bytes into a single
u64
. For compatibility with the helpers API, each argument must be au64
. - memfrob
- Same as
void *memfrob(void *s, size_t n);
instring.h
in C. See the GNU manual page (in section 3) formemfrob
. The memory is directly modified, and the helper returns 0 in all cases. Arguments 3 to 5 are unused. - rand
- Returns a random u64 value comprised between
min
andmax
values (inclusive). Arguments 3 to 5 are unused. - sqrti
- Compute and return the square root of argument 1, cast as a float. Arguments 2 to 5 are unused.
- strcmp
- C-like
strcmp
, return 0 if the strings are equal, and a non-null value otherwise.