forked from akaros/go-akaros
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-branch.go1.4] runtime: fix atomic operations on non-heap add…
…resses ««« CL 179030043 / e4ab8f908aac runtime: fix atomic operations on non-heap addresses 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 golang#9136. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/179030043 »»» TBR=dvyukov CC=golang-codereviews https://golang.org/cl/180030043
- Loading branch information
Showing
3 changed files
with
73 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters