aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorJoel Sing <joel@sing.id.au>2025-07-22 15:26:56 +0000
committerJoel Sing <joel@sing.id.au>2025-08-26 01:38:57 -0700
commitdae9e456ae6992b3c19a8c5039090ee9ca4d9b7d (patch)
tree663ee7faf103bd6633b59a320d729d834b6cedd9 /src/runtime
parent25c2d4109f5061425ca2633fb12450d43839bb79 (diff)
downloadgo-dae9e456ae6992b3c19a8c5039090ee9ca4d9b7d.tar.xz
runtime: identify virtual memory layout for riscv64
Identify sv39, sv48 and sv57 based on the system stack address. The current approach to memory allocation is less than ideal on RISC-V hardware that is using sv39 mode. On sv39 we currently end up doing around 85 mmap and 66 munmap, since we are trying to map an unusable range. With this change we do 22 mmap and 0 munmap at runtime initialisation. This will also be necessary to support the race detector on sv39. Updates #64345 Cq-Include-Trybots: luci.golang.try:gotip-linux-riscv64 Change-Id: I4f8ba6763b5ecfedfad5438e025d633820e8265c Reviewed-on: https://go-review.googlesource.com/c/go/+/690495 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/malloc.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index d21b2c49b5..29e41147f0 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -580,6 +580,16 @@ func mallocinit() {
randHeapBasePrefix = byte(randHeapBase >> (randHeapAddrBits - 8))
}
+ var vmaSize int
+ if GOARCH == "riscv64" {
+ // Identify which memory layout is in use based on the system
+ // stack address, knowing that the bottom half of virtual memory
+ // is user space. This should result in 39, 48 or 57. It may be
+ // possible to use RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS at some
+ // point in the future - for now use the system stack address.
+ vmaSize = sys.Len64(uint64(getg().m.g0.stack.hi)) + 1
+ }
+
for i := 0x7f; i >= 0; i-- {
var p uintptr
switch {
@@ -598,6 +608,8 @@ func mallocinit() {
p = uintptr(i)<<40 | uintptrMask&(0x0013<<28)
case GOARCH == "arm64":
p = uintptr(i)<<40 | uintptrMask&(0x0040<<32)
+ case GOARCH == "riscv64" && vmaSize == 39:
+ p = uintptr(i)<<32 | uintptrMask&(0x0013<<28)
case GOOS == "aix":
if i == 0 {
// We don't use addresses directly after 0x0A00000000000000