diff --git a/interpreter/nodev8/v8.go b/interpreter/nodev8/v8.go index 30959a4..96e9ee7 100644 --- a/interpreter/nodev8/v8.go +++ b/interpreter/nodev8/v8.go @@ -494,8 +494,8 @@ type v8Instance struct { // mappings is indexed by the Mapping to its generation mappings map[process.Mapping]uint32 - // prefixes is indexed by the prefix added to ebpf maps (to be cleaned up) to its generation - prefixes map[lpm.Prefix]uint32 + // prefixes is indexed by the prefix added to ebpf maps (to be cleaned up) + prefixes map[lpm.Prefix]struct{} // mappingGeneration is the current generation (so old entries can be pruned) mappingGeneration uint32 } @@ -573,30 +573,29 @@ func (i *v8Instance) SynchronizeMappings(ebpf interpreter.EbpfHandler, for _, prefix := range prefixes { if _, exists := i.prefixes[prefix]; exists { - i.prefixes[prefix] = i.mappingGeneration continue } err := ebpf.UpdatePidInterpreterMapping(pid, prefix, support.ProgUnwindV8, 0, 0) if err != nil { return err } - i.prefixes[prefix] = i.mappingGeneration + i.prefixes[prefix] = struct{}{} } } - // Remove prefixes not seen - for prefix, generation := range i.prefixes { - if generation == i.mappingGeneration { - continue - } - _ = ebpf.DeletePidInterpreterMapping(pid, prefix) - delete(i.prefixes, prefix) - } for m, generation := range i.mappings { if generation == i.mappingGeneration { continue } log.Debugf("Disabling V8 for %#x/%#x", m.Vaddr, m.Length) + prefixes, err := lpm.CalculatePrefixList(m.Vaddr, m.Vaddr+m.Length) + if err != nil { + return fmt.Errorf("new anonymous mapping lpm failure %#x/%#x", m.Vaddr, m.Length) + } + for _, prefix := range prefixes { + _ = ebpf.DeletePidInterpreterMapping(pid, prefix) + delete(i.prefixes, prefix) + } delete(i.mappings, m) } @@ -1820,7 +1819,7 @@ func (d *v8Data) Attach(ebpf interpreter.EbpfHandler, pid util.PID, _ libpf.Addr d: d, rm: rm, mappings: make(map[process.Mapping]uint32), - prefixes: make(map[lpm.Prefix]uint32), + prefixes: make(map[lpm.Prefix]struct{}), addrToString: addrToString, addrToCode: addrToCode, addrToSFI: addrToSFI,