diff options
Diffstat (limited to 'pkg/safemem')
-rw-r--r-- | pkg/safemem/block_unsafe.go | 13 | ||||
-rw-r--r-- | pkg/safemem/seq_unsafe.go | 7 |
2 files changed, 10 insertions, 10 deletions
diff --git a/pkg/safemem/block_unsafe.go b/pkg/safemem/block_unsafe.go index 7857f5853..93879bb4f 100644 --- a/pkg/safemem/block_unsafe.go +++ b/pkg/safemem/block_unsafe.go @@ -16,9 +16,9 @@ package safemem import ( "fmt" - "reflect" "unsafe" + "gvisor.dev/gvisor/pkg/gohacks" "gvisor.dev/gvisor/pkg/safecopy" ) @@ -148,12 +148,11 @@ func (b Block) TakeFirst64(n uint64) Block { // ToSlice returns a []byte equivalent to b. func (b Block) ToSlice() []byte { - var bs []byte - hdr := (*reflect.SliceHeader)(unsafe.Pointer(&bs)) - hdr.Data = uintptr(b.start) - hdr.Len = b.length - hdr.Cap = b.length - return bs + return *(*[]byte)(unsafe.Pointer(&gohacks.SliceHeader{ + Data: b.start, + Len: b.length, + Cap: b.length, + })) } // Addr returns b's start address as a uintptr. It returns uintptr instead of diff --git a/pkg/safemem/seq_unsafe.go b/pkg/safemem/seq_unsafe.go index fc4049eeb..b315b0e5a 100644 --- a/pkg/safemem/seq_unsafe.go +++ b/pkg/safemem/seq_unsafe.go @@ -17,9 +17,10 @@ package safemem import ( "bytes" "fmt" - "reflect" "syscall" "unsafe" + + "gvisor.dev/gvisor/pkg/gohacks" ) // A BlockSeq represents a sequence of Blocks, each of which has non-zero @@ -184,8 +185,8 @@ func (bs BlockSeq) Tail() BlockSeq { return BlockSeq{} } var extSlice []Block - extSliceHdr := (*reflect.SliceHeader)(unsafe.Pointer(&extSlice)) - extSliceHdr.Data = uintptr(bs.data) + extSliceHdr := (*gohacks.SliceHeader)(unsafe.Pointer(&extSlice)) + extSliceHdr.Data = bs.data extSliceHdr.Len = bs.length extSliceHdr.Cap = bs.length tailSlice := skipEmpty(extSlice[1:]) |