mirror of
https://github.com/golang/go
synced 2024-11-19 16:24:45 -07:00
2b3f379080
Race detector runtime does not tolerate operations on addresses that was not previously declared with __tsan_map_shadow (namely, data, bss and heap). The corresponding address checks for atomic operations were removed in https://golang.org/cl/111310044 Restore these checks. It's tricker than just not calling into race runtime, because it is the race runtime that makes the atomic operations themselves (if we do not call into race runtime we skip the atomic operation itself as well). So instead we call __tsan_go_ignore_sync_start/end around the atomic operation. This forces race runtime to skip all other processing except than doing the atomic operation itself. Fixes #9136. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/179030043
31 lines
754 B
Go
31 lines
754 B
Go
// Copyright 2014 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build race
|
|
// +build darwin freebsd linux
|
|
|
|
package race_test
|
|
|
|
import (
|
|
"sync/atomic"
|
|
"syscall"
|
|
"testing"
|
|
"unsafe"
|
|
)
|
|
|
|
// Test that race detector does not crash when accessing non-Go allocated memory (issue 9136).
|
|
func TestNonGoMemory(t *testing.T) {
|
|
data, err := syscall.Mmap(-1, 0, 4096, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
|
|
if err != nil {
|
|
t.Fatalf("failed to mmap memory: %v", err)
|
|
}
|
|
p := (*uint32)(unsafe.Pointer(&data[0]))
|
|
atomic.AddUint32(p, 1)
|
|
(*p)++
|
|
if *p != 2 {
|
|
t.Fatalf("data[0] = %v, expect 2", *p)
|
|
}
|
|
syscall.Munmap(data)
|
|
}
|