diff options
author | Jamie Liu <jamieliu@google.com> | 2021-02-17 17:39:24 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-02-17 17:41:10 -0800 |
commit | f051ec64639b83faabcfe766ff078072def3c2aa (patch) | |
tree | 892c0fc2f4fd4138299c3c0d5a5836a940a670b5 /pkg/fdchannel/fdchannel_unsafe.go | |
parent | 4bc7daf91a0d9102fa477b199964e7db45066da1 (diff) |
Add gohacks.Slice/StringHeader.
See https://github.com/golang/go/issues/19367 for rationale. Note that the
upstream decision arrived at in that thread, while useful for some of our use
cases, doesn't account for all of our SliceHeader use cases (we often use
SliceHeader to extract pointers from slices in a way that avoids bounds
checking and/or handles nil slices correctly) and also doesn't exist yet.
PiperOrigin-RevId: 358071574
Diffstat (limited to 'pkg/fdchannel/fdchannel_unsafe.go')
-rw-r--r-- | pkg/fdchannel/fdchannel_unsafe.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/pkg/fdchannel/fdchannel_unsafe.go b/pkg/fdchannel/fdchannel_unsafe.go index b253a8fdd..0ebdedf26 100644 --- a/pkg/fdchannel/fdchannel_unsafe.go +++ b/pkg/fdchannel/fdchannel_unsafe.go @@ -20,9 +20,10 @@ package fdchannel import ( "fmt" - "reflect" "syscall" "unsafe" + + "gvisor.dev/gvisor/pkg/gohacks" ) // int32 is the real type of a file descriptor. @@ -53,10 +54,10 @@ func (ep *Endpoint) Init(sockfd int) { // sendmsg+recvmsg for a zero-length datagram is slightly faster than // sendmsg+recvmsg for a single byte over a stream socket. cmsgSlice := make([]byte, syscall.CmsgSpace(sizeofInt32)) - cmsgReflect := (*reflect.SliceHeader)(unsafe.Pointer(&cmsgSlice)) + cmsgSliceHdr := (*gohacks.SliceHeader)(unsafe.Pointer(&cmsgSlice)) ep.sockfd = int32(sockfd) - ep.msghdr.Control = (*byte)(unsafe.Pointer(cmsgReflect.Data)) - ep.cmsg = (*syscall.Cmsghdr)(unsafe.Pointer(cmsgReflect.Data)) + ep.msghdr.Control = (*byte)(cmsgSliceHdr.Data) + ep.cmsg = (*syscall.Cmsghdr)(cmsgSliceHdr.Data) // ep.msghdr.Controllen and ep.cmsg.* are mutated by recvmsg(2), so they're // set before calling sendmsg/recvmsg. } |