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