github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/pkg/sentry/arch/fpu/fpu_amd64_abi_autogen_unsafe.go (about) 1 // Automatically generated marshal implementation. See tools/go_marshal. 2 3 // If there are issues with build constraint aggregation, see 4 // tools/go_marshal/gomarshal/generator.go:writeHeader(). The constraints here 5 // come from the input set of files used to generate this file. This input set 6 // is filtered based on pre-defined file suffixes related to build constraints, 7 // see tools/defs.bzl:calculate_sets(). 8 9 //go:build amd64 || i386 10 // +build amd64 i386 11 12 package fpu 13 14 import ( 15 "github.com/MerlinKodo/gvisor/pkg/gohacks" 16 "github.com/MerlinKodo/gvisor/pkg/hostarch" 17 "github.com/MerlinKodo/gvisor/pkg/marshal" 18 "io" 19 "reflect" 20 "runtime" 21 "unsafe" 22 ) 23 24 // Marshallable types used by this file. 25 var _ marshal.Marshallable = (*FPSoftwareFrame)(nil) 26 27 // SizeBytes implements marshal.Marshallable.SizeBytes. 28 func (f *FPSoftwareFrame) SizeBytes() int { 29 return 20 + 30 4*7 31 } 32 33 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 34 func (f *FPSoftwareFrame) MarshalBytes(dst []byte) []byte { 35 hostarch.ByteOrder.PutUint32(dst[:4], uint32(f.Magic1)) 36 dst = dst[4:] 37 hostarch.ByteOrder.PutUint32(dst[:4], uint32(f.ExtendedSize)) 38 dst = dst[4:] 39 hostarch.ByteOrder.PutUint64(dst[:8], uint64(f.Xfeatures)) 40 dst = dst[8:] 41 hostarch.ByteOrder.PutUint32(dst[:4], uint32(f.XstateSize)) 42 dst = dst[4:] 43 for idx := 0; idx < 7; idx++ { 44 hostarch.ByteOrder.PutUint32(dst[:4], uint32(f.Padding[idx])) 45 dst = dst[4:] 46 } 47 return dst 48 } 49 50 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 51 func (f *FPSoftwareFrame) UnmarshalBytes(src []byte) []byte { 52 f.Magic1 = uint32(hostarch.ByteOrder.Uint32(src[:4])) 53 src = src[4:] 54 f.ExtendedSize = uint32(hostarch.ByteOrder.Uint32(src[:4])) 55 src = src[4:] 56 f.Xfeatures = uint64(hostarch.ByteOrder.Uint64(src[:8])) 57 src = src[8:] 58 f.XstateSize = uint32(hostarch.ByteOrder.Uint32(src[:4])) 59 src = src[4:] 60 for idx := 0; idx < 7; idx++ { 61 f.Padding[idx] = uint32(hostarch.ByteOrder.Uint32(src[:4])) 62 src = src[4:] 63 } 64 return src 65 } 66 67 // Packed implements marshal.Marshallable.Packed. 68 //go:nosplit 69 func (f *FPSoftwareFrame) Packed() bool { 70 return true 71 } 72 73 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 74 func (f *FPSoftwareFrame) MarshalUnsafe(dst []byte) []byte { 75 size := f.SizeBytes() 76 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(f), uintptr(size)) 77 return dst[size:] 78 } 79 80 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 81 func (f *FPSoftwareFrame) UnmarshalUnsafe(src []byte) []byte { 82 size := f.SizeBytes() 83 gohacks.Memmove(unsafe.Pointer(f), unsafe.Pointer(&src[0]), uintptr(size)) 84 return src[size:] 85 } 86 87 // CopyOutN implements marshal.Marshallable.CopyOutN. 88 func (f *FPSoftwareFrame) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 89 // Construct a slice backed by dst's underlying memory. 90 var buf []byte 91 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 92 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(f))) 93 hdr.Len = f.SizeBytes() 94 hdr.Cap = f.SizeBytes() 95 96 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 97 // Since we bypassed the compiler's escape analysis, indicate that f 98 // must live until the use above. 99 runtime.KeepAlive(f) // escapes: replaced by intrinsic. 100 return length, err 101 } 102 103 // CopyOut implements marshal.Marshallable.CopyOut. 104 func (f *FPSoftwareFrame) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 105 return f.CopyOutN(cc, addr, f.SizeBytes()) 106 } 107 108 // CopyInN implements marshal.Marshallable.CopyInN. 109 func (f *FPSoftwareFrame) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 110 // Construct a slice backed by dst's underlying memory. 111 var buf []byte 112 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 113 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(f))) 114 hdr.Len = f.SizeBytes() 115 hdr.Cap = f.SizeBytes() 116 117 length, err := cc.CopyInBytes(addr, buf[:limit]) // escapes: okay. 118 // Since we bypassed the compiler's escape analysis, indicate that f 119 // must live until the use above. 120 runtime.KeepAlive(f) // escapes: replaced by intrinsic. 121 return length, err 122 } 123 124 // CopyIn implements marshal.Marshallable.CopyIn. 125 func (f *FPSoftwareFrame) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 126 return f.CopyInN(cc, addr, f.SizeBytes()) 127 } 128 129 // WriteTo implements io.WriterTo.WriteTo. 130 func (f *FPSoftwareFrame) WriteTo(writer io.Writer) (int64, error) { 131 // Construct a slice backed by dst's underlying memory. 132 var buf []byte 133 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 134 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(f))) 135 hdr.Len = f.SizeBytes() 136 hdr.Cap = f.SizeBytes() 137 138 length, err := writer.Write(buf) 139 // Since we bypassed the compiler's escape analysis, indicate that f 140 // must live until the use above. 141 runtime.KeepAlive(f) // escapes: replaced by intrinsic. 142 return int64(length), err 143 } 144