@@ -1119,32 +1119,42 @@ let generate_includes ctx ?(program_types=[]) () =
11191119 " #include <bpf/bpf_helpers.h>" ;
11201120 ] in
11211121
1122- (* When using vmlinux.h, we don't need context-specific kernel headers *)
1123- (* vmlinux.h contains all kernel types, so we only need eBPF helpers *)
1124- let context_includes = [] in (* No additional kernel headers needed with vmlinux.h *)
1122+ (* Get context-specific includes for macros not in vmlinux.h *)
1123+ let context_includes = List. fold_left (fun acc prog_type ->
1124+ let context_type = match prog_type with
1125+ | Ast. Tc -> Some " tc"
1126+ | _ -> None
1127+ in
1128+ match context_type with
1129+ | Some ctx_type ->
1130+ let includes = Kernelscript_context.Context_codegen. get_context_includes ctx_type in
1131+ acc @ includes
1132+ | None -> acc
1133+ ) [] program_types in
11251134
11261135 (* Remove duplicates between all include sets *)
11271136 let all_base_includes = vmlinux_includes @ standard_includes in
11281137 let unique_context_includes = List. filter (fun inc ->
11291138 not (List. mem inc all_base_includes)) context_includes in
11301139
1131- (* For kprobe programs, only emit kprobe includes which contain everything needed *)
1140+ (* For kprobe programs, still use vmlinux.h but include context-specific macro headers *)
11321141 let has_kprobe = List. exists (function Ast. Kprobe -> true | _ -> false ) program_types in
11331142 if has_kprobe then (
1134- (* With vmlinux.h, we only need it and eBPF helpers, no additional kernel headers *)
1143+ (* Use vmlinux.h and context-specific headers for macros *)
11351144 let vmlinux_and_helpers = [
11361145 " #include \" vmlinux.h\" " ;
11371146 " #include <bpf/bpf_helpers.h>" ;
11381147 ] in
11391148
11401149 List. iter (emit_line ctx) vmlinux_and_helpers;
1150+ List. iter (emit_line ctx) unique_context_includes;
11411151 emit_blank_line ctx
11421152 ) else (
11431153 (* For non-kprobe programs, use vmlinux.h and standard processing *)
11441154 let all_includes = vmlinux_includes @ standard_includes @ unique_context_includes in
11451155 List. iter (emit_line ctx) all_includes;
11461156 emit_blank_line ctx;
1147-
1157+
11481158 (* Use proper kernel implementation: extern declarations and macros *)
11491159 emit_line ctx " extern void *bpf_obj_new_impl(__u64 local_type_id__k, void *meta__ign) __ksym;" ;
11501160 emit_line ctx " extern void bpf_obj_drop_impl(void *p__alloc, void *meta__ign) __ksym;" ;
0 commit comments