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

     1  // Automatically generated marshal implementation. See tools/go_marshal.
     2  
     3  package auth
     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 = (*GID)(nil)
    17  var _ marshal.Marshallable = (*UID)(nil)
    18  
    19  // SizeBytes implements marshal.Marshallable.SizeBytes.
    20  //go:nosplit
    21  func (gid *GID) SizeBytes() int {
    22      return 4
    23  }
    24  
    25  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
    26  func (gid *GID) MarshalBytes(dst []byte) []byte {
    27      hostarch.ByteOrder.PutUint32(dst[:4], uint32(*gid))
    28      return dst[4:]
    29  }
    30  
    31  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
    32  func (gid *GID) UnmarshalBytes(src []byte) []byte {
    33      *gid = GID(uint32(hostarch.ByteOrder.Uint32(src[:4])))
    34      return src[4:]
    35  }
    36  
    37  // Packed implements marshal.Marshallable.Packed.
    38  //go:nosplit
    39  func (gid *GID) Packed() bool {
    40      // Scalar newtypes are always packed.
    41      return true
    42  }
    43  
    44  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
    45  func (gid *GID) MarshalUnsafe(dst []byte) []byte {
    46      size := gid.SizeBytes()
    47      gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(gid), uintptr(size))
    48      return dst[size:]
    49  }
    50  
    51  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
    52  func (gid *GID) UnmarshalUnsafe(src []byte) []byte {
    53      size := gid.SizeBytes()
    54      gohacks.Memmove(unsafe.Pointer(gid), unsafe.Pointer(&src[0]), uintptr(size))
    55      return src[size:]
    56  }
    57  
    58  // CopyOutN implements marshal.Marshallable.CopyOutN.
    59  func (gid *GID) 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(gid)))
    64      hdr.Len = gid.SizeBytes()
    65      hdr.Cap = gid.SizeBytes()
    66  
    67      length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
    68      // Since we bypassed the compiler's escape analysis, indicate that gid
    69      // must live until the use above.
    70      runtime.KeepAlive(gid) // escapes: replaced by intrinsic.
    71      return length, err
    72  }
    73  
    74  // CopyOut implements marshal.Marshallable.CopyOut.
    75  func (gid *GID) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
    76      return gid.CopyOutN(cc, addr, gid.SizeBytes())
    77  }
    78  
    79  // CopyInN implements marshal.Marshallable.CopyInN.
    80  func (gid *GID) 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(gid)))
    85      hdr.Len = gid.SizeBytes()
    86      hdr.Cap = gid.SizeBytes()
    87  
    88      length, err := cc.CopyInBytes(addr, buf[:limit]) // escapes: okay.
    89      // Since we bypassed the compiler's escape analysis, indicate that gid
    90      // must live until the use above.
    91      runtime.KeepAlive(gid) // escapes: replaced by intrinsic.
    92      return length, err
    93  }
    94  
    95  // CopyIn implements marshal.Marshallable.CopyIn.
    96  func (gid *GID) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
    97      return gid.CopyInN(cc, addr, gid.SizeBytes())
    98  }
    99  
   100  // WriteTo implements io.WriterTo.WriteTo.
   101  func (gid *GID) 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(gid)))
   106      hdr.Len = gid.SizeBytes()
   107      hdr.Cap = gid.SizeBytes()
   108  
   109      length, err := writer.Write(buf)
   110      // Since we bypassed the compiler's escape analysis, indicate that gid
   111      // must live until the use above.
   112      runtime.KeepAlive(gid) // escapes: replaced by intrinsic.
   113      return int64(length), err
   114  }
   115  
   116  // CopyGIDSliceIn copies in a slice of GID objects from the task's memory.
   117  func CopyGIDSliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []GID) (int, error) {
   118      count := len(dst)
   119      if count == 0 {
   120          return 0, nil
   121      }
   122      size := (*GID)(nil).SizeBytes()
   123  
   124      ptr := unsafe.Pointer(&dst)
   125      val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data))
   126  
   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(val)
   131      hdr.Len = size * count
   132      hdr.Cap = size * count
   133  
   134      length, err := cc.CopyInBytes(addr, buf) // escapes: okay.
   135      // Since we bypassed the compiler's escape analysis, indicate that dst
   136      // must live until the use above.
   137      runtime.KeepAlive(dst) // escapes: replaced by intrinsic.
   138      return length, err
   139  }
   140  
   141  // CopyGIDSliceOut copies a slice of GID objects to the task's memory.
   142  func CopyGIDSliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []GID) (int, error) {
   143      count := len(src)
   144      if count == 0 {
   145          return 0, nil
   146      }
   147      size := (*GID)(nil).SizeBytes()
   148  
   149      ptr := unsafe.Pointer(&src)
   150      val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data))
   151  
   152      // Construct a slice backed by dst's underlying memory.
   153      var buf []byte
   154      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   155      hdr.Data = uintptr(val)
   156      hdr.Len = size * count
   157      hdr.Cap = size * count
   158  
   159      length, err := cc.CopyOutBytes(addr, buf) // escapes: okay.
   160      // Since we bypassed the compiler's escape analysis, indicate that src
   161      // must live until the use above.
   162      runtime.KeepAlive(src) // escapes: replaced by intrinsic.
   163      return length, err
   164  }
   165  
   166  // MarshalUnsafeGIDSlice is like GID.MarshalUnsafe, but for a []GID.
   167  func MarshalUnsafeGIDSlice(src []GID, dst []byte) []byte {
   168      count := len(src)
   169      if count == 0 {
   170          return dst
   171      }
   172      size := (*GID)(nil).SizeBytes()
   173  
   174      buf := dst[:size*count]
   175      gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf)))
   176      return dst[size*count:]
   177  }
   178  
   179  // UnmarshalUnsafeGIDSlice is like GID.UnmarshalUnsafe, but for a []GID.
   180  func UnmarshalUnsafeGIDSlice(dst []GID, src []byte) []byte {
   181      count := len(dst)
   182      if count == 0 {
   183          return src
   184      }
   185      size := (*GID)(nil).SizeBytes()
   186  
   187      buf := src[:size*count]
   188      gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf)))
   189      return src[size*count:]
   190  }
   191  
   192  // SizeBytes implements marshal.Marshallable.SizeBytes.
   193  //go:nosplit
   194  func (uid *UID) SizeBytes() int {
   195      return 4
   196  }
   197  
   198  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
   199  func (uid *UID) MarshalBytes(dst []byte) []byte {
   200      hostarch.ByteOrder.PutUint32(dst[:4], uint32(*uid))
   201      return dst[4:]
   202  }
   203  
   204  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
   205  func (uid *UID) UnmarshalBytes(src []byte) []byte {
   206      *uid = UID(uint32(hostarch.ByteOrder.Uint32(src[:4])))
   207      return src[4:]
   208  }
   209  
   210  // Packed implements marshal.Marshallable.Packed.
   211  //go:nosplit
   212  func (uid *UID) Packed() bool {
   213      // Scalar newtypes are always packed.
   214      return true
   215  }
   216  
   217  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
   218  func (uid *UID) MarshalUnsafe(dst []byte) []byte {
   219      size := uid.SizeBytes()
   220      gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(uid), uintptr(size))
   221      return dst[size:]
   222  }
   223  
   224  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
   225  func (uid *UID) UnmarshalUnsafe(src []byte) []byte {
   226      size := uid.SizeBytes()
   227      gohacks.Memmove(unsafe.Pointer(uid), unsafe.Pointer(&src[0]), uintptr(size))
   228      return src[size:]
   229  }
   230  
   231  // CopyOutN implements marshal.Marshallable.CopyOutN.
   232  func (uid *UID) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
   233      // Construct a slice backed by dst's underlying memory.
   234      var buf []byte
   235      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   236      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(uid)))
   237      hdr.Len = uid.SizeBytes()
   238      hdr.Cap = uid.SizeBytes()
   239  
   240      length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
   241      // Since we bypassed the compiler's escape analysis, indicate that uid
   242      // must live until the use above.
   243      runtime.KeepAlive(uid) // escapes: replaced by intrinsic.
   244      return length, err
   245  }
   246  
   247  // CopyOut implements marshal.Marshallable.CopyOut.
   248  func (uid *UID) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   249      return uid.CopyOutN(cc, addr, uid.SizeBytes())
   250  }
   251  
   252  // CopyInN implements marshal.Marshallable.CopyInN.
   253  func (uid *UID) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
   254      // Construct a slice backed by dst's underlying memory.
   255      var buf []byte
   256      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   257      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(uid)))
   258      hdr.Len = uid.SizeBytes()
   259      hdr.Cap = uid.SizeBytes()
   260  
   261      length, err := cc.CopyInBytes(addr, buf[:limit]) // escapes: okay.
   262      // Since we bypassed the compiler's escape analysis, indicate that uid
   263      // must live until the use above.
   264      runtime.KeepAlive(uid) // escapes: replaced by intrinsic.
   265      return length, err
   266  }
   267  
   268  // CopyIn implements marshal.Marshallable.CopyIn.
   269  func (uid *UID) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   270      return uid.CopyInN(cc, addr, uid.SizeBytes())
   271  }
   272  
   273  // WriteTo implements io.WriterTo.WriteTo.
   274  func (uid *UID) WriteTo(writer io.Writer) (int64, error) {
   275      // Construct a slice backed by dst's underlying memory.
   276      var buf []byte
   277      hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   278      hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(uid)))
   279      hdr.Len = uid.SizeBytes()
   280      hdr.Cap = uid.SizeBytes()
   281  
   282      length, err := writer.Write(buf)
   283      // Since we bypassed the compiler's escape analysis, indicate that uid
   284      // must live until the use above.
   285      runtime.KeepAlive(uid) // escapes: replaced by intrinsic.
   286      return int64(length), err
   287  }
   288