@@ -381,8 +381,8 @@ func (r *rubyData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID, bias libp
381381 procInfo : & cdata ,
382382 globalSymbolsAddr : r .globalSymbolsAddr + bias ,
383383 addrToString : addrToString ,
384- mappings : make (map [process.RawMapping ]* uint32 ),
385- prefixes : make (map [lpm.Prefix ]* uint32 ),
384+ mappings : make (map [process.RawMapping ]uint32 ),
385+ prefixes : make (map [lpm.Prefix ]uint32 ),
386386 memPool : sync.Pool {
387387 New : func () any {
388388 buf := make ([]byte , 512 )
@@ -447,9 +447,9 @@ type rubyInstance struct {
447447 maxSize atomic.Uint32
448448
449449 // mappings is indexed by the Mapping to its generation
450- mappings map [process.RawMapping ]* uint32
450+ mappings map [process.RawMapping ]uint32
451451 // prefixes is indexed by the prefix added to ebpf maps (to be cleaned up) to its generation
452- prefixes map [lpm.Prefix ]* uint32
452+ prefixes map [lpm.Prefix ]uint32
453453 // mappingGeneration is the current generation (so old entries can be pruned)
454454 mappingGeneration uint32
455455}
@@ -1343,32 +1343,26 @@ func (r *rubyInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler,
13431343 continue
13441344 }
13451345
1346- if gen , exists := r .mappings [* m ]; exists {
1347- * gen = r .mappingGeneration
1348- continue
1346+ isNew := false
1347+ if _ , exists := r .mappings [* m ]; ! exists {
1348+ isNew = true
1349+ log .Debugf ("Enabling Ruby interpreter for %#x/%#x" , m .Vaddr , m .Length )
13491350 }
1350-
1351- // Generate a new uint32 pointer which is shared for mapping and the prefixes it owns
1352- // so updating the mapping above will reflect to prefixes also.
1353- mappingGeneration := r .mappingGeneration
1354- r .mappings [* m ] = & mappingGeneration
1355-
1356- log .Debugf ("Enabling Ruby interpreter for %#x/%#x" , m .Vaddr , m .Length )
1351+ r .mappings [* m ] = r .mappingGeneration
13571352
13581353 prefixes , err := lpm .CalculatePrefixList (m .Vaddr , m .Vaddr + m .Length )
13591354 if err != nil {
13601355 return fmt .Errorf ("new anonymous mapping lpm failure %#x/%#x: %w" , m .Vaddr , m .Length , err )
13611356 }
13621357
13631358 for _ , prefix := range prefixes {
1364- _ , exists := r .prefixes [prefix ]
1365- if ! exists {
1366- err := ebpf .UpdatePidInterpreterMapping (pid , prefix , support .ProgUnwindRuby , 0 , 0 )
1367- if err != nil {
1359+ if isNew {
1360+ if err := ebpf .UpdatePidInterpreterMapping (pid , prefix ,
1361+ support .ProgUnwindRuby , 0 , 0 ); err != nil {
13681362 return err
13691363 }
13701364 }
1371- r .prefixes [prefix ] = & mappingGeneration
1365+ r .prefixes [prefix ] = r . mappingGeneration
13721366 }
13731367 }
13741368 // Detect JIT region from all mappings and update proc data if changed.
@@ -1382,17 +1376,17 @@ func (r *rubyInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler,
13821376 log .Debugf ("Updated JIT region %#x-%#x in ruby proc info" , jitStart , jitEnd )
13831377 }
13841378 // Remove prefixes not seen
1385- for prefix , generationPtr := range r .prefixes {
1386- if * generationPtr == r .mappingGeneration {
1379+ for prefix , gen := range r .prefixes {
1380+ if gen == r .mappingGeneration {
13871381 continue
13881382 }
13891383 if err := ebpf .DeletePidInterpreterMapping (pid , prefix ); err != nil {
13901384 log .Debugf ("Failed to delete Ruby prefix %#v: %v" , prefix , err )
13911385 }
13921386 delete (r .prefixes , prefix )
13931387 }
1394- for m , generationPtr := range r .mappings {
1395- if * generationPtr == r .mappingGeneration {
1388+ for m , gen := range r .mappings {
1389+ if gen == r .mappingGeneration {
13961390 continue
13971391 }
13981392 log .Debugf ("Disabling Ruby for %#x/%#x" , m .Vaddr , m .Length )
0 commit comments