@@ -31,7 +31,7 @@ def is_map(func_node):
3131 )
3232
3333
34- def create_bpf_map (module , map_name , map_params ):
34+ def create_bpf_map (compilation_context , map_name , map_params ):
3535 """Create a BPF map in the module with given parameters and debug info"""
3636
3737 # Create the anonymous struct type for BPF map
@@ -40,7 +40,9 @@ def create_bpf_map(module, map_name, map_params):
4040 )
4141
4242 # Create the global variable
43- map_global = ir .GlobalVariable (module , map_struct_type , name = map_name )
43+ map_global = ir .GlobalVariable (
44+ compilation_context .module , map_struct_type , name = map_name
45+ )
4446 map_global .linkage = "dso_local"
4547 map_global .global_constant = False
4648 map_global .initializer = ir .Constant (map_struct_type , None )
@@ -51,11 +53,13 @@ def create_bpf_map(module, map_name, map_params):
5153 return MapSymbol (type = map_params ["type" ], sym = map_global , params = map_params )
5254
5355
54- def _parse_map_params (rval , compilation_context , expected_args = None ):
56+ def _parse_map_params (rval , expected_args = None ):
5557 """Parse map parameters from call arguments and keywords."""
5658
5759 params = {}
58- handler = compilation_context .vmlinux_handler
60+
61+ # TODO: Replace it with compilation_context.vmlinux_handler someday?
62+ handler = VmlinuxHandlerRegistry .get_handler ()
5963 # Parse positional arguments
6064 if expected_args :
6165 for i , arg_name in enumerate (expected_args ):
@@ -82,24 +86,14 @@ def _parse_map_params(rval, compilation_context, expected_args=None):
8286def _get_vmlinux_enum (handler , name ):
8387 if handler and handler .is_vmlinux_enum (name ):
8488 return handler .get_vmlinux_enum_value (name )
85-
86- # Fallback to VmlinuxHandlerRegistry if handler invalid
87- # This is for backward compatibility or if refactoring isn't complete
88- if (
89- VmlinuxHandlerRegistry .get_handler ()
90- and VmlinuxHandlerRegistry .get_handler ().is_vmlinux_enum (name )
91- ):
92- return VmlinuxHandlerRegistry .get_handler ().get_vmlinux_enum_value (name )
9389 return None
9490
9591
9692@MapProcessorRegistry .register ("RingBuffer" )
9793def process_ringbuf_map (map_name , rval , compilation_context ):
9894 """Process a BPF_RINGBUF map declaration"""
9995 logger .info (f"Processing Ringbuf: { map_name } " )
100- map_params = _parse_map_params (
101- rval , compilation_context , expected_args = ["max_entries" ]
102- )
96+ map_params = _parse_map_params (rval , expected_args = ["max_entries" ])
10397 map_params ["type" ] = BPFMapType .RINGBUF
10498
10599 # NOTE: constraints borrowed from https://docs.ebpf.io/linux/map-type/BPF_MAP_TYPE_RINGBUF/
@@ -115,13 +109,12 @@ def process_ringbuf_map(map_name, rval, compilation_context):
115109
116110 logger .info (f"Ringbuf map parameters: { map_params } " )
117111
118- map_global = create_bpf_map (compilation_context . module , map_name , map_params )
112+ map_global = create_bpf_map (compilation_context , map_name , map_params )
119113 create_ringbuf_debug_info (
120- compilation_context . module ,
114+ compilation_context ,
121115 map_global .sym ,
122116 map_name ,
123117 map_params ,
124- compilation_context .structs_sym_tab ,
125118 )
126119 return map_global
127120
@@ -130,20 +123,17 @@ def process_ringbuf_map(map_name, rval, compilation_context):
130123def process_hash_map (map_name , rval , compilation_context ):
131124 """Process a BPF_HASH map declaration"""
132125 logger .info (f"Processing HashMap: { map_name } " )
133- map_params = _parse_map_params (
134- rval , compilation_context , expected_args = ["key" , "value" , "max_entries" ]
135- )
126+ map_params = _parse_map_params (rval , expected_args = ["key" , "value" , "max_entries" ])
136127 map_params ["type" ] = BPFMapType .HASH
137128
138129 logger .info (f"Map parameters: { map_params } " )
139- map_global = create_bpf_map (compilation_context . module , map_name , map_params )
130+ map_global = create_bpf_map (compilation_context , map_name , map_params )
140131 # Generate debug info for BTF
141132 create_map_debug_info (
142- compilation_context . module ,
133+ compilation_context ,
143134 map_global .sym ,
144135 map_name ,
145136 map_params ,
146- compilation_context .structs_sym_tab ,
147137 )
148138 return map_global
149139
@@ -152,20 +142,17 @@ def process_hash_map(map_name, rval, compilation_context):
152142def process_perf_event_map (map_name , rval , compilation_context ):
153143 """Process a BPF_PERF_EVENT_ARRAY map declaration"""
154144 logger .info (f"Processing PerfEventArray: { map_name } " )
155- map_params = _parse_map_params (
156- rval , compilation_context , expected_args = ["key_size" , "value_size" ]
157- )
145+ map_params = _parse_map_params (rval , expected_args = ["key_size" , "value_size" ])
158146 map_params ["type" ] = BPFMapType .PERF_EVENT_ARRAY
159147
160148 logger .info (f"Map parameters: { map_params } " )
161- map_global = create_bpf_map (compilation_context . module , map_name , map_params )
149+ map_global = create_bpf_map (compilation_context , map_name , map_params )
162150 # Generate debug info for BTF
163151 create_map_debug_info (
164- compilation_context . module ,
152+ compilation_context ,
165153 map_global .sym ,
166154 map_name ,
167155 map_params ,
168- compilation_context .structs_sym_tab ,
169156 )
170157 return map_global
171158
0 commit comments