Source file
src/runtime/pprof/vminfo_darwin.go
1
2
3
4
5 package pprof
6
7 import (
8 "os"
9 "unsafe"
10 )
11
12 func isExecutable(protection int32) bool {
13 return (protection&_VM_PROT_EXECUTE) != 0 && (protection&_VM_PROT_READ) != 0
14 }
15
16
17
18 func machVMInfo(addMapping func(lo, hi, offset uint64, file, buildID string)) bool {
19 added := false
20 var addr uint64 = 0x1
21 for {
22 var memRegionSize uint64
23 var info machVMRegionBasicInfoData
24
25 kr := mach_vm_region(
26 &addr,
27 &memRegionSize,
28 unsafe.Pointer(&info))
29 if kr != 0 {
30 if kr == _MACH_SEND_INVALID_DEST {
31
32 return true
33 }
34 return added
35 }
36 if isExecutable(info.Protection) {
37
38
39
40 addMapping(addr,
41 addr+memRegionSize,
42 read64(&info.Offset),
43 regionFilename(addr),
44 "")
45 added = true
46 }
47 addr += memRegionSize
48 }
49 }
50
51 func read64(p *[8]byte) uint64 {
52
53 return uint64(p[0]) | uint64(p[1])<<8 | uint64(p[2])<<16 | uint64(p[3])<<24 | uint64(p[4])<<32 | uint64(p[5])<<40 | uint64(p[6])<<48 | uint64(p[7])<<56
54 }
55
56 func regionFilename(address uint64) string {
57 buf := make([]byte, _MAXPATHLEN)
58 r := proc_regionfilename(
59 os.Getpid(),
60 address,
61 unsafe.SliceData(buf),
62 int64(cap(buf)))
63 if r == 0 {
64 return ""
65 }
66 return string(buf[:r])
67 }
68
69
70
71
72
73 func mach_vm_region(address, region_size *uint64, info unsafe.Pointer) int32
74
75
76 func proc_regionfilename(pid int, address uint64, buf *byte, buflen int64) int32
77
View as plain text