-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Milestone
Description
g% cat ~/x.go
package main
import (
"log"
"sync/atomic"
"syscall"
"unsafe"
)
func main() {
data, err := syscall.Mmap(-1, 0, 4096, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON)
if err != nil {
log.Fatal(err)
}
println(data)
atomic.AddUint32((*uint32)(unsafe.Pointer(&data[0])), 1)
}
g% go run ~/x.go
[4096/4096]0x2208335000
g% go run -race ~/x.go
[4096/4096]0xbf2000
unexpected fault address 0x200002fc8000
fatal error: fault
[signal 0xb code=0x1 addr=0x200002fc8000 pc=0xcc623]
goroutine 1 [running]:
runtime.gothrow(0x0, 0x0)
/Users/rsc/g/go/src/runtime/panic.go:503 +0x8e fp=0x7fff5fbff4e0 sp=0x7fff5fbff4c8
exit status 2
g%
Program should run under -race the same as it does normally.
This worked in Go 1.3, because Go 1.3 implemented these using raceread/raceacquire
instead of "fast paths".
This is blocking Go 1.4. One possible fix is to restore the old "slow path" Go
1.3 implementations of these functions.