diff options
author | Valery Piashchynski <[email protected]> | 2021-12-26 00:50:30 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-12-26 00:50:30 +0300 |
commit | b27b2a1c9030f38e729e6e2d411379047c28402e (patch) | |
tree | 129d9d1fd1d2803712fa4b0f05d5cfbf466d10e3 /utils/race_checker.go | |
parent | 9cbb6be27ca0bd56eaa6db9a875830a8ce6110e8 (diff) |
implement common logger
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'utils/race_checker.go')
-rw-r--r-- | utils/race_checker.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/utils/race_checker.go b/utils/race_checker.go new file mode 100644 index 00000000..cd5ed556 --- /dev/null +++ b/utils/race_checker.go @@ -0,0 +1,35 @@ +//go:build race + +package utils + +import ( + "crypto/sha512" + "fmt" + "runtime" +) + +func SetChecker(b []byte) { + if len(b) == 0 { + return + } + c := checkIfConst(b) + go c.isStillConst() + runtime.SetFinalizer(c, (*constSlice).isStillConst) +} + +type constSlice struct { + b []byte + checksum [64]byte +} + +func checkIfConst(b []byte) *constSlice { + c := &constSlice{b: b} + c.checksum = sha512.Sum512(c.b) + return c +} + +func (c *constSlice) isStillConst() { + if sha512.Sum512(c.b) != c.checksum { + panic(fmt.Sprintf("mutable access detected 0x%012x", &c.b[0])) + } +} |