github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/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/ttpreport/gvisor-ligolo/pkg/gohacks"
    12  	"github.com/ttpreport/gvisor-ligolo/pkg/hostarch"
    13  	"github.com/ttpreport/gvisor-ligolo/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  // CopyIn implements marshal.Marshallable.CopyIn.
    83  func (gid *GID) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (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) // 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  // WriteTo implements io.WriterTo.WriteTo.
    99  func (gid *GID) WriteTo(writer io.Writer) (int64, error) {
   100  	// Construct a slice backed by dst's underlying memory.
   101  	var buf []byte
   102  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   103  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(gid)))
   104  	hdr.Len = gid.SizeBytes()
   105  	hdr.Cap = gid.SizeBytes()
   106  
   107  	length, err := writer.Write(buf)
   108  	// Since we bypassed the compiler's escape analysis, indicate that gid
   109  	// must live until the use above.
   110  	runtime.KeepAlive(gid) // escapes: replaced by intrinsic.
   111  	return int64(length), err
   112  }
   113  
   114  // CopyGIDSliceIn copies in a slice of GID objects from the task's memory.
   115  func CopyGIDSliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []GID) (int, error) {
   116  	count := len(dst)
   117  	if count == 0 {
   118  		return 0, nil
   119  	}
   120  	size := (*GID)(nil).SizeBytes()
   121  
   122  	ptr := unsafe.Pointer(&dst)
   123  	val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data))
   124  
   125  	// Construct a slice backed by dst's underlying memory.
   126  	var buf []byte
   127  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   128  	hdr.Data = uintptr(val)
   129  	hdr.Len = size * count
   130  	hdr.Cap = size * count
   131  
   132  	length, err := cc.CopyInBytes(addr, buf) // escapes: okay.
   133  	// Since we bypassed the compiler's escape analysis, indicate that dst
   134  	// must live until the use above.
   135  	runtime.KeepAlive(dst) // escapes: replaced by intrinsic.
   136  	return length, err
   137  }
   138  
   139  // CopyGIDSliceOut copies a slice of GID objects to the task's memory.
   140  func CopyGIDSliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []GID) (int, error) {
   141  	count := len(src)
   142  	if count == 0 {
   143  		return 0, nil
   144  	}
   145  	size := (*GID)(nil).SizeBytes()
   146  
   147  	ptr := unsafe.Pointer(&src)
   148  	val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data))
   149  
   150  	// Construct a slice backed by dst's underlying memory.
   151  	var buf []byte
   152  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   153  	hdr.Data = uintptr(val)
   154  	hdr.Len = size * count
   155  	hdr.Cap = size * count
   156  
   157  	length, err := cc.CopyOutBytes(addr, buf) // escapes: okay.
   158  	// Since we bypassed the compiler's escape analysis, indicate that src
   159  	// must live until the use above.
   160  	runtime.KeepAlive(src) // escapes: replaced by intrinsic.
   161  	return length, err
   162  }
   163  
   164  // MarshalUnsafeGIDSlice is like GID.MarshalUnsafe, but for a []GID.
   165  func MarshalUnsafeGIDSlice(src []GID, dst []byte) []byte {
   166  	count := len(src)
   167  	if count == 0 {
   168  		return dst
   169  	}
   170  	size := (*GID)(nil).SizeBytes()
   171  
   172  	buf := dst[:size*count]
   173  	gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf)))
   174  	return dst[size*count:]
   175  }
   176  
   177  // UnmarshalUnsafeGIDSlice is like GID.UnmarshalUnsafe, but for a []GID.
   178  func UnmarshalUnsafeGIDSlice(dst []GID, src []byte) []byte {
   179  	count := len(dst)
   180  	if count == 0 {
   181  		return src
   182  	}
   183  	size := (*GID)(nil).SizeBytes()
   184  
   185  	buf := src[:size*count]
   186  	gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf)))
   187  	return src[size*count:]
   188  }
   189  
   190  // SizeBytes implements marshal.Marshallable.SizeBytes.
   191  //
   192  //go:nosplit
   193  func (uid *UID) SizeBytes() int {
   194  	return 4
   195  }
   196  
   197  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
   198  func (uid *UID) MarshalBytes(dst []byte) []byte {
   199  	hostarch.ByteOrder.PutUint32(dst[:4], uint32(*uid))
   200  	return dst[4:]
   201  }
   202  
   203  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
   204  func (uid *UID) UnmarshalBytes(src []byte) []byte {
   205  	*uid = UID(uint32(hostarch.ByteOrder.Uint32(src[:4])))
   206  	return src[4:]
   207  }
   208  
   209  // Packed implements marshal.Marshallable.Packed.
   210  //
   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  // CopyIn implements marshal.Marshallable.CopyIn.
   253  func (uid *UID) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (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) // 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  // WriteTo implements io.WriterTo.WriteTo.
   269  func (uid *UID) WriteTo(writer io.Writer) (int64, error) {
   270  	// Construct a slice backed by dst's underlying memory.
   271  	var buf []byte
   272  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   273  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(uid)))
   274  	hdr.Len = uid.SizeBytes()
   275  	hdr.Cap = uid.SizeBytes()
   276  
   277  	length, err := writer.Write(buf)
   278  	// Since we bypassed the compiler's escape analysis, indicate that uid
   279  	// must live until the use above.
   280  	runtime.KeepAlive(uid) // escapes: replaced by intrinsic.
   281  	return int64(length), err
   282  }