Skip to content

Commit 3b13f6c

Browse files
committed
Remove static kprobe field mappings in favor of dynamic parameter mappings based on kernel function signatures.
1 parent d6f9dd1 commit 3b13f6c

1 file changed

Lines changed: 3 additions & 81 deletions

File tree

src/context/kprobe_codegen.ml

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -21,79 +21,6 @@
2121
open Printf
2222
open Context_codegen
2323

24-
(** Kprobe field mappings from KernelScript to kernel struct pt_regs *)
25-
let kprobe_field_mappings = [
26-
("regs", {
27-
field_name = "regs";
28-
c_expression = (fun ctx_var -> sprintf "%s" ctx_var);
29-
requires_cast = false;
30-
field_type = "struct pt_regs*";
31-
});
32-
33-
("ip", {
34-
field_name = "ip";
35-
c_expression = (fun ctx_var -> sprintf "PT_REGS_IP(%s)" ctx_var);
36-
requires_cast = false;
37-
field_type = "unsigned long";
38-
});
39-
40-
("sp", {
41-
field_name = "sp";
42-
c_expression = (fun ctx_var -> sprintf "PT_REGS_SP(%s)" ctx_var);
43-
requires_cast = false;
44-
field_type = "unsigned long";
45-
});
46-
47-
("ax", {
48-
field_name = "ax";
49-
c_expression = (fun ctx_var -> sprintf "PT_REGS_PARM1(%s)" ctx_var);
50-
requires_cast = false;
51-
field_type = "unsigned long";
52-
});
53-
54-
("bx", {
55-
field_name = "bx";
56-
c_expression = (fun ctx_var -> sprintf "PT_REGS_PARM2(%s)" ctx_var);
57-
requires_cast = false;
58-
field_type = "unsigned long";
59-
});
60-
61-
("cx", {
62-
field_name = "cx";
63-
c_expression = (fun ctx_var -> sprintf "PT_REGS_PARM3(%s)" ctx_var);
64-
requires_cast = false;
65-
field_type = "unsigned long";
66-
});
67-
68-
("dx", {
69-
field_name = "dx";
70-
c_expression = (fun ctx_var -> sprintf "PT_REGS_PARM4(%s)" ctx_var);
71-
requires_cast = false;
72-
field_type = "unsigned long";
73-
});
74-
75-
("si", {
76-
field_name = "si";
77-
c_expression = (fun ctx_var -> sprintf "PT_REGS_PARM5(%s)" ctx_var);
78-
requires_cast = false;
79-
field_type = "unsigned long";
80-
});
81-
82-
("di", {
83-
field_name = "di";
84-
c_expression = (fun ctx_var -> sprintf "PT_REGS_PARM6(%s)" ctx_var);
85-
requires_cast = false;
86-
field_type = "unsigned long";
87-
});
88-
89-
("ret", {
90-
field_name = "ret";
91-
c_expression = (fun ctx_var -> sprintf "PT_REGS_RC(%s)" ctx_var);
92-
requires_cast = false;
93-
field_type = "unsigned long";
94-
});
95-
]
96-
9724
(** Dynamic kprobe parameter mappings - populated during compilation based on function signature *)
9825
let kprobe_parameter_mappings = ref []
9926

@@ -137,16 +64,11 @@ let generate_kprobe_includes () = [
13764
(** Generate field access for kprobe context *)
13865
let generate_kprobe_field_access ctx_var field_name =
13966
try
140-
(* First check dynamic parameter mappings *)
67+
(* Use dynamic parameter mappings based on kernel function signature *)
14168
let (_, field_access) = List.find (fun (name, _) -> name = field_name) !kprobe_parameter_mappings in
14269
field_access.c_expression ctx_var
14370
with Not_found ->
144-
try
145-
(* Fallback to static register mappings *)
146-
let (_, field_access) = List.find (fun (name, _) -> name = field_name) kprobe_field_mappings in
147-
field_access.c_expression ctx_var
148-
with Not_found ->
149-
failwith ("Unknown kprobe context field: " ^ field_name)
71+
failwith ("Unknown kprobe parameter: " ^ field_name ^ ". Make sure the kernel function signature is properly extracted from BTF.")
15072

15173
(** Map kprobe return constants *)
15274
let map_kprobe_action_constant = function
@@ -159,7 +81,7 @@ let create () = {
15981
name = "Kprobe";
16082
c_type = "struct pt_regs*";
16183
section_prefix = "kprobe";
162-
field_mappings = kprobe_field_mappings;
84+
field_mappings = []; (* No static field mappings - use dynamic parameter mappings *)
16385
generate_includes = generate_kprobe_includes;
16486
generate_field_access = generate_kprobe_field_access;
16587
map_action_constant = map_kprobe_action_constant;

0 commit comments

Comments
 (0)