Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ebpf_c_codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,10 @@ and generate_assignment ctx dest_val expr is_const =
| IRValue src_val ->
(* Simple value assignment *)
let dest_str = generate_c_value ctx dest_val in
let src_str = generate_c_value ctx src_val in
(* Auto-dereference map access to get the value, not the pointer *)
let src_str = (match src_val.value_desc with
| IRMapAccess (_, _, _) -> generate_c_value ~auto_deref_map_access:true ctx src_val
| _ -> generate_c_value ctx src_val) in
emit_line ctx (sprintf "%s%s = %s;" assignment_prefix dest_str src_str)
| _ ->
(* Other expressions *)
Expand Down
19 changes: 18 additions & 1 deletion src/userspace_codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,19 @@ let generate_pinned_globals_support _project_name global_variables =

(** Generate ring buffer event handler functions *)
let generate_ringbuf_handlers_from_registry (registry : Ir.ir_ring_buffer_registry) ~dispatch_used =
(* Generate forward declarations for callback functions *)
let forward_declarations = List.map (fun rb_decl ->
let ringbuf_name = rb_decl.rb_name in
let value_type = c_type_from_ir_type rb_decl.rb_value_type in
let handler_name = match List.assoc_opt ringbuf_name registry.event_handler_registrations with
| Some handler -> handler
| None ->
(* Try callback function naming convention: {ringbuf_name}_callback *)
ringbuf_name ^ "_callback"
in
sprintf "int %s(%s *event);" handler_name value_type
) registry.ring_buffer_declarations |> String.concat "\n" in

let event_handlers = List.map (fun rb_decl ->
let ringbuf_name = rb_decl.rb_name in
let value_type = c_type_from_ir_type rb_decl.rb_value_type in
Expand All @@ -2836,7 +2849,11 @@ static int %s_event_handler(void *ctx, void *data, size_t data_sz) {
else "" in

(* Only generate event handlers if dispatch is actually used *)
let final_event_handlers = if dispatch_used then event_handlers else "" in
let final_event_handlers = if dispatch_used then
if List.length registry.ring_buffer_declarations > 0 then
sprintf "\n// Forward declarations for ring buffer callbacks\n%s\n%s" forward_declarations event_handlers
else ""
else "" in

final_event_handlers ^ combined_rb_declaration

Expand Down