aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mranges.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2020-04-28 21:30:57 +0000
committerMichael Knyszek <mknyszek@google.com>2020-05-08 16:32:03 +0000
commitea5f9b666ccf7affca596be3ab0dc523ca4444fb (patch)
tree5fa08a27635a5d1a65384d071c16229c4fd200c8 /src/runtime/mranges.go
parentd69509ff995bf3b92246365980e3d27eaf720e6a (diff)
downloadgo-ea5f9b666ccf7affca596be3ab0dc523ca4444fb.tar.gz
go-ea5f9b666ccf7affca596be3ab0dc523ca4444fb.zip
runtime: use offAddr in more parts of the runtime
This change uses the new offAddr type in more parts of the runtime where we've been implicitly switching from the default address space to a contiguous view. The purpose of offAddr is to represent addresses in the contiguous view of the address space, and to make direct computations between real addresses and offset addresses impossible. This change thus improves readability in the runtime. Updates #35788. Change-Id: I4e1c5fed3ed68aa12f49a42b82eb3f46aba82fc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/230718 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mranges.go')
-rw-r--r--src/runtime/mranges.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/runtime/mranges.go b/src/runtime/mranges.go
index 468a73057b..e574c2f518 100644
--- a/src/runtime/mranges.go
+++ b/src/runtime/mranges.go
@@ -69,6 +69,31 @@ func (a addrRange) subtract(b addrRange) addrRange {
return a
}
+var (
+ // minOffAddr is the minimum address in the offset space, and
+ // it corresponds to the virtual address -arenaBaseOffset.
+ //
+ // We don't initialize this with offAddrFromRaw because allocation
+ // may happen during bootstrapping, and we rely on this value
+ // being initialized.
+ //
+ // As a result, creating this value in Go is tricky because of
+ // overflow not being allowed in constants. In order to get
+ // the value we want, we take arenaBaseOffset and do a manual
+ // two's complement negation, then mask that into what can fit
+ // into a uintptr.
+ minOffAddr = offAddr{((^arenaBaseOffset) + 1) & uintptrMask}
+
+ // maxOffAddr is the maximum address in the offset address
+ // space, and it corresponds to the virtual address
+ // ^uintptr(0) - arenaBaseOffset.
+ //
+ // We don't initialize this with offAddrFromRaw because allocation
+ // may happen during bootstrapping, and we rely on this value
+ // being initialized.
+ maxOffAddr = offAddr{^uintptr(0) - arenaBaseOffset}
+)
+
// offAddr represents an address in a contiguous view
// of the address space on systems where the address space is
// segmented. On other systems, it's just a normal address.
@@ -268,7 +293,7 @@ func (a *addrRanges) removeGreaterEqual(addr uintptr) {
}
if r := a.ranges[pivot-1]; r.contains(addr) {
removed += r.size()
- r = r.subtract(makeAddrRange(addr, maxSearchAddr))
+ r = r.subtract(makeAddrRange(addr, maxOffAddr.addr()))
if r.size() == 0 {
pivot--
} else {