From a95454b6f31a982f064d262987199fba19f085e9 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Mon, 29 Mar 2021 15:10:50 +0800 Subject: [PATCH] runtime: init plan9 hashkey by time Maphash requires non-zero integer for initial hashkey Fixes #45090 Change-Id: Ie567f648c19e81cddc8e72a1c64809fbf52df188 Reviewed-on: https://go-review.googlesource.com/c/go/+/303969 Trust: Meng Zhuo Run-TryBot: Meng Zhuo TryBot-Result: Go Bot Reviewed-by: Richard Miller Reviewed-by: Keith Randall --- src/runtime/os_plan9.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/runtime/os_plan9.go b/src/runtime/os_plan9.go index 77665f461a..4d428346f0 100644 --- a/src/runtime/os_plan9.go +++ b/src/runtime/os_plan9.go @@ -325,7 +325,23 @@ func crash() { //go:nosplit func getRandomData(r []byte) { - extendRandom(r, 0) + // inspired by wyrand see hash32.go for detail + t := nanotime() + v := getg().m.procid ^ uint64(t) + + for len(r) > 0 { + v ^= 0xa0761d6478bd642f + v *= 0xe7037ed1a0b428db + size := 8 + if len(r) < 8 { + size = len(r) + } + for i := 0; i < size; i++ { + r[i] = byte(v >> (8 * i)) + } + r = r[size:] + v = v>>32 | v<<32 + } } func initsig(preinit bool) {