From 155b64e4d8af098a06fc1ee29d5b4845030ed716 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Tue, 7 Feb 2023 17:03:16 -0800 Subject: [PATCH] Internal change PiperOrigin-RevId: 507925165 --- pkg/sentry/mm/syscalls.go | 19 +++++++++++++++++++ pkg/sentry/platform/platform.go | 2 ++ 2 files changed, 21 insertions(+) diff --git a/pkg/sentry/mm/syscalls.go b/pkg/sentry/mm/syscalls.go index c4994fb04..884964e8c 100644 --- a/pkg/sentry/mm/syscalls.go +++ b/pkg/sentry/mm/syscalls.go @@ -1320,3 +1320,22 @@ func (mm *MemoryManager) EnableMembarrierRSeq() { func (mm *MemoryManager) IsMembarrierRSeqEnabled() bool { return mm.membarrierRSeqEnabled.Load() != 0 } + +// FindVMAByName finds a vma with the specified name and returns its start address and offset. +func (mm *MemoryManager) FindVMAByName(ar hostarch.AddrRange, hint string) (hostarch.Addr, uint64, error) { + mm.mappingMu.RLock() + defer mm.mappingMu.RUnlock() + + for vseg := mm.vmas.LowerBoundSegment(ar.Start); vseg.Ok(); vseg = vseg.NextSegment() { + start := vseg.Start() + if !ar.Contains(start) { + break + } + vma := vseg.ValuePtr() + + if vma.hint == hint { + return start, vma.off, nil + } + } + return 0, 0, fmt.Errorf("could not find \"%s\" in %s", hint, ar) +} diff --git a/pkg/sentry/platform/platform.go b/pkg/sentry/platform/platform.go index 2971dc569..f91cf194f 100644 --- a/pkg/sentry/platform/platform.go +++ b/pkg/sentry/platform/platform.go @@ -176,6 +176,8 @@ type MemoryManager interface { MMap(ctx context.Context, opts memmap.MMapOpts) (hostarch.Addr, error) // AddressSpace returns the AddressSpace bound to mm. AddressSpace() AddressSpace + // FindVMAByName finds a vma with the specified name. + FindVMAByName(ar hostarch.AddrRange, hint string) (hostarch.Addr, uint64, error) } // Context represents the execution context for a single thread.