Skip to Content
Viewing release/v0.5.0-alpha.3 docs — not the stable branch. Changes vs main · Go to main

Maps and Helpers

Relevant source files

Map types

Four map types can be created at runtime through BPF_MAP_CREATE (BpfManager::create_map_for). Any other type value returns InvalidInstruction.

TypeValueConstraints at creationStorage and behaviour
Hash (BPF_MAP_TYPE_HASH)1non-zero key and value sizeOne flat buffer of state, key, value buckets with linear probing; fixed key and value sizes
Array (BPF_MAP_TYPE_ARRAY)2key size must be 4, non-zero value sizeContiguous value bytes indexed by u32
Ring buffer (BPF_MAP_TYPE_RINGBUF)27key size 0, value size 0, max_entries a power of two (it is the byte size)Reserve, submit and poll with an 8-byte event header; polling copies one committed event and advances the tail; nonblocking
Time series (BPF_MAP_TYPE_TIMESERIES)100key size 8 (a timestamp), non-zero value sizeCircular storage of timestamped fixed-size values

The kernel_bpf::maps::MapType enum names more types (prog array, per-CPU maps, stack trace, cgroup array, and cloud-only LRU hash, LRU per-CPU hash and LPM trie) so that ELF map definitions can be parsed, but the manager does not create them. The ABI catalog lists only the four above.

All constructors validate dimensions, use checked arithmetic for allocation sizes and reserve memory fallibly, returning MapError on invalid or exhausted requests. The resize operation exists only in cloud builds. Embedded constructors additionally reject any single map whose full allocation exceeds MEMORY_BUDGET (64 KiB). There is no static map pool.

Reserved envelope map

Handle 0 (ENVELOPE_MAP_ID) is a kernel-owned, read-only envelope map created at manager construction from the profile’s actuation constants. RESERVED_MAP_COUNT is 1, so user maps start after it. Mutating helpers on this handle are rejected by the verifier (read-only) and at runtime.

Kernel quotas (BpfLimits)

LimitCloudEmbedded
Live programs12832
Program slots1024128
Per-owner programs328
Total program bytes16 MiB2 MiB
Single program bytes1 MiB800 KiB
Per-owner program bytes4 MiB512 KiB
Max ELF bytes1 MiB1 MiB
Live maps6416
Map slots51264
Per-owner maps164
Total map bytes64 MiB64 KiB
Single map bytes16 MiB64 KiB
Per-owner map bytes16 MiB32 KiB
Pinned maps12832
Key size512256
Value size64 KiB4 KiB
Max entries1,048,5764096

Access and sharing

The verifier receives the caller’s authoritative view of map sizes, generations and permissions (MapPerm: Unavailable, ReadOnly, WriteOnly, ReadWrite), and ProgramRuntime retains only the maps a program references and is authorized to use. At run time helpers re-resolve the handle through the program’s captured map set and re-check access. During execution each map is leased (MapLease, up to 128 leases per execution); userspace mutation or destruction of a leased map fails rather than blocks. Pinning and cross-process grants are described in Trust Model.

Helper functions

Helper IDs are defined once in kernel_abi and mirrored by the verifier’s HelperId enum, which is also what the loader relocation table, the WCET cost table and the interpreter dispatch use. The loader source states the IDs are the kernel’s own runtime ABI, not the upstream Linux uapi numbering; rkBPF extensions start at 1000.

The table lists every ID in HelperId. “Runtime” says whether the interpreter implements it; the others are known to the verifier and signature table but return InvalidHelper if executed. Tier is the minimum caller tier (P = privileged). “Act.” marks helpers that require the actuation capability.

