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