From 4286a510b465493cf81b6ed200359e675b37cb9c Mon Sep 17 00:00:00 2001 From: visualfc Date: Mon, 1 Jul 2024 16:20:14 +0800 Subject: [PATCH] runtime: stubs init hashkey --- internal/runtime/stubs.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/runtime/stubs.go b/internal/runtime/stubs.go index 6c09e115..34dd529d 100644 --- a/internal/runtime/stubs.go +++ b/internal/runtime/stubs.go @@ -8,12 +8,16 @@ import ( "unsafe" "github.com/goplus/llgo/c/sync/atomic" + "github.com/goplus/llgo/c/time" "github.com/goplus/llgo/internal/runtime/math" ) //go:linkname fastrand C.rand func fastrand() uint32 +//go:linkname srand C.srand +func srand(uint32) + func fastrand64() uint64 { n := uint64(fastrand()) n += 0xa0761d6478bd642f @@ -21,6 +25,14 @@ func fastrand64() uint64 { return hi ^ lo } +func init() { + srand(uint32(time.Time(nil))) + hashkey[0] = uintptr(fastrand()) | 1 + hashkey[1] = uintptr(fastrand()) | 1 + hashkey[2] = uintptr(fastrand()) | 1 + hashkey[3] = uintptr(fastrand()) | 1 +} + /* TODO(xsw): func fastrand() uint32 { mp := getg().m