MapInternal implements memmap.File.MapInternal.
(fr memmap.FileRange, at hostarch.AccessType)
| 1432 | |
| 1433 | // MapInternal implements memmap.File.MapInternal. |
| 1434 | func (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. |
no test coverage detected