Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions link/kprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ func (ko *KprobeOptions) cookie() uint64 {
return ko.Cookie
}

// SyscallWrapper returns the platform-specific kernel wrapper symbol for syscall.
func SyscallWrapper(syscall string) string {
prefix := linux.PlatformPrefix()
if prefix == "" || strings.HasPrefix(syscall, prefix) {
return syscall
}

return prefix + syscall
}

// Kprobe attaches the given eBPF program to a perf event that fires when the
// given kernel symbol starts executing. See /proc/kallsyms for available
// symbols. For example, printk():
Expand Down
4 changes: 1 addition & 3 deletions link/kprobe_multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/features"
"github.com/cilium/ebpf/internal/linux"
"github.com/cilium/ebpf/internal/testutils"
"github.com/cilium/ebpf/internal/unix"
)
Expand Down Expand Up @@ -127,9 +126,8 @@ func TestKprobeMultiProgramCall(t *testing.T) {

// Use actual syscall names with platform prefix.
// For simplicity, just assert the increment happens with any symbol in the array.
prefix := linux.PlatformPrefix()
opts := KprobeMultiOptions{
Symbols: []string{prefix + "sys_getpid", prefix + "sys_gettid"},
Symbols: []string{SyscallWrapper("sys_getpid"), SyscallWrapper("sys_gettid")},
}
km, err := KprobeMulti(p, opts)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions link/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/asm"
"github.com/cilium/ebpf/internal/linux"
"github.com/cilium/ebpf/internal/testutils"
"github.com/cilium/ebpf/internal/tracefs"
"github.com/cilium/ebpf/internal/unix"
Expand All @@ -27,6 +28,17 @@ var symTests = []string{
"unregister_kprobes.part.0", // function body that was split and partially inlined
}

func TestSyscallWrapper(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically a copy of the helper logic itself, that makes this test a little unnecessary. It's already being exercised in TestKprobeMultiProgramCall, that's fine.

prefix := linux.PlatformPrefix()

qt.Assert(t, qt.Equals(SyscallWrapper("sys_getpid"), prefix+"sys_getpid"))

if prefix != "" {
wrapped := prefix + "sys_getpid"
qt.Assert(t, qt.Equals(SyscallWrapper(wrapped), wrapped))
}
}

func TestKprobe(t *testing.T) {
prog := mustLoadProgram(t, ebpf.Kprobe, 0, "")

Expand Down
Loading