github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/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/ttpreport/gvisor-ligolo/pkg/gohacks"
    16  	"github.com/ttpreport/gvisor-ligolo/pkg/hostarch"
    17  	"github.com/ttpreport/gvisor-ligolo/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  //
    69  //go:nosplit
    70  func (f *FPSoftwareFrame) Packed() bool {
    71  	return true
    72  }
    73  
    74  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
    75  func (f *FPSoftwareFrame) MarshalUnsafe(dst []byte) []byte {
    76  	size := f.SizeBytes()
    77  	gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(f), uintptr(size))
    78  	return dst[size:]
    79  }
    80  
    81  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
    82  func (f *FPSoftwareFrame) UnmarshalUnsafe(src []byte) []byte {
    83  	size := f.SizeBytes()
    84  	gohacks.Memmove(unsafe.Pointer(f), unsafe.Pointer(&src[0]), uintptr(size))
    85  	return src[size:]
    86  }
    87  
    88  // CopyOutN implements marshal.Marshallable.CopyOutN.
    89  func (f *FPSoftwareFrame) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
    90  	// Construct a slice backed by dst's underlying memory.
    91  	var buf []byte
    92  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
    93  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(f)))
    94  	hdr.Len = f.SizeBytes()
    95  	hdr.Cap = f.SizeBytes()
    96  
    97  	length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
    98  	// Since we bypassed the compiler's escape analysis, indicate that f
    99  	// must live until the use above.
   100  	runtime.KeepAlive(f) // escapes: replaced by intrinsic.
   101  	return length, err
   102  }
   103  
   104  // CopyOut implements marshal.Marshallable.CopyOut.
   105  func (f *FPSoftwareFrame) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   106  	return f.CopyOutN(cc, addr, f.SizeBytes())
   107  }
   108  
   109  // CopyIn implements marshal.Marshallable.CopyIn.
   110  func (f *FPSoftwareFrame) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   111  	// Construct a slice backed by dst's underlying memory.
   112  	var buf []byte
   113  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   114  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(f)))
   115  	hdr.Len = f.SizeBytes()
   116  	hdr.Cap = f.SizeBytes()
   117  
   118  	length, err := cc.CopyInBytes(addr, buf) // escapes: okay.
   119  	// Since we bypassed the compiler's escape analysis, indicate that f
   120  	// must live until the use above.
   121  	runtime.KeepAlive(f) // escapes: replaced by intrinsic.
   122  	return length, err
   123  }
   124  
   125  // WriteTo implements io.WriterTo.WriteTo.
   126  func (f *FPSoftwareFrame) WriteTo(writer io.Writer) (int64, error) {
   127  	// Construct a slice backed by dst's underlying memory.
   128  	var buf []byte
   129  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   130  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(f)))
   131  	hdr.Len = f.SizeBytes()
   132  	hdr.Cap = f.SizeBytes()
   133  
   134  	length, err := writer.Write(buf)
   135  	// Since we bypassed the compiler's escape analysis, indicate that f
   136  	// must live until the use above.
   137  	runtime.KeepAlive(f) // escapes: replaced by intrinsic.
   138  	return int64(length), err
   139  }