Skip to content

Commit 5bcf0cb

Browse files
committed
Narrow generated skeleton cleanup to userspace object lifetime
Keep generated atexit cleanup limited to destroying the libbpf skeleton object, and avoid using it for kernel lifecycle state such as struct_ops links. This preserves explicit lifecycle behavior for struct_ops registration while still releasing userspace-owned skeleton resources on process exit.
1 parent 8f3c455 commit 5bcf0cb

1 file changed

Lines changed: 4 additions & 18 deletions

File tree

src/userspace_codegen.ml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,30 +2959,16 @@ int detach_struct_ops_%s(void) {
29592959
) (Ir.get_struct_ops_instances ir_multi_program) in
29602960
String.concat "\n" attach_functions
29612961

2962-
let generate_skeleton_cleanup_helper base_name ir_multi_program needs_skeleton =
2962+
let generate_skeleton_cleanup_helper base_name needs_skeleton =
29632963
if not needs_skeleton then
29642964
""
29652965
else
2966-
let struct_ops_instances = Ir.get_struct_ops_instances ir_multi_program in
2967-
let cleanup_lines =
2968-
struct_ops_instances
2969-
|> List.map (fun struct_ops_inst ->
2970-
let instance_name = struct_ops_inst.ir_instance_name in
2971-
sprintf {| if (%s_link) {
2972-
bpf_link__destroy(%s_link);
2973-
%s_link = NULL;
2974-
}|} instance_name instance_name instance_name)
2975-
|> String.concat "\n\n"
2976-
in
2977-
let cleanup_prefix =
2978-
if cleanup_lines = "" then "" else cleanup_lines ^ "\n\n"
2979-
in
29802966
sprintf {|static void cleanup_%s(void) {
2981-
%s if (obj) {
2967+
if (obj) {
29822968
%s_ebpf__destroy(obj);
29832969
obj = NULL;
29842970
}
2985-
}|} base_name cleanup_prefix base_name
2971+
}|} base_name base_name
29862972

29872973
let generate_struct_ops_runtime_helpers base_name ir_multi_program =
29882974
let struct_ops_instances = Ir.get_struct_ops_instances ir_multi_program in
@@ -4874,7 +4860,7 @@ static void handle_signal(int sig) {
48744860
|}
48754861
else "" in
48764862
4877-
let skeleton_cleanup_helper = generate_skeleton_cleanup_helper base_name ir_multi_prog needs_skeleton in
4863+
let skeleton_cleanup_helper = generate_skeleton_cleanup_helper base_name needs_skeleton in
48784864
let struct_ops_runtime_helpers = generate_struct_ops_runtime_helpers base_name ir_multi_prog in
48794865
48804866
(* Generate struct_ops attach functions *)

0 commit comments

Comments
 (0)