@@ -124,21 +124,42 @@ impl<'ctx> MapManager<'ctx> {
124124 } ;
125125 let max_entries_u32 = max_entries. min ( u32:: MAX as u64 ) as u32 ;
126126
127- // Create a simple struct with basic map definition layout
128- // Use the standard 4-field layout that most eBPF maps use
129- let elements = vec ! [
130- i32_type. into( ) , // type (map type)
131- i32_type. into( ) , // key_size
132- i32_type. into( ) , // value_size
133- i32_type. into( ) , // max_entries
134- ] ;
127+ // Create struct with appropriate fields based on map type
128+ // Ringbuf only needs type and max_entries, others need all 4 fields
129+ let ( elements, initializer_values) : ( Vec < _ > , Vec < _ > ) = match map_type {
130+ BpfMapType :: Ringbuf => {
131+ // Ringbuf: only type and max_entries
132+ (
133+ vec ! [
134+ i32_type. into( ) , // type
135+ i32_type. into( ) , // max_entries
136+ ] ,
137+ vec ! [
138+ i32_type. const_int( map_type_id as u64 , false ) . into( ) ,
139+ i32_type. const_int( max_entries_u32 as u64 , false ) . into( ) ,
140+ ] ,
141+ )
142+ }
143+ _ => {
144+ // Other maps: type, key_size, value_size, max_entries
145+ (
146+ vec ! [
147+ i32_type. into( ) , // type
148+ i32_type. into( ) , // key_size
149+ i32_type. into( ) , // value_size
150+ i32_type. into( ) , // max_entries
151+ ] ,
152+ vec ! [
153+ i32_type. const_int( map_type_id as u64 , false ) . into( ) ,
154+ i32_type. const_int( key_size as u64 , false ) . into( ) ,
155+ i32_type. const_int( value_size as u64 , false ) . into( ) ,
156+ i32_type. const_int( max_entries_u32 as u64 , false ) . into( ) ,
157+ ] ,
158+ )
159+ }
160+ } ;
135161 let struct_type = self . context . struct_type ( & elements, false ) ;
136- let initializer = struct_type. const_named_struct ( & [
137- i32_type. const_int ( map_type_id as u64 , false ) . into ( ) ,
138- i32_type. const_int ( key_size as u64 , false ) . into ( ) ,
139- i32_type. const_int ( value_size as u64 , false ) . into ( ) ,
140- i32_type. const_int ( max_entries_u32 as u64 , false ) . into ( ) ,
141- ] ) ;
162+ let initializer = struct_type. const_named_struct ( & initializer_values) ;
142163
143164 // Create BTF type information for the map
144165 // This is critical for aya to understand the map structure
@@ -215,15 +236,13 @@ impl<'ctx> MapManager<'ctx> {
215236 di_builder : & DebugInfoBuilder < ' ctx > ,
216237 compile_unit : & inkwell:: debug_info:: DICompileUnit < ' ctx > ,
217238 name : & str ,
218- perf_rb_pages : u64 ,
239+ ringbuf_size : u64 ,
219240 ) -> Result < ( ) > {
220- // For ringbuf, max_entries should be power of 2 and reasonable size
221- // Use 256KB (262144 bytes) which is a common size for eBPF ringbuf
222- let max_entries = 256 * 1024 ; // 262144
223- info ! (
224- "Creating ringbuf map: {} with {} max entries ({} pages)" ,
225- name, max_entries, perf_rb_pages
226- ) ;
241+ // For ringbuf, max_entries is the buffer size in bytes (must be power of 2)
242+ // The parameter name is kept as perf_rb_pages for backward compatibility,
243+ // but we now interpret it directly as the ringbuf size in bytes
244+ let max_entries = ringbuf_size;
245+ info ! ( "Creating ringbuf map: {} with {} bytes" , name, max_entries) ;
227246 self . create_map_definition (
228247 module,
229248 di_builder,
0 commit comments