From b224e2ef31ff2630c344dc91437ff20f000db13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Juli=C3=A1n?= Date: Tue, 10 Sep 2024 20:33:10 +0200 Subject: [PATCH] [EBPF] Replace generated pointers to structs with uintptr (#29221) --- pkg/ebpf/cgo/genpost.go | 4 ++++ pkg/network/ebpf/kprobe_types_linux.go | 8 ++++---- tasks/system_probe.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/ebpf/cgo/genpost.go b/pkg/ebpf/cgo/genpost.go index 62863734b35f24..512d0542c62d92 100644 --- a/pkg/ebpf/cgo/genpost.go +++ b/pkg/ebpf/cgo/genpost.go @@ -44,6 +44,10 @@ func main() { convertInt8ArrayToByteArrayRegex := regexp.MustCompile(`(` + strings.Join(int8variableNames, "|") + `)(\s+)\[(\d+)\]u?int8`) b = convertInt8ArrayToByteArrayRegex.ReplaceAll(b, []byte("$1$2[$3]byte")) + // Convert generated pointers to CGo structs to uintptr + convertPointerToUint64Regex := regexp.MustCompile(`\*_Ctype_struct_(\w+)`) + b = convertPointerToUint64Regex.ReplaceAll(b, []byte("uintptr")) + b, err = format.Source(b) if err != nil { log.Fatal(err) diff --git a/pkg/network/ebpf/kprobe_types_linux.go b/pkg/network/ebpf/kprobe_types_linux.go index 63dd4b4c6e3933..7916d343dcd109 100644 --- a/pkg/network/ebpf/kprobe_types_linux.go +++ b/pkg/network/ebpf/kprobe_types_linux.go @@ -77,12 +77,12 @@ type PIDFD struct { Fd uint32 } type UDPRecvSock struct { - Sk *_Ctype_struct_sock - Msg *_Ctype_struct_msghdr + Sk uintptr + Msg uintptr } type BindSyscallArgs struct { - Addr *_Ctype_struct_sockaddr - Sk *_Ctype_struct_sock + Addr uintptr + Sk uintptr } type ProtocolStack struct { Api uint8 diff --git a/tasks/system_probe.py b/tasks/system_probe.py index 2c92a7aa33b31c..da7d6fbe451677 100644 --- a/tasks/system_probe.py +++ b/tasks/system_probe.py @@ -516,7 +516,7 @@ def ninja_cgo_type_files(nw: NinjaWriter): inputs=[f], outputs=[os.path.join(in_dir, out_file)], rule="godefs", - implicit=headers, + implicit=headers + [script_path], variables={ "in_dir": in_dir, "in_file": in_file,