MCPcopy Index your code
hub / github.com/google/gvisor / MapInternal

Method MapInternal

pkg/sentry/pgalloc/pgalloc.go:1434–1462  ·  view source on GitHub ↗

MapInternal implements memmap.File.MapInternal.

(fr memmap.FileRange, at hostarch.AccessType)

Source from the content-addressed store, hash-verified

1432
1433// MapInternal implements memmap.File.MapInternal.
1434func (f *MemoryFile) MapInternal(fr memmap.FileRange, at hostarch.AccessType) (safemem.BlockSeq, error) {
1435 if !fr.WellFormed() || fr.Length() == 0 {
1436 panic(fmt.Sprintf("invalid range: %v", fr))
1437 }
1438 if at.Execute {
1439 return safemem.BlockSeq{}, linuxerr.EACCES
1440 }
1441
1442 if amfl := f.asyncPageLoad.Load(); amfl != nil {
1443 if err := amfl.awaitLoad(fr); err != nil {
1444 return safemem.BlockSeq{}, err
1445 }
1446 }
1447
1448 chunks := ((fr.End + chunkMask) / chunkSize) - (fr.Start / chunkSize)
1449 if chunks == 1 {
1450 // Avoid an unnecessary slice allocation.
1451 var seq safemem.BlockSeq
1452 f.forEachMappingSlice(fr, func(bs []byte) {
1453 seq = safemem.BlockSeqOf(safemem.BlockFromSafeSlice(bs))
1454 })
1455 return seq, nil
1456 }
1457 blocks := make([]safemem.Block, 0, chunks)
1458 f.forEachMappingSlice(fr, func(bs []byte) {
1459 blocks = append(blocks, safemem.BlockFromSafeSlice(bs))
1460 })
1461 return safemem.BlockSeqFromSlice(blocks), nil
1462}
1463
1464// forEachMappingSlice invokes fn on a sequence of byte slices that
1465// collectively map all bytes in fr.

Callers 1

AllocateMethod · 0.95

Calls 8

forEachMappingSliceMethod · 0.95
BlockSeqOfFunction · 0.92
BlockFromSafeSliceFunction · 0.92
BlockSeqFromSliceFunction · 0.92
WellFormedMethod · 0.80
awaitLoadMethod · 0.80
LoadMethod · 0.65
LengthMethod · 0.45

Tested by

no test coverage detected