foniod/redbpf

printk macro why not use {}

Closed this issue · 1 comments

in rust world, format!, println! or log::info!, all of them use {}, why printk! use %llu %d?

Well for once, those functions all use std::fmt internally, which we do not have access to as eBPF programs work without stdlib, so you can't just proxy.

Next, you have to recall that in eBPF, we do not have access to any (standard) memory allocation mechanisms (only limited size stack and some map trickery), so working with arbitrary size data is not possible. You would have to write a very limited emulation of the format! macro.

What printk! does internally, it just calls the kernel's printk function (plus some safety checks). And %llu, %d etc all happen to be the syntax used by the kernel: https://www.kernel.org/doc/Documentation/printk-formats.txt