Skip to content

Commit

Permalink
Fix KFUNC_PROBE return value
Browse files Browse the repository at this point in the history
The KFUNC_PROBE macro is using "void" as return type, this is causing problems
in some tools that have a filtering enable that returns 0.

Reproducer: (Notice that it requires BTF support)

```
$ python opensnoop.py --pid 5
/virtual/main.c:33:21: error: void function '____kretfunc__do_sys_open' should not return a value [-Wreturn-type]
    if (pid != 5) { return 0; }
                    ^      ~
1 error generated.
...
```

Signed-off-by: Mauricio Vásquez <[email protected]>
  • Loading branch information
mauriciovasquezbernal authored and yonghong-song committed May 21, 2020
1 parent 74e66b4 commit 44e0f43
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/cc/export/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ int raw_tracepoint__##event(struct bpf_raw_tracepoint_args *ctx)
#define BPF_PROG(name, args...) \
int name(unsigned long long *ctx); \
__attribute__((always_inline)) \
static void ____##name(unsigned long long *ctx, ##args); \
static int ____##name(unsigned long long *ctx, ##args); \
int name(unsigned long long *ctx) \
{ \
_Pragma("GCC diagnostic push") \
Expand All @@ -1021,7 +1021,7 @@ int name(unsigned long long *ctx) \
_Pragma("GCC diagnostic pop") \
return 0; \
} \
static void ____##name(unsigned long long *ctx, ##args)
static int ____##name(unsigned long long *ctx, ##args)

#define KFUNC_PROBE(event, args...) \
BPF_PROG(kfunc__ ## event, args)
Expand Down
6 changes: 3 additions & 3 deletions tools/klockstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,17 @@ def stack_id_err(stack_id):
program_kfunc = """
KFUNC_PROBE(mutex_unlock, void *lock)
{
do_mutex_unlock_enter();
return do_mutex_unlock_enter();
}
KRETFUNC_PROBE(mutex_lock, void *lock, int ret)
{
do_mutex_lock_return();
return do_mutex_lock_return();
}
KFUNC_PROBE(mutex_lock, void *lock)
{
do_mutex_lock_enter(ctx, 3);
return do_mutex_lock_enter(ctx, 3);
}
"""
Expand Down
2 changes: 2 additions & 0 deletions tools/opensnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
data.ret = ret;
events.perf_submit(ctx, &data, sizeof(data));
return 0:
}
"""

Expand Down

0 comments on commit 44e0f43

Please sign in to comment.