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