github.com/iDigitalFlame/xmt@v0.5.4/device/winapi/mem_v10.go (about) 1 //go:build windows && cgo && freemem && go1.10 && !go1.11 2 // +build windows,cgo,freemem,go1.10,!go1.11 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package winapi 21 22 import "unsafe" 23 24 //go:linkname gcBitsArenas runtime.gcBitsArenas 25 var gcBitsArenas [4]uintptr 26 27 type mheap struct { 28 _ uintptr 29 _ [256]uintptr 30 freeLarge *treapNode 31 _ [256]uintptr 32 _, _ uintptr 33 _, _, _ uint32 34 allspans []*mspan 35 spans []*mspan 36 _ [2]struct { 37 _, _, _, _ uintptr 38 _ uint32 39 } 40 _ uint32 41 _, _, _, _ uint64 42 _ float64 43 _, _, _, _ uint64 44 _ [67]uint64 45 _, _ uintptr 46 base uintptr 47 _, _ uintptr 48 end uintptr 49 _ bool 50 _ [134]struct { 51 _ uintptr 52 _ uint8 53 _, _, _, _ uintptr 54 _ uint64 55 _ [cacheLineSize - ((5*ptrSize)+9)%cacheLineSize]byte 56 } 57 spanalloc fixalloc 58 cachealloc fixalloc 59 treapalloc fixalloc 60 specialfinalizeralloc fixalloc 61 specialprofilealloc fixalloc 62 } 63 type mspan struct { 64 _, _ *mspan 65 _ uintptr 66 startAddr uintptr 67 } 68 type fixalloc struct { 69 _, _, _, _ uintptr 70 chunk uintptr 71 _ uint32 72 inuse uintptr 73 _ uintptr 74 _ bool 75 } 76 type treapNode struct { 77 _, _ uintptr 78 parent *treapNode 79 _ uintptr 80 spanKey uintptr 81 } 82 83 func enumRuntimeMemory(h *mheap, m memoryMap) { 84 for x := h.freeLarge; x != nil; x = x.parent { 85 m.add(x.spanKey) 86 } 87 for i := 1; i < len(gcBitsArenas); i++ { 88 m.add(gcBitsArenas[i]) 89 } 90 if len(h.allspans) > 0 { 91 for i := range h.allspans { 92 if h.allspans[i] != nil { 93 m.add(h.allspans[i].startAddr) 94 } 95 } 96 m.add(uintptr(unsafe.Pointer(&h.allspans[0]))) 97 } 98 for i := range h.spans { 99 if h.spans[i] != nil { 100 m.add(h.spans[i].startAddr) 101 } 102 } 103 if m.add(h.base); h.end > 1 { 104 m.add(h.end - 1) 105 } 106 m.add(h.spanalloc.chunk) 107 m.add(h.spanalloc.inuse) 108 m.add(h.cachealloc.chunk) 109 m.add(h.cachealloc.inuse) 110 m.add(h.treapalloc.chunk) 111 m.add(h.treapalloc.inuse) 112 m.add(h.specialfinalizeralloc.chunk) 113 m.add(h.specialfinalizeralloc.inuse) 114 m.add(h.specialprofilealloc.chunk) 115 m.add(h.specialprofilealloc.inuse) 116 }