Skip to content

Commit

Permalink
Automatically compute sizeof in bpf_trace_printk
Browse files Browse the repository at this point in the history
* Addresses issue iovisor#61

Signed-off-by: Brenden Blanco <[email protected]>
  • Loading branch information
Brenden Blanco committed Jun 17, 2015
1 parent 7679a2e commit 71c3638
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions examples/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

prog = """
int hello(void *ctx) {
char fmt[] = "Hello, World!\\n";
bpf_trace_printk(fmt, sizeof(fmt));
bpf_trace_printk("Hello, World!\\n");
return 0;
};
"""
Expand Down
4 changes: 3 additions & 1 deletion src/cc/export/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ static int (*bpf_probe_read)(void *dst, u64 size, void *unsafe_ptr) =
(void *) BPF_FUNC_probe_read;
static u64 (*bpf_ktime_get_ns)(void) =
(void *) BPF_FUNC_ktime_get_ns;
static int (*bpf_trace_printk)(const char *fmt, u64 fmt_size, ...) =
static int (*bpf_trace_printk_)(const char *fmt, u64 fmt_size, ...) =
(void *) BPF_FUNC_trace_printk;
#define bpf_trace_printk(_fmt, ...) \
({ char fmt[] = _fmt; bpf_trace_printk_(fmt, sizeof(fmt), ##__VA_ARGS__); })
static u64 (*bpf_clone_redirect)(void *ctx, u64 ifindex, u64 flags) =
(void *) BPF_FUNC_clone_redirect;
static void bpf_tail_call_(u64 map_fd, void *ctx, int index) {
Expand Down

0 comments on commit 71c3638

Please sign in to comment.