type addrRange … // makeAddrRange creates a new address range from two virtual addresses. // // Throws if the base and limit are not in the same memory segment. func makeAddrRange(base, limit uintptr) addrRange { … } // size returns the size of the range represented in bytes. func (a addrRange) size() uintptr { … } // contains returns whether or not the range contains a given address. func (a addrRange) contains(addr uintptr) bool { … } // subtract takes the addrRange toPrune and cuts out any overlap with // from, then returns the new range. subtract assumes that a and b // either don't overlap at all, only overlap on one side, or are equal. // If b is strictly contained in a, thus forcing a split, it will throw. func (a addrRange) subtract(b addrRange) addrRange { … } // takeFromFront takes len bytes from the front of the address range, aligning // the base to align first. On success, returns the aligned start of the region // taken and true. func (a *addrRange) takeFromFront(len uintptr, align uint8) (uintptr, bool) { … } // takeFromBack takes len bytes from the end of the address range, aligning // the limit to align after subtracting len. On success, returns the aligned // start of the region taken and true. func (a *addrRange) takeFromBack(len uintptr, align uint8) (uintptr, bool) { … } // removeGreaterEqual removes all addresses in a greater than or equal // to addr and returns the new range. func (a addrRange) removeGreaterEqual(addr uintptr) addrRange { … } var minOffAddr … var maxOffAddr … type offAddr … // add adds a uintptr offset to the offAddr. func (l offAddr) add(bytes uintptr) offAddr { … } // sub subtracts a uintptr offset from the offAddr. func (l offAddr) sub(bytes uintptr) offAddr { … } // diff returns the amount of bytes in between the // two offAddrs. func (l1 offAddr) diff(l2 offAddr) uintptr { … } // lessThan returns true if l1 is less than l2 in the offset // address space. func (l1 offAddr) lessThan(l2 offAddr) bool { … } // lessEqual returns true if l1 is less than or equal to l2 in // the offset address space. func (l1 offAddr) lessEqual(l2 offAddr) bool { … } // equal returns true if the two offAddr values are equal. func (l1 offAddr) equal(l2 offAddr) bool { … } // addr returns the virtual address for this offset address. func (l offAddr) addr() uintptr { … } type atomicOffAddr … // Clear attempts to store minOffAddr in atomicOffAddr. It may fail // if a marked value is placed in the box in the meanwhile. func (b *atomicOffAddr) Clear() { … } // StoreMin stores addr if it's less than the current value in the // offset address space if the current value is not marked. func (b *atomicOffAddr) StoreMin(addr uintptr) { … } // StoreUnmark attempts to unmark the value in atomicOffAddr and // replace it with newAddr. markedAddr must be a marked address // returned by Load. This function will not store newAddr if the // box no longer contains markedAddr. func (b *atomicOffAddr) StoreUnmark(markedAddr, newAddr uintptr) { … } // StoreMarked stores addr but first converted to the offset address // space and then negated. func (b *atomicOffAddr) StoreMarked(addr uintptr) { … } // Load returns the address in the box as a virtual address. It also // returns if the value was marked or not. func (b *atomicOffAddr) Load() (uintptr, bool) { … } type addrRanges … func (a *addrRanges) init(sysStat *sysMemStat) { … } // findSucc returns the first index in a such that addr is // less than the base of the addrRange at that index. func (a *addrRanges) findSucc(addr uintptr) int { … } // findAddrGreaterEqual returns the smallest address represented by a // that is >= addr. Thus, if the address is represented by a, // then it returns addr. The second return value indicates whether // such an address exists for addr in a. That is, if addr is larger than // any address known to a, the second return value will be false. func (a *addrRanges) findAddrGreaterEqual(addr uintptr) (uintptr, bool) { … } // contains returns true if a covers the address addr. func (a *addrRanges) contains(addr uintptr) bool { … } // add inserts a new address range to a. // // r must not overlap with any address range in a and r.size() must be > 0. func (a *addrRanges) add(r addrRange) { … } // removeLast removes and returns the highest-addressed contiguous range // of a, or the last nBytes of that range, whichever is smaller. If a is // empty, it returns an empty range. func (a *addrRanges) removeLast(nBytes uintptr) addrRange { … } // removeGreaterEqual removes the ranges of a which are above addr, and additionally // splits any range containing addr. func (a *addrRanges) removeGreaterEqual(addr uintptr) { … } // cloneInto makes a deep clone of a's state into b, re-using // b's ranges if able. func (a *addrRanges) cloneInto(b *addrRanges) { … }