Move platform.File in memmap

The subsequent systrap changes will need to import memmap from
the platform package.

PiperOrigin-RevId: 323409486
This commit is contained in:
Andrei Vagin
2020-07-27 11:59:10 -07:00
committed by gVisor bot
parent 1876225fc8
commit f347a578b7
29 changed files with 205 additions and 223 deletions
+2 -5
View File
@@ -8,7 +8,6 @@ go_template_instance(
out = "dirty_set_impl.go", out = "dirty_set_impl.go",
imports = { imports = {
"memmap": "gvisor.dev/gvisor/pkg/sentry/memmap", "memmap": "gvisor.dev/gvisor/pkg/sentry/memmap",
"platform": "gvisor.dev/gvisor/pkg/sentry/platform",
}, },
package = "fsutil", package = "fsutil",
prefix = "Dirty", prefix = "Dirty",
@@ -25,14 +24,14 @@ go_template_instance(
name = "frame_ref_set_impl", name = "frame_ref_set_impl",
out = "frame_ref_set_impl.go", out = "frame_ref_set_impl.go",
imports = { imports = {
"platform": "gvisor.dev/gvisor/pkg/sentry/platform", "memmap": "gvisor.dev/gvisor/pkg/sentry/memmap",
}, },
package = "fsutil", package = "fsutil",
prefix = "FrameRef", prefix = "FrameRef",
template = "//pkg/segment:generic_set", template = "//pkg/segment:generic_set",
types = { types = {
"Key": "uint64", "Key": "uint64",
"Range": "platform.FileRange", "Range": "memmap.FileRange",
"Value": "uint64", "Value": "uint64",
"Functions": "FrameRefSetFunctions", "Functions": "FrameRefSetFunctions",
}, },
@@ -43,7 +42,6 @@ go_template_instance(
out = "file_range_set_impl.go", out = "file_range_set_impl.go",
imports = { imports = {
"memmap": "gvisor.dev/gvisor/pkg/sentry/memmap", "memmap": "gvisor.dev/gvisor/pkg/sentry/memmap",
"platform": "gvisor.dev/gvisor/pkg/sentry/platform",
}, },
package = "fsutil", package = "fsutil",
prefix = "FileRange", prefix = "FileRange",
@@ -86,7 +84,6 @@ go_library(
"//pkg/sentry/kernel/time", "//pkg/sentry/kernel/time",
"//pkg/sentry/memmap", "//pkg/sentry/memmap",
"//pkg/sentry/pgalloc", "//pkg/sentry/pgalloc",
"//pkg/sentry/platform",
"//pkg/sentry/socket/unix/transport", "//pkg/sentry/socket/unix/transport",
"//pkg/sentry/usage", "//pkg/sentry/usage",
"//pkg/state", "//pkg/state",
+3 -4
View File
@@ -20,7 +20,6 @@ import (
"gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/safemem" "gvisor.dev/gvisor/pkg/safemem"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/pkg/usermem"
) )
@@ -159,7 +158,7 @@ func (ds *DirtySet) AllowClean(mr memmap.MappableRange) {
// repeatedly until all bytes have been written. max is the true size of the // repeatedly until all bytes have been written. max is the true size of the
// cached object; offsets beyond max will not be passed to writeAt, even if // cached object; offsets beyond max will not be passed to writeAt, even if
// they are marked dirty. // they are marked dirty.
func SyncDirty(ctx context.Context, mr memmap.MappableRange, cache *FileRangeSet, dirty *DirtySet, max uint64, mem platform.File, writeAt func(ctx context.Context, srcs safemem.BlockSeq, offset uint64) (uint64, error)) error { func SyncDirty(ctx context.Context, mr memmap.MappableRange, cache *FileRangeSet, dirty *DirtySet, max uint64, mem memmap.File, writeAt func(ctx context.Context, srcs safemem.BlockSeq, offset uint64) (uint64, error)) error {
var changedDirty bool var changedDirty bool
defer func() { defer func() {
if changedDirty { if changedDirty {
@@ -194,7 +193,7 @@ func SyncDirty(ctx context.Context, mr memmap.MappableRange, cache *FileRangeSet
// successful partial write, SyncDirtyAll will call it repeatedly until all // successful partial write, SyncDirtyAll will call it repeatedly until all
// bytes have been written. max is the true size of the cached object; offsets // bytes have been written. max is the true size of the cached object; offsets
// beyond max will not be passed to writeAt, even if they are marked dirty. // beyond max will not be passed to writeAt, even if they are marked dirty.
func SyncDirtyAll(ctx context.Context, cache *FileRangeSet, dirty *DirtySet, max uint64, mem platform.File, writeAt func(ctx context.Context, srcs safemem.BlockSeq, offset uint64) (uint64, error)) error { func SyncDirtyAll(ctx context.Context, cache *FileRangeSet, dirty *DirtySet, max uint64, mem memmap.File, writeAt func(ctx context.Context, srcs safemem.BlockSeq, offset uint64) (uint64, error)) error {
dseg := dirty.FirstSegment() dseg := dirty.FirstSegment()
for dseg.Ok() { for dseg.Ok() {
if err := syncDirtyRange(ctx, dseg.Range(), cache, max, mem, writeAt); err != nil { if err := syncDirtyRange(ctx, dseg.Range(), cache, max, mem, writeAt); err != nil {
@@ -210,7 +209,7 @@ func SyncDirtyAll(ctx context.Context, cache *FileRangeSet, dirty *DirtySet, max
} }
// Preconditions: mr must be page-aligned. // Preconditions: mr must be page-aligned.
func syncDirtyRange(ctx context.Context, mr memmap.MappableRange, cache *FileRangeSet, max uint64, mem platform.File, writeAt func(ctx context.Context, srcs safemem.BlockSeq, offset uint64) (uint64, error)) error { func syncDirtyRange(ctx context.Context, mr memmap.MappableRange, cache *FileRangeSet, max uint64, mem memmap.File, writeAt func(ctx context.Context, srcs safemem.BlockSeq, offset uint64) (uint64, error)) error {
for cseg := cache.LowerBoundSegment(mr.Start); cseg.Ok() && cseg.Start() < mr.End; cseg = cseg.NextSegment() { for cseg := cache.LowerBoundSegment(mr.Start); cseg.Ok() && cseg.Start() < mr.End; cseg = cseg.NextSegment() {
wbr := cseg.Range().Intersect(mr) wbr := cseg.Range().Intersect(mr)
if max < wbr.Start { if max < wbr.Start {
+7 -8
View File
@@ -23,13 +23,12 @@ import (
"gvisor.dev/gvisor/pkg/safemem" "gvisor.dev/gvisor/pkg/safemem"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/pgalloc" "gvisor.dev/gvisor/pkg/sentry/pgalloc"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sentry/usage" "gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/pkg/usermem"
) )
// FileRangeSet maps offsets into a memmap.Mappable to offsets into a // FileRangeSet maps offsets into a memmap.Mappable to offsets into a
// platform.File. It is used to implement Mappables that store data in // memmap.File. It is used to implement Mappables that store data in
// sparsely-allocated memory. // sparsely-allocated memory.
// //
// type FileRangeSet <generated by go_generics> // type FileRangeSet <generated by go_generics>
@@ -65,20 +64,20 @@ func (FileRangeSetFunctions) Split(mr memmap.MappableRange, frstart uint64, spli
} }
// FileRange returns the FileRange mapped by seg. // FileRange returns the FileRange mapped by seg.
func (seg FileRangeIterator) FileRange() platform.FileRange { func (seg FileRangeIterator) FileRange() memmap.FileRange {
return seg.FileRangeOf(seg.Range()) return seg.FileRangeOf(seg.Range())
} }
// FileRangeOf returns the FileRange mapped by mr. // FileRangeOf returns the FileRange mapped by mr.
// //
// Preconditions: seg.Range().IsSupersetOf(mr). mr.Length() != 0. // Preconditions: seg.Range().IsSupersetOf(mr). mr.Length() != 0.
func (seg FileRangeIterator) FileRangeOf(mr memmap.MappableRange) platform.FileRange { func (seg FileRangeIterator) FileRangeOf(mr memmap.MappableRange) memmap.FileRange {
frstart := seg.Value() + (mr.Start - seg.Start()) frstart := seg.Value() + (mr.Start - seg.Start())
return platform.FileRange{frstart, frstart + mr.Length()} return memmap.FileRange{frstart, frstart + mr.Length()}
} }
// Fill attempts to ensure that all memmap.Mappable offsets in required are // Fill attempts to ensure that all memmap.Mappable offsets in required are
// mapped to a platform.File offset, by allocating from mf with the given // mapped to a memmap.File offset, by allocating from mf with the given
// memory usage kind and invoking readAt to store data into memory. (If readAt // memory usage kind and invoking readAt to store data into memory. (If readAt
// returns a successful partial read, Fill will call it repeatedly until all // returns a successful partial read, Fill will call it repeatedly until all
// bytes have been read.) EOF is handled consistently with the requirements of // bytes have been read.) EOF is handled consistently with the requirements of
@@ -141,7 +140,7 @@ func (frs *FileRangeSet) Fill(ctx context.Context, required, optional memmap.Map
} }
// Drop removes segments for memmap.Mappable offsets in mr, freeing the // Drop removes segments for memmap.Mappable offsets in mr, freeing the
// corresponding platform.FileRanges. // corresponding memmap.FileRanges.
// //
// Preconditions: mr must be page-aligned. // Preconditions: mr must be page-aligned.
func (frs *FileRangeSet) Drop(mr memmap.MappableRange, mf *pgalloc.MemoryFile) { func (frs *FileRangeSet) Drop(mr memmap.MappableRange, mf *pgalloc.MemoryFile) {
@@ -154,7 +153,7 @@ func (frs *FileRangeSet) Drop(mr memmap.MappableRange, mf *pgalloc.MemoryFile) {
} }
// DropAll removes all segments in mr, freeing the corresponding // DropAll removes all segments in mr, freeing the corresponding
// platform.FileRanges. // memmap.FileRanges.
func (frs *FileRangeSet) DropAll(mf *pgalloc.MemoryFile) { func (frs *FileRangeSet) DropAll(mf *pgalloc.MemoryFile) {
for seg := frs.FirstSegment(); seg.Ok(); seg = seg.NextSegment() { for seg := frs.FirstSegment(); seg.Ok(); seg = seg.NextSegment() {
mf.DecRef(seg.FileRange()) mf.DecRef(seg.FileRange())
+5 -5
View File
@@ -17,7 +17,7 @@ package fsutil
import ( import (
"math" "math"
"gvisor.dev/gvisor/pkg/sentry/platform" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/usage" "gvisor.dev/gvisor/pkg/sentry/usage"
) )
@@ -39,7 +39,7 @@ func (FrameRefSetFunctions) ClearValue(val *uint64) {
} }
// Merge implements segment.Functions.Merge. // Merge implements segment.Functions.Merge.
func (FrameRefSetFunctions) Merge(_ platform.FileRange, val1 uint64, _ platform.FileRange, val2 uint64) (uint64, bool) { func (FrameRefSetFunctions) Merge(_ memmap.FileRange, val1 uint64, _ memmap.FileRange, val2 uint64) (uint64, bool) {
if val1 != val2 { if val1 != val2 {
return 0, false return 0, false
} }
@@ -47,13 +47,13 @@ func (FrameRefSetFunctions) Merge(_ platform.FileRange, val1 uint64, _ platform.
} }
// Split implements segment.Functions.Split. // Split implements segment.Functions.Split.
func (FrameRefSetFunctions) Split(_ platform.FileRange, val uint64, _ uint64) (uint64, uint64) { func (FrameRefSetFunctions) Split(_ memmap.FileRange, val uint64, _ uint64) (uint64, uint64) {
return val, val return val, val
} }
// IncRefAndAccount adds a reference on the range fr. All newly inserted segments // IncRefAndAccount adds a reference on the range fr. All newly inserted segments
// are accounted as host page cache memory mappings. // are accounted as host page cache memory mappings.
func (refs *FrameRefSet) IncRefAndAccount(fr platform.FileRange) { func (refs *FrameRefSet) IncRefAndAccount(fr memmap.FileRange) {
seg, gap := refs.Find(fr.Start) seg, gap := refs.Find(fr.Start)
for { for {
switch { switch {
@@ -74,7 +74,7 @@ func (refs *FrameRefSet) IncRefAndAccount(fr platform.FileRange) {
// DecRefAndAccount removes a reference on the range fr and untracks segments // DecRefAndAccount removes a reference on the range fr and untracks segments
// that are removed from memory accounting. // that are removed from memory accounting.
func (refs *FrameRefSet) DecRefAndAccount(fr platform.FileRange) { func (refs *FrameRefSet) DecRefAndAccount(fr memmap.FileRange) {
seg := refs.FindSegment(fr.Start) seg := refs.FindSegment(fr.Start)
for seg.Ok() && seg.Start() < fr.End { for seg.Ok() && seg.Start() < fr.End {
+2 -3
View File
@@ -21,7 +21,6 @@ import (
"gvisor.dev/gvisor/pkg/log" "gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/safemem" "gvisor.dev/gvisor/pkg/safemem"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sync" "gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/pkg/usermem"
) )
@@ -126,7 +125,7 @@ func (f *HostFileMapper) DecRefOn(mr memmap.MappableRange) {
// offsets in fr or until the next call to UnmapAll. // offsets in fr or until the next call to UnmapAll.
// //
// Preconditions: The caller must hold a reference on all offsets in fr. // Preconditions: The caller must hold a reference on all offsets in fr.
func (f *HostFileMapper) MapInternal(fr platform.FileRange, fd int, write bool) (safemem.BlockSeq, error) { func (f *HostFileMapper) MapInternal(fr memmap.FileRange, fd int, write bool) (safemem.BlockSeq, error) {
chunks := ((fr.End + chunkMask) >> chunkShift) - (fr.Start >> chunkShift) chunks := ((fr.End + chunkMask) >> chunkShift) - (fr.Start >> chunkShift)
f.mapsMu.Lock() f.mapsMu.Lock()
defer f.mapsMu.Unlock() defer f.mapsMu.Unlock()
@@ -146,7 +145,7 @@ func (f *HostFileMapper) MapInternal(fr platform.FileRange, fd int, write bool)
} }
// Preconditions: f.mapsMu must be locked. // Preconditions: f.mapsMu must be locked.
func (f *HostFileMapper) forEachMappingBlockLocked(fr platform.FileRange, fd int, write bool, fn func(safemem.Block)) error { func (f *HostFileMapper) forEachMappingBlockLocked(fr memmap.FileRange, fd int, write bool, fn func(safemem.Block)) error {
prot := syscall.PROT_READ prot := syscall.PROT_READ
if write { if write {
prot |= syscall.PROT_WRITE prot |= syscall.PROT_WRITE
+9 -10
View File
@@ -21,18 +21,17 @@ import (
"gvisor.dev/gvisor/pkg/safemem" "gvisor.dev/gvisor/pkg/safemem"
"gvisor.dev/gvisor/pkg/sentry/fs" "gvisor.dev/gvisor/pkg/sentry/fs"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sync" "gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/pkg/usermem"
) )
// HostMappable implements memmap.Mappable and platform.File over a // HostMappable implements memmap.Mappable and memmap.File over a
// CachedFileObject. // CachedFileObject.
// //
// Lock order (compare the lock order model in mm/mm.go): // Lock order (compare the lock order model in mm/mm.go):
// truncateMu ("fs locks") // truncateMu ("fs locks")
// mu ("memmap.Mappable locks not taken by Translate") // mu ("memmap.Mappable locks not taken by Translate")
// ("platform.File locks") // ("memmap.File locks")
// backingFile ("CachedFileObject locks") // backingFile ("CachedFileObject locks")
// //
// +stateify savable // +stateify savable
@@ -124,24 +123,24 @@ func (h *HostMappable) NotifyChangeFD() error {
return nil return nil
} }
// MapInternal implements platform.File.MapInternal. // MapInternal implements memmap.File.MapInternal.
func (h *HostMappable) MapInternal(fr platform.FileRange, at usermem.AccessType) (safemem.BlockSeq, error) { func (h *HostMappable) MapInternal(fr memmap.FileRange, at usermem.AccessType) (safemem.BlockSeq, error) {
return h.hostFileMapper.MapInternal(fr, h.backingFile.FD(), at.Write) return h.hostFileMapper.MapInternal(fr, h.backingFile.FD(), at.Write)
} }
// FD implements platform.File.FD. // FD implements memmap.File.FD.
func (h *HostMappable) FD() int { func (h *HostMappable) FD() int {
return h.backingFile.FD() return h.backingFile.FD()
} }
// IncRef implements platform.File.IncRef. // IncRef implements memmap.File.IncRef.
func (h *HostMappable) IncRef(fr platform.FileRange) { func (h *HostMappable) IncRef(fr memmap.FileRange) {
mr := memmap.MappableRange{Start: fr.Start, End: fr.End} mr := memmap.MappableRange{Start: fr.Start, End: fr.End}
h.hostFileMapper.IncRefOn(mr) h.hostFileMapper.IncRefOn(mr)
} }
// DecRef implements platform.File.DecRef. // DecRef implements memmap.File.DecRef.
func (h *HostMappable) DecRef(fr platform.FileRange) { func (h *HostMappable) DecRef(fr memmap.FileRange) {
mr := memmap.MappableRange{Start: fr.Start, End: fr.End} mr := memmap.MappableRange{Start: fr.Start, End: fr.End}
h.hostFileMapper.DecRefOn(mr) h.hostFileMapper.DecRefOn(mr)
} }
+12 -13
View File
@@ -26,7 +26,6 @@ import (
ktime "gvisor.dev/gvisor/pkg/sentry/kernel/time" ktime "gvisor.dev/gvisor/pkg/sentry/kernel/time"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/pgalloc" "gvisor.dev/gvisor/pkg/sentry/pgalloc"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sentry/usage" "gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/sync" "gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/pkg/usermem"
@@ -934,7 +933,7 @@ func maxFillRange(required, optional memmap.MappableRange) memmap.MappableRange
// InvalidateUnsavable implements memmap.Mappable.InvalidateUnsavable. // InvalidateUnsavable implements memmap.Mappable.InvalidateUnsavable.
func (c *CachingInodeOperations) InvalidateUnsavable(ctx context.Context) error { func (c *CachingInodeOperations) InvalidateUnsavable(ctx context.Context) error {
// Whether we have a host fd (and consequently what platform.File is // Whether we have a host fd (and consequently what memmap.File is
// mapped) can change across save/restore, so invalidate all translations // mapped) can change across save/restore, so invalidate all translations
// unconditionally. // unconditionally.
c.mapsMu.Lock() c.mapsMu.Lock()
@@ -999,10 +998,10 @@ func (c *CachingInodeOperations) Evict(ctx context.Context, er pgalloc.Evictable
} }
} }
// IncRef implements platform.File.IncRef. This is used when we directly map an // IncRef implements memmap.File.IncRef. This is used when we directly map an
// underlying host fd and CachingInodeOperations is used as the platform.File // underlying host fd and CachingInodeOperations is used as the memmap.File
// during translation. // during translation.
func (c *CachingInodeOperations) IncRef(fr platform.FileRange) { func (c *CachingInodeOperations) IncRef(fr memmap.FileRange) {
// Hot path. Avoid defers. // Hot path. Avoid defers.
c.dataMu.Lock() c.dataMu.Lock()
seg, gap := c.refs.Find(fr.Start) seg, gap := c.refs.Find(fr.Start)
@@ -1024,10 +1023,10 @@ func (c *CachingInodeOperations) IncRef(fr platform.FileRange) {
} }
} }
// DecRef implements platform.File.DecRef. This is used when we directly map an // DecRef implements memmap.File.DecRef. This is used when we directly map an
// underlying host fd and CachingInodeOperations is used as the platform.File // underlying host fd and CachingInodeOperations is used as the memmap.File
// during translation. // during translation.
func (c *CachingInodeOperations) DecRef(fr platform.FileRange) { func (c *CachingInodeOperations) DecRef(fr memmap.FileRange) {
// Hot path. Avoid defers. // Hot path. Avoid defers.
c.dataMu.Lock() c.dataMu.Lock()
seg := c.refs.FindSegment(fr.Start) seg := c.refs.FindSegment(fr.Start)
@@ -1046,15 +1045,15 @@ func (c *CachingInodeOperations) DecRef(fr platform.FileRange) {
c.dataMu.Unlock() c.dataMu.Unlock()
} }
// MapInternal implements platform.File.MapInternal. This is used when we // MapInternal implements memmap.File.MapInternal. This is used when we
// directly map an underlying host fd and CachingInodeOperations is used as the // directly map an underlying host fd and CachingInodeOperations is used as the
// platform.File during translation. // memmap.File during translation.
func (c *CachingInodeOperations) MapInternal(fr platform.FileRange, at usermem.AccessType) (safemem.BlockSeq, error) { func (c *CachingInodeOperations) MapInternal(fr memmap.FileRange, at usermem.AccessType) (safemem.BlockSeq, error) {
return c.hostFileMapper.MapInternal(fr, c.backingFile.FD(), at.Write) return c.hostFileMapper.MapInternal(fr, c.backingFile.FD(), at.Write)
} }
// FD implements platform.File.FD. This is used when we directly map an // FD implements memmap.File.FD. This is used when we directly map an
// underlying host fd and CachingInodeOperations is used as the platform.File // underlying host fd and CachingInodeOperations is used as the memmap.File
// during translation. // during translation.
func (c *CachingInodeOperations) FD() int { func (c *CachingInodeOperations) FD() int {
return c.backingFile.FD() return c.backingFile.FD()
+13 -14
View File
@@ -29,7 +29,6 @@ import (
"gvisor.dev/gvisor/pkg/sentry/fs/fsutil" "gvisor.dev/gvisor/pkg/sentry/fs/fsutil"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/pgalloc" "gvisor.dev/gvisor/pkg/sentry/pgalloc"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sentry/usage" "gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/sentry/vfs" "gvisor.dev/gvisor/pkg/sentry/vfs"
"gvisor.dev/gvisor/pkg/syserror" "gvisor.dev/gvisor/pkg/syserror"
@@ -221,12 +220,12 @@ func (fd *regularFileFD) pwriteLocked(ctx context.Context, src usermem.IOSequenc
return 0, syserror.EINVAL return 0, syserror.EINVAL
} }
mr := memmap.MappableRange{pgstart, pgend} mr := memmap.MappableRange{pgstart, pgend}
var freed []platform.FileRange var freed []memmap.FileRange
d.dataMu.Lock() d.dataMu.Lock()
cseg := d.cache.LowerBoundSegment(mr.Start) cseg := d.cache.LowerBoundSegment(mr.Start)
for cseg.Ok() && cseg.Start() < mr.End { for cseg.Ok() && cseg.Start() < mr.End {
cseg = d.cache.Isolate(cseg, mr) cseg = d.cache.Isolate(cseg, mr)
freed = append(freed, platform.FileRange{cseg.Value(), cseg.Value() + cseg.Range().Length()}) freed = append(freed, memmap.FileRange{cseg.Value(), cseg.Value() + cseg.Range().Length()})
cseg = d.cache.Remove(cseg).NextSegment() cseg = d.cache.Remove(cseg).NextSegment()
} }
d.dataMu.Unlock() d.dataMu.Unlock()
@@ -821,7 +820,7 @@ func maxFillRange(required, optional memmap.MappableRange) memmap.MappableRange
// InvalidateUnsavable implements memmap.Mappable.InvalidateUnsavable. // InvalidateUnsavable implements memmap.Mappable.InvalidateUnsavable.
func (d *dentry) InvalidateUnsavable(ctx context.Context) error { func (d *dentry) InvalidateUnsavable(ctx context.Context) error {
// Whether we have a host fd (and consequently what platform.File is // Whether we have a host fd (and consequently what memmap.File is
// mapped) can change across save/restore, so invalidate all translations // mapped) can change across save/restore, so invalidate all translations
// unconditionally. // unconditionally.
d.mapsMu.Lock() d.mapsMu.Lock()
@@ -869,8 +868,8 @@ func (d *dentry) Evict(ctx context.Context, er pgalloc.EvictableRange) {
} }
} }
// dentryPlatformFile implements platform.File. It exists solely because dentry // dentryPlatformFile implements memmap.File. It exists solely because dentry
// cannot implement both vfs.DentryImpl.IncRef and platform.File.IncRef. // cannot implement both vfs.DentryImpl.IncRef and memmap.File.IncRef.
// //
// dentryPlatformFile is only used when a host FD representing the remote file // dentryPlatformFile is only used when a host FD representing the remote file
// is available (i.e. dentry.handle.fd >= 0), and that FD is used for // is available (i.e. dentry.handle.fd >= 0), and that FD is used for
@@ -878,7 +877,7 @@ func (d *dentry) Evict(ctx context.Context, er pgalloc.EvictableRange) {
type dentryPlatformFile struct { type dentryPlatformFile struct {
*dentry *dentry
// fdRefs counts references on platform.File offsets. fdRefs is protected // fdRefs counts references on memmap.File offsets. fdRefs is protected
// by dentry.dataMu. // by dentry.dataMu.
fdRefs fsutil.FrameRefSet fdRefs fsutil.FrameRefSet
@@ -890,29 +889,29 @@ type dentryPlatformFile struct {
hostFileMapperInitOnce sync.Once hostFileMapperInitOnce sync.Once
} }
// IncRef implements platform.File.IncRef. // IncRef implements memmap.File.IncRef.
func (d *dentryPlatformFile) IncRef(fr platform.FileRange) { func (d *dentryPlatformFile) IncRef(fr memmap.FileRange) {
d.dataMu.Lock() d.dataMu.Lock()
d.fdRefs.IncRefAndAccount(fr) d.fdRefs.IncRefAndAccount(fr)
d.dataMu.Unlock() d.dataMu.Unlock()
} }
// DecRef implements platform.File.DecRef. // DecRef implements memmap.File.DecRef.
func (d *dentryPlatformFile) DecRef(fr platform.FileRange) { func (d *dentryPlatformFile) DecRef(fr memmap.FileRange) {
d.dataMu.Lock() d.dataMu.Lock()
d.fdRefs.DecRefAndAccount(fr) d.fdRefs.DecRefAndAccount(fr)
d.dataMu.Unlock() d.dataMu.Unlock()
} }
// MapInternal implements platform.File.MapInternal. // MapInternal implements memmap.File.MapInternal.
func (d *dentryPlatformFile) MapInternal(fr platform.FileRange, at usermem.AccessType) (safemem.BlockSeq, error) { func (d *dentryPlatformFile) MapInternal(fr memmap.FileRange, at usermem.AccessType) (safemem.BlockSeq, error) {
d.handleMu.RLock() d.handleMu.RLock()
bs, err := d.hostFileMapper.MapInternal(fr, int(d.handle.fd), at.Write) bs, err := d.hostFileMapper.MapInternal(fr, int(d.handle.fd), at.Write)
d.handleMu.RUnlock() d.handleMu.RUnlock()
return bs, err return bs, err
} }
// FD implements platform.File.FD. // FD implements memmap.File.FD.
func (d *dentryPlatformFile) FD() int { func (d *dentryPlatformFile) FD() int {
d.handleMu.RLock() d.handleMu.RLock()
fd := d.handle.fd fd := d.handle.fd
-1
View File
@@ -34,7 +34,6 @@ go_library(
"//pkg/sentry/kernel", "//pkg/sentry/kernel",
"//pkg/sentry/kernel/auth", "//pkg/sentry/kernel/auth",
"//pkg/sentry/memmap", "//pkg/sentry/memmap",
"//pkg/sentry/platform",
"//pkg/sentry/socket/control", "//pkg/sentry/socket/control",
"//pkg/sentry/socket/unix", "//pkg/sentry/socket/unix",
"//pkg/sentry/socket/unix/transport", "//pkg/sentry/socket/unix/transport",
+10 -11
View File
@@ -19,13 +19,12 @@ import (
"gvisor.dev/gvisor/pkg/safemem" "gvisor.dev/gvisor/pkg/safemem"
"gvisor.dev/gvisor/pkg/sentry/fs/fsutil" "gvisor.dev/gvisor/pkg/sentry/fs/fsutil"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sync" "gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/pkg/usermem"
) )
// inodePlatformFile implements platform.File. It exists solely because inode // inodePlatformFile implements memmap.File. It exists solely because inode
// cannot implement both kernfs.Inode.IncRef and platform.File.IncRef. // cannot implement both kernfs.Inode.IncRef and memmap.File.IncRef.
// //
// inodePlatformFile should only be used if inode.canMap is true. // inodePlatformFile should only be used if inode.canMap is true.
type inodePlatformFile struct { type inodePlatformFile struct {
@@ -34,7 +33,7 @@ type inodePlatformFile struct {
// fdRefsMu protects fdRefs. // fdRefsMu protects fdRefs.
fdRefsMu sync.Mutex fdRefsMu sync.Mutex
// fdRefs counts references on platform.File offsets. It is used solely for // fdRefs counts references on memmap.File offsets. It is used solely for
// memory accounting. // memory accounting.
fdRefs fsutil.FrameRefSet fdRefs fsutil.FrameRefSet
@@ -45,32 +44,32 @@ type inodePlatformFile struct {
fileMapperInitOnce sync.Once fileMapperInitOnce sync.Once
} }
// IncRef implements platform.File.IncRef. // IncRef implements memmap.File.IncRef.
// //
// Precondition: i.inode.canMap must be true. // Precondition: i.inode.canMap must be true.
func (i *inodePlatformFile) IncRef(fr platform.FileRange) { func (i *inodePlatformFile) IncRef(fr memmap.FileRange) {
i.fdRefsMu.Lock() i.fdRefsMu.Lock()
i.fdRefs.IncRefAndAccount(fr) i.fdRefs.IncRefAndAccount(fr)
i.fdRefsMu.Unlock() i.fdRefsMu.Unlock()
} }
// DecRef implements platform.File.DecRef. // DecRef implements memmap.File.DecRef.
// //
// Precondition: i.inode.canMap must be true. // Precondition: i.inode.canMap must be true.
func (i *inodePlatformFile) DecRef(fr platform.FileRange) { func (i *inodePlatformFile) DecRef(fr memmap.FileRange) {
i.fdRefsMu.Lock() i.fdRefsMu.Lock()
i.fdRefs.DecRefAndAccount(fr) i.fdRefs.DecRefAndAccount(fr)
i.fdRefsMu.Unlock() i.fdRefsMu.Unlock()
} }
// MapInternal implements platform.File.MapInternal. // MapInternal implements memmap.File.MapInternal.
// //
// Precondition: i.inode.canMap must be true. // Precondition: i.inode.canMap must be true.
func (i *inodePlatformFile) MapInternal(fr platform.FileRange, at usermem.AccessType) (safemem.BlockSeq, error) { func (i *inodePlatformFile) MapInternal(fr memmap.FileRange, at usermem.AccessType) (safemem.BlockSeq, error) {
return i.fileMapper.MapInternal(fr, i.hostFD, at.Write) return i.fileMapper.MapInternal(fr, i.hostFD, at.Write)
} }
// FD implements platform.File.FD. // FD implements memmap.File.FD.
func (i *inodePlatformFile) FD() int { func (i *inodePlatformFile) FD() int {
return i.hostFD return i.hostFD
} }
-1
View File
@@ -20,7 +20,6 @@ go_library(
"//pkg/sentry/kernel/time", "//pkg/sentry/kernel/time",
"//pkg/sentry/memmap", "//pkg/sentry/memmap",
"//pkg/sentry/pgalloc", "//pkg/sentry/pgalloc",
"//pkg/sentry/platform",
"//pkg/sentry/usage", "//pkg/sentry/usage",
"//pkg/sync", "//pkg/sync",
"//pkg/syserror", "//pkg/syserror",
+1 -2
View File
@@ -45,7 +45,6 @@ import (
ktime "gvisor.dev/gvisor/pkg/sentry/kernel/time" ktime "gvisor.dev/gvisor/pkg/sentry/kernel/time"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/pgalloc" "gvisor.dev/gvisor/pkg/sentry/pgalloc"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sentry/usage" "gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/sync" "gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/syserror" "gvisor.dev/gvisor/pkg/syserror"
@@ -370,7 +369,7 @@ type Shm struct {
// fr is the offset into mfp.MemoryFile() that backs this contents of this // fr is the offset into mfp.MemoryFile() that backs this contents of this
// segment. Immutable. // segment. Immutable.
fr platform.FileRange fr memmap.FileRange
// mu protects all fields below. // mu protects all fields below.
mu sync.Mutex `state:"nosave"` mu sync.Mutex `state:"nosave"`
+2 -2
View File
@@ -21,8 +21,8 @@ import (
"gvisor.dev/gvisor/pkg/log" "gvisor.dev/gvisor/pkg/log"
ktime "gvisor.dev/gvisor/pkg/sentry/kernel/time" ktime "gvisor.dev/gvisor/pkg/sentry/kernel/time"
"gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/pgalloc" "gvisor.dev/gvisor/pkg/sentry/pgalloc"
"gvisor.dev/gvisor/pkg/sentry/platform"
sentrytime "gvisor.dev/gvisor/pkg/sentry/time" sentrytime "gvisor.dev/gvisor/pkg/sentry/time"
"gvisor.dev/gvisor/pkg/sync" "gvisor.dev/gvisor/pkg/sync"
) )
@@ -90,7 +90,7 @@ type Timekeeper struct {
// NewTimekeeper does not take ownership of paramPage. // NewTimekeeper does not take ownership of paramPage.
// //
// SetClocks must be called on the returned Timekeeper before it is usable. // SetClocks must be called on the returned Timekeeper before it is usable.
func NewTimekeeper(mfp pgalloc.MemoryFileProvider, paramPage platform.FileRange) (*Timekeeper, error) { func NewTimekeeper(mfp pgalloc.MemoryFileProvider, paramPage memmap.FileRange) (*Timekeeper, error) {
return &Timekeeper{ return &Timekeeper{
params: NewVDSOParamPage(mfp, paramPage), params: NewVDSOParamPage(mfp, paramPage),
}, nil }, nil
+3 -3
View File
@@ -19,8 +19,8 @@ import (
"gvisor.dev/gvisor/pkg/binary" "gvisor.dev/gvisor/pkg/binary"
"gvisor.dev/gvisor/pkg/safemem" "gvisor.dev/gvisor/pkg/safemem"
"gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/pgalloc" "gvisor.dev/gvisor/pkg/sentry/pgalloc"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/pkg/usermem"
) )
@@ -58,7 +58,7 @@ type vdsoParams struct {
type VDSOParamPage struct { type VDSOParamPage struct {
// The parameter page is fr, allocated from mfp.MemoryFile(). // The parameter page is fr, allocated from mfp.MemoryFile().
mfp pgalloc.MemoryFileProvider mfp pgalloc.MemoryFileProvider
fr platform.FileRange fr memmap.FileRange
// seq is the current sequence count written to the page. // seq is the current sequence count written to the page.
// //
@@ -81,7 +81,7 @@ type VDSOParamPage struct {
// * VDSOParamPage must be the only writer to fr. // * VDSOParamPage must be the only writer to fr.
// //
// * mfp.MemoryFile().MapInternal(fr) must return a single safemem.Block. // * mfp.MemoryFile().MapInternal(fr) must return a single safemem.Block.
func NewVDSOParamPage(mfp pgalloc.MemoryFileProvider, fr platform.FileRange) *VDSOParamPage { func NewVDSOParamPage(mfp pgalloc.MemoryFileProvider, fr memmap.FileRange) *VDSOParamPage {
return &VDSOParamPage{mfp: mfp, fr: fr} return &VDSOParamPage{mfp: mfp, fr: fr}
} }
+13 -1
View File
@@ -28,9 +28,21 @@ go_template_instance(
}, },
) )
go_template_instance(
name = "file_range",
out = "file_range.go",
package = "memmap",
prefix = "File",
template = "//pkg/segment:generic_range",
types = {
"T": "uint64",
},
)
go_library( go_library(
name = "memmap", name = "memmap",
srcs = [ srcs = [
"file_range.go",
"mappable_range.go", "mappable_range.go",
"mapping_set.go", "mapping_set.go",
"mapping_set_impl.go", "mapping_set_impl.go",
@@ -40,7 +52,7 @@ go_library(
deps = [ deps = [
"//pkg/context", "//pkg/context",
"//pkg/log", "//pkg/log",
"//pkg/sentry/platform", "//pkg/safemem",
"//pkg/syserror", "//pkg/syserror",
"//pkg/usermem", "//pkg/usermem",
], ],
+53 -7
View File
@@ -19,12 +19,12 @@ import (
"fmt" "fmt"
"gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/sentry/platform" "gvisor.dev/gvisor/pkg/safemem"
"gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/pkg/usermem"
) )
// Mappable represents a memory-mappable object, a mutable mapping from uint64 // Mappable represents a memory-mappable object, a mutable mapping from uint64
// offsets to (platform.File, uint64 File offset) pairs. // offsets to (File, uint64 File offset) pairs.
// //
// See mm/mm.go for Mappable's place in the lock order. // See mm/mm.go for Mappable's place in the lock order.
// //
@@ -74,7 +74,7 @@ type Mappable interface {
// Translations are valid until invalidated by a callback to // Translations are valid until invalidated by a callback to
// MappingSpace.Invalidate or until the caller removes its mapping of the // MappingSpace.Invalidate or until the caller removes its mapping of the
// translated range. Mappable implementations must ensure that at least one // translated range. Mappable implementations must ensure that at least one
// reference is held on all pages in a platform.File that may be the result // reference is held on all pages in a File that may be the result
// of a valid Translation. // of a valid Translation.
// //
// Preconditions: required.Length() > 0. optional.IsSupersetOf(required). // Preconditions: required.Length() > 0. optional.IsSupersetOf(required).
@@ -100,7 +100,7 @@ type Translation struct {
Source MappableRange Source MappableRange
// File is the mapped file. // File is the mapped file.
File platform.File File File
// Offset is the offset into File at which this Translation begins. // Offset is the offset into File at which this Translation begins.
Offset uint64 Offset uint64
@@ -110,9 +110,9 @@ type Translation struct {
Perms usermem.AccessType Perms usermem.AccessType
} }
// FileRange returns the platform.FileRange represented by t. // FileRange returns the FileRange represented by t.
func (t Translation) FileRange() platform.FileRange { func (t Translation) FileRange() FileRange {
return platform.FileRange{t.Offset, t.Offset + t.Source.Length()} return FileRange{t.Offset, t.Offset + t.Source.Length()}
} }
// CheckTranslateResult returns an error if (ts, terr) does not satisfy all // CheckTranslateResult returns an error if (ts, terr) does not satisfy all
@@ -361,3 +361,49 @@ type MMapOpts struct {
// TODO(jamieliu): Replace entirely with MappingIdentity? // TODO(jamieliu): Replace entirely with MappingIdentity?
Hint string Hint string
} }
// File represents a host file that may be mapped into an platform.AddressSpace.
type File interface {
// All pages in a File are reference-counted.
// IncRef increments the reference count on all pages in fr.
//
// Preconditions: fr.Start and fr.End must be page-aligned. fr.Length() >
// 0. At least one reference must be held on all pages in fr. (The File
// interface does not provide a way to acquire an initial reference;
// implementors may define mechanisms for doing so.)
IncRef(fr FileRange)
// DecRef decrements the reference count on all pages in fr.
//
// Preconditions: fr.Start and fr.End must be page-aligned. fr.Length() >
// 0. At least one reference must be held on all pages in fr.
DecRef(fr FileRange)
// MapInternal returns a mapping of the given file offsets in the invoking
// process' address space for reading and writing.
//
// Note that fr.Start and fr.End need not be page-aligned.
//
// Preconditions: fr.Length() > 0. At least one reference must be held on
// all pages in fr.
//
// Postconditions: The returned mapping is valid as long as at least one
// reference is held on the mapped pages.
MapInternal(fr FileRange, at usermem.AccessType) (safemem.BlockSeq, error)
// FD returns the file descriptor represented by the File.
//
// The only permitted operation on the returned file descriptor is to map
// pages from it consistent with the requirements of AddressSpace.MapFile.
FD() int
}
// FileRange represents a range of uint64 offsets into a File.
//
// type FileRange <generated using go_generics>
// String implements fmt.Stringer.String.
func (fr FileRange) String() string {
return fmt.Sprintf("[%#x, %#x)", fr.Start, fr.End)
}
+2 -2
View File
@@ -7,14 +7,14 @@ go_template_instance(
name = "file_refcount_set", name = "file_refcount_set",
out = "file_refcount_set.go", out = "file_refcount_set.go",
imports = { imports = {
"platform": "gvisor.dev/gvisor/pkg/sentry/platform", "memmap": "gvisor.dev/gvisor/pkg/sentry/memmap",
}, },
package = "mm", package = "mm",
prefix = "fileRefcount", prefix = "fileRefcount",
template = "//pkg/segment:generic_set", template = "//pkg/segment:generic_set",
types = { types = {
"Key": "uint64", "Key": "uint64",
"Range": "platform.FileRange", "Range": "memmap.FileRange",
"Value": "int32", "Value": "int32",
"Functions": "fileRefcountSetFunctions", "Functions": "fileRefcountSetFunctions",
}, },
+1 -2
View File
@@ -20,7 +20,6 @@ import (
"gvisor.dev/gvisor/pkg/refs" "gvisor.dev/gvisor/pkg/refs"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/pgalloc" "gvisor.dev/gvisor/pkg/sentry/pgalloc"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sentry/usage" "gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/sync" "gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/syserror" "gvisor.dev/gvisor/pkg/syserror"
@@ -243,7 +242,7 @@ type aioMappable struct {
refs.AtomicRefCount refs.AtomicRefCount
mfp pgalloc.MemoryFileProvider mfp pgalloc.MemoryFileProvider
fr platform.FileRange fr memmap.FileRange
} }
var aioRingBufferSize = uint64(usermem.Addr(linux.AIORingSize).MustRoundUp()) var aioRingBufferSize = uint64(usermem.Addr(linux.AIORingSize).MustRoundUp())
+5 -5
View File
@@ -25,7 +25,7 @@
// Locks taken by memmap.Mappable.Translate // Locks taken by memmap.Mappable.Translate
// mm.privateRefs.mu // mm.privateRefs.mu
// platform.AddressSpace locks // platform.AddressSpace locks
// platform.File locks // memmap.File locks
// mm.aioManager.mu // mm.aioManager.mu
// mm.AIOContext.mu // mm.AIOContext.mu
// //
@@ -396,7 +396,7 @@ type pma struct {
// file is the file mapped by this pma. Only pmas for which file == // file is the file mapped by this pma. Only pmas for which file ==
// MemoryManager.mfp.MemoryFile() may be saved. pmas hold a reference to // MemoryManager.mfp.MemoryFile() may be saved. pmas hold a reference to
// the corresponding file range while they exist. // the corresponding file range while they exist.
file platform.File `state:"nosave"` file memmap.File `state:"nosave"`
// off is the offset into file at which this pma begins. // off is the offset into file at which this pma begins.
// //
@@ -436,7 +436,7 @@ type pma struct {
private bool private bool
// If internalMappings is not empty, it is the cached return value of // If internalMappings is not empty, it is the cached return value of
// file.MapInternal for the platform.FileRange mapped by this pma. // file.MapInternal for the memmap.FileRange mapped by this pma.
internalMappings safemem.BlockSeq `state:"nosave"` internalMappings safemem.BlockSeq `state:"nosave"`
} }
@@ -469,10 +469,10 @@ func (fileRefcountSetFunctions) MaxKey() uint64 {
func (fileRefcountSetFunctions) ClearValue(_ *int32) { func (fileRefcountSetFunctions) ClearValue(_ *int32) {
} }
func (fileRefcountSetFunctions) Merge(_ platform.FileRange, rc1 int32, _ platform.FileRange, rc2 int32) (int32, bool) { func (fileRefcountSetFunctions) Merge(_ memmap.FileRange, rc1 int32, _ memmap.FileRange, rc2 int32) (int32, bool) {
return rc1, rc1 == rc2 return rc1, rc1 == rc2
} }
func (fileRefcountSetFunctions) Split(_ platform.FileRange, rc int32, _ uint64) (int32, int32) { func (fileRefcountSetFunctions) Split(_ memmap.FileRange, rc int32, _ uint64) (int32, int32) {
return rc, rc return rc, rc
} }
+12 -13
View File
@@ -21,7 +21,6 @@ import (
"gvisor.dev/gvisor/pkg/safecopy" "gvisor.dev/gvisor/pkg/safecopy"
"gvisor.dev/gvisor/pkg/safemem" "gvisor.dev/gvisor/pkg/safemem"
"gvisor.dev/gvisor/pkg/sentry/memmap" "gvisor.dev/gvisor/pkg/sentry/memmap"
"gvisor.dev/gvisor/pkg/sentry/platform"
"gvisor.dev/gvisor/pkg/sentry/usage" "gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/syserror" "gvisor.dev/gvisor/pkg/syserror"
"gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/pkg/usermem"
@@ -604,7 +603,7 @@ func (mm *MemoryManager) invalidateLocked(ar usermem.AddrRange, invalidatePrivat
} }
} }
// Pin returns the platform.File ranges currently mapped by addresses in ar in // Pin returns the memmap.File ranges currently mapped by addresses in ar in
// mm, acquiring a reference on the returned ranges which the caller must // mm, acquiring a reference on the returned ranges which the caller must
// release by calling Unpin. If not all addresses are mapped, Pin returns a // release by calling Unpin. If not all addresses are mapped, Pin returns a
// non-nil error. Note that Pin may return both a non-empty slice of // non-nil error. Note that Pin may return both a non-empty slice of
@@ -674,15 +673,15 @@ type PinnedRange struct {
Source usermem.AddrRange Source usermem.AddrRange
// File is the mapped file. // File is the mapped file.
File platform.File File memmap.File
// Offset is the offset into File at which this PinnedRange begins. // Offset is the offset into File at which this PinnedRange begins.
Offset uint64 Offset uint64
} }
// FileRange returns the platform.File offsets mapped by pr. // FileRange returns the memmap.File offsets mapped by pr.
func (pr PinnedRange) FileRange() platform.FileRange { func (pr PinnedRange) FileRange() memmap.FileRange {
return platform.FileRange{pr.Offset, pr.Offset + uint64(pr.Source.Length())} return memmap.FileRange{pr.Offset, pr.Offset + uint64(pr.Source.Length())}
} }
// Unpin releases the reference held by prs. // Unpin releases the reference held by prs.
@@ -857,7 +856,7 @@ func (mm *MemoryManager) vecInternalMappingsLocked(ars usermem.AddrRangeSeq) saf
} }
// incPrivateRef acquires a reference on private pages in fr. // incPrivateRef acquires a reference on private pages in fr.
func (mm *MemoryManager) incPrivateRef(fr platform.FileRange) { func (mm *MemoryManager) incPrivateRef(fr memmap.FileRange) {
mm.privateRefs.mu.Lock() mm.privateRefs.mu.Lock()
defer mm.privateRefs.mu.Unlock() defer mm.privateRefs.mu.Unlock()
refSet := &mm.privateRefs.refs refSet := &mm.privateRefs.refs
@@ -878,8 +877,8 @@ func (mm *MemoryManager) incPrivateRef(fr platform.FileRange) {
} }
// decPrivateRef releases a reference on private pages in fr. // decPrivateRef releases a reference on private pages in fr.
func (mm *MemoryManager) decPrivateRef(fr platform.FileRange) { func (mm *MemoryManager) decPrivateRef(fr memmap.FileRange) {
var freed []platform.FileRange var freed []memmap.FileRange
mm.privateRefs.mu.Lock() mm.privateRefs.mu.Lock()
refSet := &mm.privateRefs.refs refSet := &mm.privateRefs.refs
@@ -951,7 +950,7 @@ func (pmaSetFunctions) Merge(ar1 usermem.AddrRange, pma1 pma, ar2 usermem.AddrRa
// Discard internal mappings instead of trying to merge them, since merging // Discard internal mappings instead of trying to merge them, since merging
// them requires an allocation and getting them again from the // them requires an allocation and getting them again from the
// platform.File might not. // memmap.File might not.
pma1.internalMappings = safemem.BlockSeq{} pma1.internalMappings = safemem.BlockSeq{}
return pma1, true return pma1, true
} }
@@ -1012,12 +1011,12 @@ func (pseg pmaIterator) getInternalMappingsLocked() error {
return nil return nil
} }
func (pseg pmaIterator) fileRange() platform.FileRange { func (pseg pmaIterator) fileRange() memmap.FileRange {
return pseg.fileRangeOf(pseg.Range()) return pseg.fileRangeOf(pseg.Range())
} }
// Preconditions: pseg.Range().IsSupersetOf(ar). ar.Length != 0. // Preconditions: pseg.Range().IsSupersetOf(ar). ar.Length != 0.
func (pseg pmaIterator) fileRangeOf(ar usermem.AddrRange) platform.FileRange { func (pseg pmaIterator) fileRangeOf(ar usermem.AddrRange) memmap.FileRange {
if checkInvariants { if checkInvariants {
if !pseg.Ok() { if !pseg.Ok() {
panic("terminal pma iterator") panic("terminal pma iterator")
@@ -1032,5 +1031,5 @@ func (pseg pmaIterator) fileRangeOf(ar usermem.AddrRange) platform.FileRange {
pma := pseg.ValuePtr() pma := pseg.ValuePtr()
pstart := pseg.Start() pstart := pseg.Start()
return platform.FileRange{pma.off + uint64(ar.Start-pstart), pma.off + uint64(ar.End-pstart)} return memmap.FileRange{pma.off + uint64(ar.Start-pstart), pma.off + uint64(ar.End-pstart)}
} }

Some files were not shown because too many files have changed in this diff Show More