...
Source file src/pkg/cmd/compile/internal/gc/mapfile_mmap.go
1
2
3
4
5
6
7 package gc
8
9 import (
10 "os"
11 "reflect"
12 "syscall"
13 "unsafe"
14 )
15
16
17
18
19
20
21 func mapFile(f *os.File, offset, length int64) (string, error) {
22
23
24 x := offset & int64(os.Getpagesize()-1)
25 offset -= x
26 length += x
27
28 buf, err := syscall.Mmap(int(f.Fd()), offset, int(length), syscall.PROT_READ, syscall.MAP_SHARED)
29 keepAlive(f)
30 if err != nil {
31 return "", err
32 }
33
34 buf = buf[x:]
35 pSlice := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
36
37 var res string
38 pString := (*reflect.StringHeader)(unsafe.Pointer(&res))
39
40 pString.Data = pSlice.Data
41 pString.Len = pSlice.Len
42
43 return res, nil
44 }
45
46
47
48 var keepAlive = func(interface{}) {}
49
View as plain text