Skip to content

Commit 6d5e114

Browse files
committed
Address pair-review feedback and move prctl mapping support from PR #36
- Fix JIT region check to use >= for lower bound (half-open interval [start, end)) matching V8 and HotSpot conventions - Reuse map lookup value to avoid double hashing of RawMapping struct key - Wrap CalculatePrefixList error for better debugging - Log stale prefix deletion errors instead of silently discarding - Move prctl(PR_SET_VMA) named anonymous mapping support from process/process.go (was in PR #36 but is needed here for findJITRegion labeled detection) - Remove stale 'assume all anonymous' comment - Rebuild BPF blobs for >= fix
1 parent 77b5929 commit 6d5e114

5 files changed

Lines changed: 10 additions & 7 deletions

File tree

interpreter/ruby/ruby.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,8 @@ func (r *rubyInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler,
13421342
continue
13431343
}
13441344

1345-
if _, exists := r.mappings[*m]; exists {
1346-
*r.mappings[*m] = r.mappingGeneration
1345+
if gen, exists := r.mappings[*m]; exists {
1346+
*gen = r.mappingGeneration
13471347
continue
13481348
}
13491349

@@ -1352,12 +1352,11 @@ func (r *rubyInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler,
13521352
mappingGeneration := r.mappingGeneration
13531353
r.mappings[*m] = &mappingGeneration
13541354

1355-
// Just assume all anonymous and executable mappings are Ruby for now
13561355
log.Debugf("Enabling Ruby interpreter for %#x/%#x", m.Vaddr, m.Length)
13571356

13581357
prefixes, err := lpm.CalculatePrefixList(m.Vaddr, m.Vaddr+m.Length)
13591358
if err != nil {
1360-
return fmt.Errorf("new anonymous mapping lpm failure %#x/%#x", m.Vaddr, m.Length)
1359+
return fmt.Errorf("new anonymous mapping lpm failure %#x/%#x: %w", m.Vaddr, m.Length, err)
13611360
}
13621361

13631362
for _, prefix := range prefixes {
@@ -1386,8 +1385,9 @@ func (r *rubyInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler,
13861385
if *generationPtr == r.mappingGeneration {
13871386
continue
13881387
}
1389-
log.Debugf("Delete Ruby prefix %#v", prefix)
1390-
_ = ebpf.DeletePidInterpreterMapping(pid, prefix)
1388+
if err := ebpf.DeletePidInterpreterMapping(pid, prefix); err != nil {
1389+
log.Debugf("Failed to delete Ruby prefix %#v: %v", prefix, err)
1390+
}
13911391
delete(r.prefixes, prefix)
13921392
}
13931393
for m, generationPtr := range r.mappings {

process/process.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ func iterateMappings(mapsFile io.Reader, callback func(m RawMapping) bool) (uint
282282
inode = vdsoInode
283283
} else if fields[5] == "" {
284284
// This is an anonymous mapping, keep it
285+
} else if strings.HasPrefix(fields[5], "[anon:") {
286+
// This is an anonymous mapping named with prctl(PR_SET_VMA), keep the name
287+
path = trimMappingPath(fields[5])
285288
} else {
286289
// Ignore other mappings that are invalid, non-existent or are special pseudo-files
287290
continue

support/ebpf/ruby_tracer.ebpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static EBPF_INLINE ErrorCode walk_ruby_stack(
451451
}
452452

453453
if (
454-
rubyinfo->jit_start > 0 && record->state.pc > rubyinfo->jit_start &&
454+
rubyinfo->jit_start > 0 && record->state.pc >= rubyinfo->jit_start &&
455455
record->state.pc < rubyinfo->jit_end) {
456456
record->rubyUnwindState.jit_detected = true;
457457

support/ebpf/tracer.ebpf.amd64

0 Bytes
Binary file not shown.

support/ebpf/tracer.ebpf.arm64

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)