int (*delete) (_key_type *); \
void (*call) (void *, int index); \
void (*increment) (_key_type); \
+ int (*get_stackid) (void *, u64); \
_leaf_type data[_max_entries]; \
}; \
__attribute__((section("maps/" _table_type))) \
#define BPF_HISTOGRAM(...) \
BPF_HISTX(__VA_ARGS__, BPF_HIST3, BPF_HIST2, BPF_HIST1)(__VA_ARGS__)
+struct bpf_stacktrace {
+ u64 ip[BPF_MAX_STACK_DEPTH];
+};
+
#define BPF_STACK_TRACE(_name, _max_entries) \
-struct _name##_table_t { \
- int key; \
- struct { u64 data[BPF_MAX_STACK_DEPTH]; } leaf; \
- int (*lookup) (void *); \
- struct { u64 data[BPF_MAX_STACK_DEPTH]; } data[_max_entries]; \
-}; \
-__attribute__((section("maps/stacktrace"))) \
-struct _name##_table_t _name
+ BPF_TABLE("stacktrace", int, struct bpf_stacktrace, _name, _max_entries);
// packet parsing state machine helpers
#define cursor_advance(_cursor, _len) \
Call->getArg(2)->getLocEnd()));
txt = "bpf_perf_event_output(" + arg0 + ", bpf_pseudo_fd(1, " + fd + ")";
txt += ", bpf_get_smp_processor_id(), " + args_other + ")";
- } else {
- if (memb_name == "lookup") {
+ } else if (memb_name == "get_stackid") {
if (table_it->type == BPF_MAP_TYPE_STACK_TRACE) {
- prefix = "bpf_get_stackid";
- // TODO: expose the different flags, how?
- suffix = ", 0)";
+ txt = "bpf_get_stackid(";
+ txt += "bpf_pseudo_fd(1, " + fd + "), " + args + ")";
} else {
- prefix = "bpf_map_lookup_elem";
- suffix = ")";
+ unsigned diag_id = C.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error,
+ "get_stackid only available on stacktrace maps");
+ C.getDiagnostics().Report(Call->getLocStart(), diag_id);
+ return false;
}
+ } else {
+ if (memb_name == "lookup") {
+ prefix = "bpf_map_lookup_elem";
+ suffix = ")";
} else if (memb_name == "update") {
prefix = "bpf_map_update_elem";
suffix = ", " + map_update_policy + ")";
BPF_HASH(stack_entries, int, int);
BPF_HASH(stub);
int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *k) {
- int id = stack_traces.lookup(ctx);
+ int id = stack_traces.get_stackid(ctx, (BPF_F_REUSE_STACKID));
+ if (id < 0)
+ return 0;
int key = 1;
stack_entries.update(&key, &id);
return 0;
self.assertIn(k, stack_entries)
stackid = stack_entries[k]
self.assertIsNotNone(stackid)
- stack = stack_traces[stackid].data
+ stack = stack_traces[stackid].ip
self.assertEqual(b.ksym(stack[0]), "htab_map_delete_elem")