From 3ec8b2a55ea7929d15c1578d689376795cdf1ab8 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 6 Feb 2024 09:49:42 +0200 Subject: cann recv a string from the kernel to userland --- main.bpf.c | 15 ++------------- main.go | 12 +----------- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/main.bpf.c b/main.bpf.c index 3c8a928..df20264 100644 --- a/main.bpf.c +++ b/main.bpf.c @@ -25,19 +25,8 @@ struct { SEC("kprobe/sys_mmap") int kprobe__sys_mmap(struct pt_regs *ctx) { - u32 firstKey = 1; - struct value *v1 = bpf_map_lookup_elem(&tester, &firstKey); - if (!v1) { - return 1; - } - bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, v1, sizeof(struct value)); - - s64 secondKey = 42069420; - struct value *v2 = bpf_map_lookup_elem(&tester, &secondKey); - if (!v2) { - return 1; - } - bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, v2, sizeof(char) * 3); + char *foo = "foo"; + bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, foo, sizeof(char) * 3); return 0; } diff --git a/main.go b/main.go index 23301b0..77fe40d 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,6 @@ import ( "time" "unsafe" - "encoding/binary" "fmt" "syscall" @@ -104,16 +103,7 @@ func main() { }() ev := <-eventsChannel - if binary.LittleEndian.Uint32(ev) != 50 { - fmt.Fprintf(os.Stderr, "invalid data retrieved\n") - os.Exit(-1) - } - - ev = <-eventsChannel - if ev[0] != value2[0] || ev[1] != value2[1] || ev[2] != value2[2] { - fmt.Fprintf(os.Stderr, "invalid data retrieved\n") - os.Exit(-1) - } + fmt.Println("Received ", string(ev)) pb.Stop() pb.Close() -- cgit v1.2.3