IDNamePurposeRuntimeTierNotes
1bpf_ktime_get_nsKernel time in nanosecondsyesany
2bpf_trace_printkLog a message to the kernel logyesanyMay log; not available on embedded; rejected on timer, GPIO and sched_switch hooks
3bpf_get_prandom_u32Pseudo-random 32-bit valuenoany
4bpf_get_smp_processor_idCurrent CPU IDnoany
5bpf_map_lookup_elemLook up a map element; returns a maybe-null value pointeryesany
6bpf_map_update_elemInsert or update an elementyesanyRequires writable map
7bpf_map_delete_elemDelete an elementyesanyRequires writable map
8bpf_ringbuf_outputCopy an event into a ring buffer mapyesanyRequires writable map
9bpf_timeseries_pushPush a timestamped value into a time-series mapyesanyRequires writable map
10bpf_get_current_pid_tgidCurrent PID and TGIDnoany
11bpf_get_current_uid_gidCurrent UID and GIDnoany
12bpf_get_current_commCurrent process command name into a stack buffernoany
13bpf_get_interrupt_latency_nsInterrupt latency stored in the contextyesany
14bpf_probe_readRead from an arbitrary address with safety checksnoP
15bpf_get_boot_time_msBoot time in milliseconds from the contextyesP
16bpf_get_kernel_heap_kbKernel heap usage in KiB from the contextyesP
17bpf_get_kernel_image_mbKernel image size in MiB from the contextyesP
40bpf_ringbuf_reserveReserve ring buffer space; returns a maybe-null pointernoanyNot available on embedded
41bpf_ringbuf_submitSubmit a reserved entrynoany
42bpf_ringbuf_discardDiscard a reserved entrynoany
1002bpf_sensor_last_timestampLast timestamp from a sensornoanyRelocatable by name
1003bpf_gpio_setSet a GPIO output levelyesanyAct.; passes through the actuation monitor
1004bpf_gpio_getRead a GPIO input levelyesanyReturns -1 on invalid pin or non-Pi 5 builds
1005bpf_pwm_writeWrite a PWM duty (pwm id 0 or 1, channel 1 or 2)yesanyAct.; guarded by the actuation monitor; link-owned motor channels are routed over the Shrike link
1006bpf_iio_readRead an IIO sensor valuenoany
1007bpf_can_sendSend a CAN messagenoanyAct.

Which helpers the ABI catalog advertises as supported: bpf_ktime_get_ns, bpf_trace_printk (cloud profile only), map lookup/update/delete, bpf_ringbuf_output, bpf_timeseries_push, bpf_get_interrupt_latency_ns, bpf_get_boot_time_ms, bpf_get_kernel_heap_kb, bpf_get_kernel_image_mb, and, on Raspberry Pi 5, bpf_gpio_set, bpf_gpio_get and bpf_pwm_write.

Argument checking

Each helper has a HelperSignature of up to five argument types (Scalar, PtrToMapKey, PtrToMapValue, PtrToStack, PtrToMem, MemSize, Const, ring buffer types, and others) and a return type (Integer, PtrToMapValueOrNull, PtrToAllocMemOrNull, Void). Pointer returns become maybe-null pointers whose accessible size comes from the map’s value size. Memory arguments paired with a size are bounds-checked against the pointed region.

Actuation

Actuation helpers (gpio_set, pwm_write, can_send) require both the verifier’s allow_actuation flag (from the process ACTUATE capability at load time) and, at runtime, the ARM-A monitor in kernel_bpf::actuation. The profile supplies the envelope: on embedded a PWM duty ceiling of 90 percent and a slew limit of 20 per 1 ms window; on cloud these are no-op bounds. A program’s authorization snapshot is stored with it, so later privilege changes do not widen an existing program. Kernel helpers bpf_gpio_toggle and bpf_gpio_set_output exist in kernel/src/bpf/helpers.rs but are explicitly not exposed to the BPF ABI.

The loader’s relocation table recognises only 17 helper names (see Loader); bpf_gpio_*, bpf_pwm_write, bpf_iio_read and bpf_can_send cannot be linked by name from an ELF and are called by numeric ID in the bundled demo. The kernel’s bpf_trace_printk implementation reads a NUL-terminated string from the pointer it is given.

Last updated on