Skip to content

Commit

Permalink
[bcc] fix for new bpf_attach_kprobe signature
Browse files Browse the repository at this point in the history
bcc changed the signature of bpf_attach_kprobe to accept a new argument:
`maxactive`, which determines the maximum limit of how many calls in
parallel a kretprobe attached to a kernel function can catch. The new
signature is not backwards compatible, thus our build broke. Since
there's no way to feature detect the existance of an argument in a
function using cmake, we use a function pointer with the long signature
and cast bpf_attach_kprobe to it. If we're on an older bcc version, the
last argument will be allocated in a register (according to the
platform's calling convention), but should be ignored inside the
function.

Ref: torvalds/linux@696ced4
Ref: iovisor/bcc#2224
Fixes: #453
  • Loading branch information
mmarchini committed Mar 13, 2019
1 parent 89eb329 commit 080bef8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/attached_probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,20 @@ void AttachedProbe::load_prog()
}
}

// XXX(mmarchini): bcc changed the signature of bpf_attach_kprobe, adding a new
// int parameter at the end. Since there's no reliable way to feature-detect
// this, we create a function pointer with the long signature and cast
// bpf_attach_kprobe to this function pointer. If we're on an older bcc
// version, bpf_attach_kprobe call will be augmented with an extra register
// being used for the last parameter, even though this register won't be used
// inside the function. Since the register won't be used this is kinda safe,
// although not ideal.
typedef int (*attach_probe_wrapper_signature)(int, enum bpf_probe_attach_type, const char*, const char*, uint64_t, int);

void AttachedProbe::attach_kprobe()
{
int perf_event_fd = bpf_attach_kprobe(progfd_, attachtype(probe_.type),
eventname().c_str(), probe_.attach_point.c_str(), 0);
int perf_event_fd = reinterpret_cast<attach_probe_wrapper_signature>(&bpf_attach_kprobe)(progfd_, attachtype(probe_.type),
eventname().c_str(), probe_.attach_point.c_str(), 0, 0);

if (perf_event_fd < 0) {
if (probe_.orig_name != probe_.name) {
Expand Down

0 comments on commit 080bef8

Please sign in to comment.