From 8bcda6c79d40f49363cd04cdaf5bd7909de8f94f Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Fri, 25 Jul 2025 20:41:51 +1000 Subject: runtime/race: add race detector support for linux/riscv64 This enables support for the race detector on linux/riscv64. Fixes #64345 Cq-Include-Trybots: luci.golang.try:gotip-linux-riscv64 Change-Id: I98962827e91455404858549b0f9691ee438f104b Reviewed-on: https://go-review.googlesource.com/c/go/+/690497 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Reviewed-by: Meng Zhuo Reviewed-by: Carlos Amedee --- src/runtime/malloc.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/runtime/malloc.go') diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 29e41147f0..ec5f0765ba 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -588,11 +588,20 @@ func mallocinit() { // 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 + if raceenabled && vmaSize != 39 && vmaSize != 48 { + println("vma size = ", vmaSize) + throw("riscv64 vma size is unknown and race mode is enabled") + } } for i := 0x7f; i >= 0; i-- { var p uintptr switch { + case raceenabled && GOARCH == "riscv64" && vmaSize == 39: + p = uintptr(i)<<28 | uintptrMask&(0x0013<<28) + if p >= uintptrMask&0x000f00000000 { + continue + } case raceenabled: // The TSAN runtime requires the heap // to be in the range [0x00c000000000, -- cgit v1.3-5-g9baa