-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtracewrapper.h
46 lines (32 loc) · 1.49 KB
/
tracewrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <linux/version.h>
#include <linux/kallsyms.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)
extern uint64_t kallsyms_lookup_name_address;
#define kallsyms_lookup_name ((unsigned long(*)(const char *))kallsyms_lookup_name_address)
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0)
#define register_tracepoint_wrapper(tp, func, ctx) \
register_trace_ ## tp(func, ctx)
#define unregister_tracepoint_wrapper(tp, func, ctx) \
unregister_trace_ ## tp(func, ctx)
#define tracepoint_available(name) 1
#else
static struct tracepoint *do_lookup_tracepoint(const char *tracepointName, const char *tracepointPtrName)
{
struct tracepoint *pTracepoint = (struct tracepoint *)kallsyms_lookup_name(tracepointName);
if (!pTracepoint)
{
struct tracepoint **ppTracepoint = (struct tracepoint **)kallsyms_lookup_name(tracepointPtrName);
BUG_ON(!ppTracepoint);
pTracepoint = *ppTracepoint;
BUG_ON(!pTracepoint);
}
return pTracepoint;
}
#define register_tracepoint_wrapper(tp, func, ctx) \
tracepoint_probe_register(do_lookup_tracepoint("__tracepoint_" #tp, "__tracepoint_ptr_" #tp), func, ctx)
#define unregister_tracepoint_wrapper(tp, func, ctx) \
tracepoint_probe_unregister(do_lookup_tracepoint("__tracepoint_" #tp, "__tracepoint_ptr_" #tp), func, ctx)
#define tracepoint_available(tp) (kallsyms_lookup_name("__tracepoint_" #tp) || kallsyms_lookup_name("__tracepoint_ptr_" #tp))
#endif