github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/sentry/seccheck/sinks/remote/wire/wire_abi_autogen_unsafe.go (about)

     1  // Automatically generated marshal implementation. See tools/go_marshal.
     2  
     3  package wire
     4  
     5  import (
     6      "github.com/metacubex/gvisor/pkg/gohacks"
     7      "github.com/metacubex/gvisor/pkg/hostarch"
     8      "github.com/metacubex/gvisor/pkg/marshal"
     9      "io"
    10      "reflect"
    11      "runtime"
    12      "unsafe"
    13  )
    14  
    15  // Marshallable types used by this file.
    16  var _ marshal.Marshallable = (*Header)(nil)
    17  
    18  // SizeBytes implements marshal.Marshallable.SizeBytes.
    19  func (h *Header) SizeBytes() int {
    20      return 8
    21  }
    22  
    23  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
    24  func (h *Header) MarshalBytes(dst []byte) []byte {
    25      hostarch.ByteOrder.PutUint16(dst[:2], uint16(h.HeaderSize))
    26      dst = dst[2:]
    27      hostarch.ByteOrder.PutUint16(dst[:2], uint16(h.MessageType))
    28      dst = dst[2:]
    29      hostarch.ByteOrder.PutUint32(dst[:4], uint32(h.DroppedCount))
    30      dst = dst[4:]
    31      return dst
    32  }
    33  
    34  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
    35  func (h *Header) UnmarshalBytes(src []byte) []byte {
    36      h.HeaderSize = uint16(hostarch.ByteOrder.Uint16(src[:2]))
    37      src = src[2:]
    38      h.MessageType = uint16(hostarch.ByteOrder.Uint16(src[:2]))
    39      src = src[2:]
    40      h.DroppedCount = uint32(hostarch.ByteOrder.Uint32(src[:4]))
    41      src = src[4:]
    42      return src
    43  }
    44  
    45  // Packed implements marshal.Marshallable.Packed.
    46  //go:nosplit
    47  func (h *Header) Packed() bool {
    48      return true
    49  }
    50  
    51  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
    52  func (h *Header) MarshalUnsafe(dst []byte) []byte {
    53      size := h.SizeBytes()
    54      gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(h), uintptr(size))
    55      return dst[size:]
    56  }
    57  
    58  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
    59  func (h *Header) UnmarshalUnsafe(src []byte) []byte {
    60      size := h.SizeBytes()
    61      gohacks.Memmove(unsafe.Pointer(h), unsafe.Pointer(&src[0]), uintptr(size))
    62      return src[size:]
    63  }
    64  
    65  // CopyOutN implements marshal.Marshallable.CopyOutN.
    66  func (h *Header) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
    67      // Construct a slice backed by dst's underlying memory.
    68      var buf []byte
    69      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
    70      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(h)))
    71      hdr.Len = h.SizeBytes()
    72      hdr.Cap = h.SizeBytes()
    73  
    74      length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
    75      // Since we bypassed the compiler's escape analysis, indicate that h
    76      // must live until the use above.
    77      runtime.KeepAlive(h) // escapes: replaced by intrinsic.
    78      return length, err
    79  }
    80  
    81  // CopyOut implements marshal.Marshallable.CopyOut.
    82  func (h *Header) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
    83      return h.CopyOutN(cc, addr, h.SizeBytes())
    84  }
    85  
    86  // CopyInN implements marshal.Marshallable.CopyInN.
    87  func (h *Header) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
    88      // Construct a slice backed by dst's underlying memory.
    89      var buf []byte
    90      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
    91      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(h)))
    92      hdr.Len = h.SizeBytes()
    93      hdr.Cap = h.SizeBytes()
    94  
    95      length, err := cc.CopyInBytes(addr, buf[:limit]) // escapes: okay.
    96      // Since we bypassed the compiler's escape analysis, indicate that h
    97      // must live until the use above.
    98      runtime.KeepAlive(h) // escapes: replaced by intrinsic.
    99      return length, err
   100  }
   101  
   102  // CopyIn implements marshal.Marshallable.CopyIn.
   103  func (h *Header) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   104      return h.CopyInN(cc, addr, h.SizeBytes())
   105  }
   106  
   107  // WriteTo implements io.WriterTo.WriteTo.
   108  func (h *Header) WriteTo(writer io.Writer) (int64, error) {
   109      // Construct a slice backed by dst's underlying memory.
   110      var buf []byte
   111      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   112      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(h)))
   113      hdr.Len = h.SizeBytes()
   114      hdr.Cap = h.SizeBytes()
   115  
   116      length, err := writer.Write(buf)
   117      // Since we bypassed the compiler's escape analysis, indicate that h
   118      // must live until the use above.
   119      runtime.KeepAlive(h) // escapes: replaced by intrinsic.
   120      return int64(length), err
   121  }
   122