BPFMap.GetValue(): panic: runtime error: cgo argument has Go pointer to Go pointer
Songrui625 opened this issue · comments
...
connStatsMap, err := bpfModule.GetMap("conn_stats")
if err != nil {
log.Fatal(err)
}
iter := connStatsMap.Iterator()
for iter.Next() {
keyBytes := iter.Key()
valBytes, err := connStatsMap.GetValue(unsafe.Pointer(&keyBytes))
if err != nil {
log.Fatal(err)
}
...
}
After go build
and I got results:
panic: runtime error: cgo argument has Go pointer to Go pointer
goroutine 1 [running]:
github.com/aquasecurity/libbpfgo.(*BPFMap).GetValue.func1(0x10000c000108030, 0x7f974c5e8328, 0x8)
/home/songrui.771/go/pkg/mod/github.com/aquasecurity/libbpfgo@v0.4.0-libbpf-1.0.0/libbpfgo.go:717 +0x39
github.com/aquasecurity/libbpfgo.(*BPFMap).GetValue(0xc000090000, 0xc00000e048)
/home/songrui.771/go/pkg/mod/github.com/aquasecurity/libbpfgo@v0.4.0-libbpf-1.0.0/libbpfgo.go:717 +0x70
main.main()
/home/songrui.771/codespace/demo/go/libbpfgo-demo/main.go:87 +0x630
Hi @Songrui625. It would be nice to know what you are trying to achieve. Could you also provide the whole code generating such an error?
In the meantime, you can take a look at these Iterator() examples:
Hi @Songrui625 . It would be nice to know what you are trying to achieve. Could you also provide the whole code generating such an error?
In the meantime, you can take a look at these Iterator() examples:
Hi @geyslan , I am trying to iterate all elements of the bpf hash map conn_stats
which key and value is an object of struct in c. The bpf program will be hooked to kprobe and update the bpf hash map conn_stats
dynamically. So I deserialize the bytes to the struct I want and print it.
Hi @Songrui625 . It would be nice to know what you are trying to achieve. Could you also provide the whole code generating such an error?
In the meantime, you can take a look at these Iterator() examples:Hi @geyslan , I am trying to iterate all elements of the bpf hash map
conn_stats
which key and value is an object of struct in c. The bpf program will be hooked to kprobe and update the bpf hash mapconn_stats
dynamically. So I deserialize the bytes to the struct I want and print it.
I didn't look at the comment of GetValue()
closely. I solved it by changing &keyBytes
to &keyBytes[0]
.
Thanks @geyslan