mirror of
https://github.com/golang/go
synced 2024-11-17 05:14:56 -07:00
syscall: add race annotations to Windows ReadFile and WriteFile
For #51618 Fixes #51673 Change-Id: Ie63408d62303293d80afed8d5cf1cb164a8abecc Reviewed-on: https://go-review.googlesource.com/c/go/+/392774 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
49f16625c8
commit
e475cf2e70
@ -202,8 +202,8 @@ func NewCallbackCDecl(fn any) uintptr {
|
||||
//sys formatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
|
||||
//sys ExitProcess(exitcode uint32)
|
||||
//sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) [failretval==InvalidHandle] = CreateFileW
|
||||
//sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
|
||||
//sys WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
|
||||
//sys readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) = ReadFile
|
||||
//sys writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) = WriteFile
|
||||
//sys SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) [failretval==0xffffffff]
|
||||
//sys CloseHandle(handle Handle) (err error)
|
||||
//sys GetStdHandle(stdhandle int) (handle Handle, err error) [failretval==InvalidHandle]
|
||||
@ -385,42 +385,52 @@ func Read(fd Handle, p []byte) (n int, err error) {
|
||||
}
|
||||
return 0, e
|
||||
}
|
||||
if race.Enabled {
|
||||
if done > 0 {
|
||||
race.WriteRange(unsafe.Pointer(&p[0]), int(done))
|
||||
}
|
||||
race.Acquire(unsafe.Pointer(&ioSync))
|
||||
}
|
||||
if msanenabled && done > 0 {
|
||||
msanWrite(unsafe.Pointer(&p[0]), int(done))
|
||||
}
|
||||
if asanenabled && done > 0 {
|
||||
asanWrite(unsafe.Pointer(&p[0]), int(done))
|
||||
}
|
||||
return int(done), nil
|
||||
}
|
||||
|
||||
func Write(fd Handle, p []byte) (n int, err error) {
|
||||
if race.Enabled {
|
||||
race.ReleaseMerge(unsafe.Pointer(&ioSync))
|
||||
}
|
||||
var done uint32
|
||||
e := WriteFile(fd, p, &done, nil)
|
||||
if e != nil {
|
||||
return 0, e
|
||||
}
|
||||
if race.Enabled && done > 0 {
|
||||
race.ReadRange(unsafe.Pointer(&p[0]), int(done))
|
||||
}
|
||||
if msanenabled && done > 0 {
|
||||
msanRead(unsafe.Pointer(&p[0]), int(done))
|
||||
}
|
||||
if asanenabled && done > 0 {
|
||||
asanRead(unsafe.Pointer(&p[0]), int(done))
|
||||
}
|
||||
return int(done), nil
|
||||
}
|
||||
|
||||
func ReadFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error {
|
||||
err := readFile(fd, p, done, overlapped)
|
||||
if race.Enabled {
|
||||
if *done > 0 {
|
||||
race.WriteRange(unsafe.Pointer(&p[0]), int(*done))
|
||||
}
|
||||
race.Acquire(unsafe.Pointer(&ioSync))
|
||||
}
|
||||
if msanenabled && *done > 0 {
|
||||
msanWrite(unsafe.Pointer(&p[0]), int(*done))
|
||||
}
|
||||
if asanenabled && *done > 0 {
|
||||
asanWrite(unsafe.Pointer(&p[0]), int(*done))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func WriteFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error {
|
||||
if race.Enabled {
|
||||
race.ReleaseMerge(unsafe.Pointer(&ioSync))
|
||||
}
|
||||
err := writeFile(fd, p, done, overlapped)
|
||||
if race.Enabled && *done > 0 {
|
||||
race.ReadRange(unsafe.Pointer(&p[0]), int(*done))
|
||||
}
|
||||
if msanenabled && *done > 0 {
|
||||
msanRead(unsafe.Pointer(&p[0]), int(*done))
|
||||
}
|
||||
if asanenabled && *done > 0 {
|
||||
asanRead(unsafe.Pointer(&p[0]), int(*done))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
var ioSync int64
|
||||
|
||||
var procSetFilePointerEx = modkernel32.NewProc("SetFilePointerEx")
|
||||
|
@ -1016,7 +1016,7 @@ func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree
|
||||
return
|
||||
}
|
||||
|
||||
func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
|
||||
func readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
|
||||
var _p0 *byte
|
||||
if len(buf) > 0 {
|
||||
_p0 = &buf[0]
|
||||
@ -1158,7 +1158,7 @@ func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32,
|
||||
return
|
||||
}
|
||||
|
||||
func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
|
||||
func writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
|
||||
var _p0 *byte
|
||||
if len(buf) > 0 {
|
||||
_p0 = &buf[0]
|
||||
|
Loading…
Reference in New Issue
Block a user