From 982d5d2e84910cd29d52b97cfbe733fd56fd04ef Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 11 Oct 2021 14:57:53 -0600 Subject: conn,wintun: use unsafe.Slice instead of unsafeSlice Signed-off-by: Jason A. Donenfeld --- tun/wintun/session_windows.go | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'tun') diff --git a/tun/wintun/session_windows.go b/tun/wintun/session_windows.go index ffa9380..f023baf 100644 --- a/tun/wintun/session_windows.go +++ b/tun/wintun/session_windows.go @@ -67,7 +67,7 @@ func (session Session) ReceivePacket() (packet []byte, err error) { err = e1 return } - unsafeSlice(unsafe.Pointer(&packet), unsafe.Pointer(r0), int(packetSize)) + packet = unsafe.Slice((*byte)(unsafe.Pointer(r0)), packetSize) return } @@ -81,28 +81,10 @@ func (session Session) AllocateSendPacket(packetSize int) (packet []byte, err er err = e1 return } - unsafeSlice(unsafe.Pointer(&packet), unsafe.Pointer(r0), int(packetSize)) + packet = unsafe.Slice((*byte)(unsafe.Pointer(r0)), packetSize) return } func (session Session) SendPacket(packet []byte) { syscall.Syscall(procWintunSendPacket.Addr(), 2, session.handle, uintptr(unsafe.Pointer(&packet[0])), 0) } - -// unsafeSlice updates the slice slicePtr to be a slice -// referencing the provided data with its length & capacity set to -// lenCap. -// -// TODO: when Go 1.16 or Go 1.17 is the minimum supported version, -// update callers to use unsafe.Slice instead of this. -func unsafeSlice(slicePtr, data unsafe.Pointer, lenCap int) { - type sliceHeader struct { - Data unsafe.Pointer - Len int - Cap int - } - h := (*sliceHeader)(slicePtr) - h.Data = data - h.Len = lenCap - h.Cap = lenCap -} -- cgit v1.2.3-54-g00ecf