mirror of
https://github.com/zrepl/zrepl.git
synced 2025-04-10 19:38:16 +02:00
rpc/dataconn: audit and comment use of unsafe for readv usage
Go 1.13 will add a more precise escape analysis: https://tip.golang.org/doc/go1.13#compiler Reviewed usage of unsafe to ensure we adhere to the unsafe.Pointer safety rules: https://tip.golang.org/pkg/unsafe/#Pointer
This commit is contained in:
parent
c4be60c29f
commit
95e16f01c1
@ -244,6 +244,14 @@ func (c Conn) readv(rawConn syscall.RawConn, iovecs []syscall.Iovec) (n int64, e
|
|||||||
func (c Conn) doOneReadv(rawConn syscall.RawConn, iovecs *[]syscall.Iovec) (n int64, err error) {
|
func (c Conn) doOneReadv(rawConn syscall.RawConn, iovecs *[]syscall.Iovec) (n int64, err error) {
|
||||||
rawReadErr := rawConn.Read(func(fd uintptr) (done bool) {
|
rawReadErr := rawConn.Read(func(fd uintptr) (done bool) {
|
||||||
// iovecs, n and err must not be shadowed!
|
// iovecs, n and err must not be shadowed!
|
||||||
|
|
||||||
|
// NOTE: unsafe.Pointer safety rules
|
||||||
|
// https://tip.golang.org/pkg/unsafe/#Pointer
|
||||||
|
//
|
||||||
|
// (4) Conversion of a Pointer to a uintptr when calling syscall.Syscall.
|
||||||
|
// ...
|
||||||
|
// uintptr() conversions must appear within the syscall.Syscall argument list.
|
||||||
|
// (even though we are not the escape analysis Likely not )
|
||||||
thisReadN, _, errno := syscall.Syscall(
|
thisReadN, _, errno := syscall.Syscall(
|
||||||
syscall.SYS_READV,
|
syscall.SYS_READV,
|
||||||
fd,
|
fd,
|
||||||
@ -268,6 +276,12 @@ func (c Conn) doOneReadv(rawConn syscall.RawConn, iovecs *[]syscall.Iovec) (n in
|
|||||||
left -= int64((*iovecs)[0].Len)
|
left -= int64((*iovecs)[0].Len)
|
||||||
*iovecs = (*iovecs)[1:]
|
*iovecs = (*iovecs)[1:]
|
||||||
} else {
|
} else {
|
||||||
|
// NOTE: unsafe.Pointer safety rules
|
||||||
|
// https://tip.golang.org/pkg/unsafe/#Pointer
|
||||||
|
// (3) Conversion of a Pointer to a uintptr and back, with arithmetic.
|
||||||
|
// ...
|
||||||
|
// Note that both conversions must appear in the same expression,
|
||||||
|
// with only the intervening arithmetic between them:
|
||||||
(*iovecs)[0].Base = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer((*iovecs)[0].Base)) + uintptr(left)))
|
(*iovecs)[0].Base = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer((*iovecs)[0].Base)) + uintptr(left)))
|
||||||
(*iovecs)[0].Len = uint64(curVecNewLength)
|
(*iovecs)[0].Len = uint64(curVecNewLength)
|
||||||
break // inner
|
break // inner
|
||||||
|
Loading…
Reference in New Issue
Block a user