lizrice / learning-ebpf

Learning eBPF, published by O'Reilly - out now! Here's where you'll find a VM config for the examples, and more
https://www.amazon.com/Learning-eBPF-Programming-Observability-Networking/dp/1098135121
Apache License 2.0
1.19k stars 255 forks source link

Chapter 5: ksyscall build issue #22

Closed ayushman4 closed 1 year ago

ayushman4 commented 1 year ago

The chapter says ctx is available but it doesn't seem to be able to reference it. Also, any parameters added to BPF_KSYSCALL seems to throw an error.

make
clang \
    -target bpf \
        -D __TARGET_ARCH_x86 \
    -Wall \
    -O2 -g -o hello-buffer-config.bpf.o -c hello-buffer-config.bpf.c
hello-buffer-config.bpf.c:27:31: error: expected identifier
int BPF_KPROBE_SYSCALL(hello, const char *pathname)
                              ^
hello-buffer-config.bpf.c:36:59: error: use of undeclared identifier 'pathname'
   bpf_probe_read_user_str(&data.path, sizeof(data.path), pathname);
                                                          ^
hello-buffer-config.bpf.c:45:26: error: use of undeclared identifier 'ctx'
   bpf_perf_event_output(ctx, &output, BPF_F_CURRENT_CPU, &data, sizeof(data));   
                         ^
3 errors generated.
make: *** [Makefile:15: hello-buffer-config.bpf.o] Error 1
tonyliu666 commented 11 months ago

Hello, I am facing the same issues. If you have solved this problem, could you tell me how to solve this, thx!

Anna-Katona commented 9 months ago

Hello, I am facing the same issues. If you have solved this problem, could you tell me how to solve this, thx!

sudo apt install -t sid libbpf-dev was suggested in https://github.com/lizrice/learning-ebpf/issues/12#issuecomment-1566825387