AllocationSize calculates the private region size to which the frame return address pertains if the memory pages within the region are private and non-shareable pages.
(proc windows.Handle)
| 80 | // memory pages within the region are private and |
| 81 | // non-shareable pages. |
| 82 | func (f *Frame) AllocationSize(proc windows.Handle) uint64 { |
| 83 | if f.Addr.InSystemRange() { |
| 84 | return 0 |
| 85 | } |
| 86 | |
| 87 | r := va.VirtualQuery(proc, f.Addr.Uint64()) |
| 88 | |
| 89 | if r == nil || (r.State != windows.MEM_COMMIT || r.Protect == windows.PAGE_NOACCESS || r.Type != va.MemImage) { |
| 90 | return 0 |
| 91 | } |
| 92 | |
| 93 | pageCount := r.Size / pageSize |
| 94 | m := make([]sys.MemoryWorkingSetExInformation, pageCount) |
| 95 | for n := range pageCount { |
| 96 | addr := f.Addr.Inc(n * pageSize) |
| 97 | m[n].VirtualAddress = addr.Uintptr() |
| 98 | } |
| 99 | |
| 100 | ws := va.QueryWorkingSet(proc, m) |
| 101 | if ws == nil { |
| 102 | return 0 |
| 103 | } |
| 104 | |
| 105 | var size uint64 |
| 106 | |
| 107 | // traverse all pages in the region |
| 108 | for _, r := range ws { |
| 109 | attr := r.VirtualAttributes |
| 110 | if !attr.Valid() { |
| 111 | continue |
| 112 | } |
| 113 | |
| 114 | // use SharedOriginal after RS3/1709 |
| 115 | if buildNumber >= 16299 { |
| 116 | if !attr.SharedOriginal() { |
| 117 | size += pageSize |
| 118 | } |
| 119 | } else { |
| 120 | if !attr.Shared() { |
| 121 | size += pageSize |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | return size |
| 127 | } |
| 128 | |
| 129 | // Protection resolves the memory protection |
| 130 | // of the pages within the region that contains the |
no test coverage detected