github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/sentry/kernel/kernel_abi_autogen_unsafe.go (about)

     1  // Automatically generated marshal implementation. See tools/go_marshal.
     2  
     3  package kernel
     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 = (*ThreadID)(nil)
    17  var _ marshal.Marshallable = (*vdsoParams)(nil)
    18  
    19  // SizeBytes implements marshal.Marshallable.SizeBytes.
    20  //go:nosplit
    21  func (tid *ThreadID) SizeBytes() int {
    22      return 4
    23  }
    24  
    25  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
    26  func (tid *ThreadID) MarshalBytes(dst []byte) []byte {
    27      hostarch.ByteOrder.PutUint32(dst[:4], uint32(*tid))
    28      return dst[4:]
    29  }
    30  
    31  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
    32  func (tid *ThreadID) UnmarshalBytes(src []byte) []byte {
    33      *tid = ThreadID(int32(hostarch.ByteOrder.Uint32(src[:4])))
    34      return src[4:]
    35  }
    36  
    37  // Packed implements marshal.Marshallable.Packed.
    38  //go:nosplit
    39  func (tid *ThreadID) Packed() bool {
    40      // Scalar newtypes are always packed.
    41      return true
    42  }
    43  
    44  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
    45  func (tid *ThreadID) MarshalUnsafe(dst []byte) []byte {
    46      size := tid.SizeBytes()
    47      gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(tid), uintptr(size))
    48      return dst[size:]
    49  }
    50  
    51  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
    52  func (tid *ThreadID) UnmarshalUnsafe(src []byte) []byte {
    53      size := tid.SizeBytes()
    54      gohacks.Memmove(unsafe.Pointer(tid), unsafe.Pointer(&src[0]), uintptr(size))
    55      return src[size:]
    56  }
    57  
    58  // CopyOutN implements marshal.Marshallable.CopyOutN.
    59  func (tid *ThreadID) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
    60      // Construct a slice backed by dst's underlying memory.
    61      var buf []byte
    62      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
    63      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(tid)))
    64      hdr.Len = tid.SizeBytes()
    65      hdr.Cap = tid.SizeBytes()
    66  
    67      length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
    68      // Since we bypassed the compiler's escape analysis, indicate that tid
    69      // must live until the use above.
    70      runtime.KeepAlive(tid) // escapes: replaced by intrinsic.
    71      return length, err
    72  }
    73  
    74  // CopyOut implements marshal.Marshallable.CopyOut.
    75  func (tid *ThreadID) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
    76      return tid.CopyOutN(cc, addr, tid.SizeBytes())
    77  }
    78  
    79  // CopyInN implements marshal.Marshallable.CopyInN.
    80  func (tid *ThreadID) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
    81      // Construct a slice backed by dst's underlying memory.
    82      var buf []byte
    83      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
    84      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(tid)))
    85      hdr.Len = tid.SizeBytes()
    86      hdr.Cap = tid.SizeBytes()
    87  
    88      length, err := cc.CopyInBytes(addr, buf[:limit]) // escapes: okay.
    89      // Since we bypassed the compiler's escape analysis, indicate that tid
    90      // must live until the use above.
    91      runtime.KeepAlive(tid) // escapes: replaced by intrinsic.
    92      return length, err
    93  }
    94  
    95  // CopyIn implements marshal.Marshallable.CopyIn.
    96  func (tid *ThreadID) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
    97      return tid.CopyInN(cc, addr, tid.SizeBytes())
    98  }
    99  
   100  // WriteTo implements io.WriterTo.WriteTo.
   101  func (tid *ThreadID) WriteTo(writer io.Writer) (int64, error) {
   102      // Construct a slice backed by dst's underlying memory.
   103      var buf []byte
   104      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   105      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(tid)))
   106      hdr.Len = tid.SizeBytes()
   107      hdr.Cap = tid.SizeBytes()
   108  
   109      length, err := writer.Write(buf)
   110      // Since we bypassed the compiler's escape analysis, indicate that tid
   111      // must live until the use above.
   112      runtime.KeepAlive(tid) // escapes: replaced by intrinsic.
   113      return int64(length), err
   114  }
   115  
   116  // SizeBytes implements marshal.Marshallable.SizeBytes.
   117  func (v *vdsoParams) SizeBytes() int {
   118      return 64
   119  }
   120  
   121  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
   122  func (v *vdsoParams) MarshalBytes(dst []byte) []byte {
   123      hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.monotonicReady))
   124      dst = dst[8:]
   125      hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.monotonicBaseCycles))
   126      dst = dst[8:]
   127      hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.monotonicBaseRef))
   128      dst = dst[8:]
   129      hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.monotonicFrequency))
   130      dst = dst[8:]
   131      hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.realtimeReady))
   132      dst = dst[8:]
   133      hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.realtimeBaseCycles))
   134      dst = dst[8:]
   135      hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.realtimeBaseRef))
   136      dst = dst[8:]
   137      hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.realtimeFrequency))
   138      dst = dst[8:]
   139      return dst
   140  }
   141  
   142  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
   143  func (v *vdsoParams) UnmarshalBytes(src []byte) []byte {
   144      v.monotonicReady = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   145      src = src[8:]
   146      v.monotonicBaseCycles = int64(hostarch.ByteOrder.Uint64(src[:8]))
   147      src = src[8:]
   148      v.monotonicBaseRef = int64(hostarch.ByteOrder.Uint64(src[:8]))
   149      src = src[8:]
   150      v.monotonicFrequency = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   151      src = src[8:]
   152      v.realtimeReady = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   153      src = src[8:]
   154      v.realtimeBaseCycles = int64(hostarch.ByteOrder.Uint64(src[:8]))
   155      src = src[8:]
   156      v.realtimeBaseRef = int64(hostarch.ByteOrder.Uint64(src[:8]))
   157      src = src[8:]
   158      v.realtimeFrequency = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   159      src = src[8:]
   160      return src
   161  }
   162  
   163  // Packed implements marshal.Marshallable.Packed.
   164  //go:nosplit
   165  func (v *vdsoParams) Packed() bool {
   166      return true
   167  }
   168  
   169  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
   170  func (v *vdsoParams) MarshalUnsafe(dst []byte) []byte {
   171      size := v.SizeBytes()
   172      gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(v), uintptr(size))
   173      return dst[size:]
   174  }
   175  
   176  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
   177  func (v *vdsoParams) UnmarshalUnsafe(src []byte) []byte {
   178      size := v.SizeBytes()
   179      gohacks.Memmove(unsafe.Pointer(v), unsafe.Pointer(&src[0]), uintptr(size))
   180      return src[size:]
   181  }
   182  
   183  // CopyOutN implements marshal.Marshallable.CopyOutN.
   184  func (v *vdsoParams) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
   185      // Construct a slice backed by dst's underlying memory.
   186      var buf []byte
   187      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   188      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(v)))
   189      hdr.Len = v.SizeBytes()
   190      hdr.Cap = v.SizeBytes()
   191  
   192      length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
   193      // Since we bypassed the compiler's escape analysis, indicate that v
   194      // must live until the use above.
   195      runtime.KeepAlive(v) // escapes: replaced by intrinsic.
   196      return length, err
   197  }
   198  
   199  // CopyOut implements marshal.Marshallable.CopyOut.
   200  func (v *vdsoParams) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   201      return v.CopyOutN(cc, addr, v.SizeBytes())
   202  }
   203  
   204  // CopyInN implements marshal.Marshallable.CopyInN.
   205  func (v *vdsoParams) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
   206      // Construct a slice backed by dst's underlying memory.
   207      var buf []byte
   208      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   209      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(v)))
   210      hdr.Len = v.SizeBytes()
   211      hdr.Cap = v.SizeBytes()
   212  
   213      length, err := cc.CopyInBytes(addr, buf[:limit]) // escapes: okay.
   214      // Since we bypassed the compiler's escape analysis, indicate that v
   215      // must live until the use above.
   216      runtime.KeepAlive(v) // escapes: replaced by intrinsic.
   217      return length, err
   218  }
   219  
   220  // CopyIn implements marshal.Marshallable.CopyIn.
   221  func (v *vdsoParams) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   222      return v.CopyInN(cc, addr, v.SizeBytes())
   223  }
   224  
   225  // WriteTo implements io.WriterTo.WriteTo.
   226  func (v *vdsoParams) WriteTo(writer io.Writer) (int64, error) {
   227      // Construct a slice backed by dst's underlying memory.
   228      var buf []byte
   229      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   230      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(v)))
   231      hdr.Len = v.SizeBytes()
   232      hdr.Cap = v.SizeBytes()
   233  
   234      length, err := writer.Write(buf)
   235      // Since we bypassed the compiler's escape analysis, indicate that v
   236      // must live until the use above.
   237      runtime.KeepAlive(v) // escapes: replaced by intrinsic.
   238      return int64(length), err
   239  }
   240