From f051ec64639b83faabcfe766ff078072def3c2aa Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Wed, 17 Feb 2021 17:39:24 -0800 Subject: 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 --- pkg/usermem/addr_range_seq_unsafe.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pkg/usermem') diff --git a/pkg/usermem/addr_range_seq_unsafe.go b/pkg/usermem/addr_range_seq_unsafe.go index 495896ded..c9a1415a0 100644 --- a/pkg/usermem/addr_range_seq_unsafe.go +++ b/pkg/usermem/addr_range_seq_unsafe.go @@ -17,8 +17,9 @@ package usermem import ( "bytes" "fmt" - "reflect" "unsafe" + + "gvisor.dev/gvisor/pkg/gohacks" ) // An AddrRangeSeq represents a sequence of AddrRanges. @@ -163,8 +164,8 @@ func (ars AddrRangeSeq) externalTail() AddrRangeSeq { tailLimit = int64(ars.limit - headLen) } var extSlice []AddrRange - extSliceHdr := (*reflect.SliceHeader)(unsafe.Pointer(&extSlice)) - extSliceHdr.Data = uintptr(ars.data) + extSliceHdr := (*gohacks.SliceHeader)(unsafe.Pointer(&extSlice)) + extSliceHdr.Data = ars.data extSliceHdr.Len = ars.length extSliceHdr.Cap = ars.length return addrRangeSeqFromSliceLimited(extSlice[1:], tailLimit) -- cgit v1.2.3