github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/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/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 = (*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  // CopyInN implements marshal.Marshallable.CopyInN.
    83  func (tid *ThreadID) 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(tid)))
    88  	hdr.Len = tid.SizeBytes()
    89  	hdr.Cap = tid.SizeBytes()
    90  
    91  	length, err := cc.CopyInBytes(addr, buf[:limit]) // 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  // CopyIn implements marshal.Marshallable.CopyIn.
    99  func (tid *ThreadID) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   100  	return tid.CopyInN(cc, addr, tid.SizeBytes())
   101  }
   102  
   103  // WriteTo implements io.WriterTo.WriteTo.
   104  func (tid *ThreadID) 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(tid)))
   109  	hdr.Len = tid.SizeBytes()
   110  	hdr.Cap = tid.SizeBytes()
   111  
   112  	length, err := writer.Write(buf)
   113  	// Since we bypassed the compiler's escape analysis, indicate that tid
   114  	// must live until the use above.
   115  	runtime.KeepAlive(tid) // escapes: replaced by intrinsic.
   116  	return int64(length), err
   117  }
   118  
   119  // SizeBytes implements marshal.Marshallable.SizeBytes.
   120  func (v *vdsoParams) SizeBytes() int {
   121  	return 64
   122  }
   123  
   124  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
   125  func (v *vdsoParams) MarshalBytes(dst []byte) []byte {
   126  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.monotonicReady))
   127  	dst = dst[8:]
   128  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.monotonicBaseCycles))
   129  	dst = dst[8:]
   130  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.monotonicBaseRef))
   131  	dst = dst[8:]
   132  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.monotonicFrequency))
   133  	dst = dst[8:]
   134  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.realtimeReady))
   135  	dst = dst[8:]
   136  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.realtimeBaseCycles))
   137  	dst = dst[8:]
   138  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.realtimeBaseRef))
   139  	dst = dst[8:]
   140  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(v.realtimeFrequency))
   141  	dst = dst[8:]
   142  	return dst
   143  }
   144  
   145  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
   146  func (v *vdsoParams) UnmarshalBytes(src []byte) []byte {
   147  	v.monotonicReady = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   148  	src = src[8:]
   149  	v.monotonicBaseCycles = int64(hostarch.ByteOrder.Uint64(src[:8]))
   150  	src = src[8:]
   151  	v.monotonicBaseRef = int64(hostarch.ByteOrder.Uint64(src[:8]))
   152  	src = src[8:]
   153  	v.monotonicFrequency = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   154  	src = src[8:]
   155  	v.realtimeReady = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   156  	src = src[8:]
   157  	v.realtimeBaseCycles = int64(hostarch.ByteOrder.Uint64(src[:8]))
   158  	src = src[8:]
   159  	v.realtimeBaseRef = int64(hostarch.ByteOrder.Uint64(src[:8]))
   160  	src = src[8:]
   161  	v.realtimeFrequency = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   162  	src = src[8:]
   163  	return src
   164  }
   165  
   166  // Packed implements marshal.Marshallable.Packed.
   167  //
   168  //go:nosplit
   169  func (v *vdsoParams) Packed() bool {
   170  	return true
   171  }
   172  
   173  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
   174  func (v *vdsoParams) MarshalUnsafe(dst []byte) []byte {
   175  	size := v.SizeBytes()
   176  	gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(v), uintptr(size))
   177  	return dst[size:]
   178  }
   179  
   180  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
   181  func (v *vdsoParams) UnmarshalUnsafe(src []byte) []byte {
   182  	size := v.SizeBytes()
   183  	gohacks.Memmove(unsafe.Pointer(v), unsafe.Pointer(&src[0]), uintptr(size))
   184  	return src[size:]
   185  }
   186  
   187  // CopyOutN implements marshal.Marshallable.CopyOutN.
   188  func (v *vdsoParams) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
   189  	// Construct a slice backed by dst's underlying memory.
   190  	var buf []byte
   191  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   192  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(v)))
   193  	hdr.Len = v.SizeBytes()
   194  	hdr.Cap = v.SizeBytes()
   195  
   196  	length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
   197  	// Since we bypassed the compiler's escape analysis, indicate that v
   198  	// must live until the use above.
   199  	runtime.KeepAlive(v) // escapes: replaced by intrinsic.
   200  	return length, err
   201  }
   202  
   203  // CopyOut implements marshal.Marshallable.CopyOut.
   204  func (v *vdsoParams) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   205  	return v.CopyOutN(cc, addr, v.SizeBytes())
   206  }
   207  
   208  // CopyInN implements marshal.Marshallable.CopyInN.
   209  func (v *vdsoParams) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
   210  	// Construct a slice backed by dst's underlying memory.
   211  	var buf []byte
   212  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   213  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(v)))
   214  	hdr.Len = v.SizeBytes()
   215  	hdr.Cap = v.SizeBytes()
   216  
   217  	length, err := cc.CopyInBytes(addr, buf[:limit]) // escapes: okay.
   218  	// Since we bypassed the compiler's escape analysis, indicate that v
   219  	// must live until the use above.
   220  	runtime.KeepAlive(v) // escapes: replaced by intrinsic.
   221  	return length, err
   222  }
   223  
   224  // CopyIn implements marshal.Marshallable.CopyIn.
   225  func (v *vdsoParams) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   226  	return v.CopyInN(cc, addr, v.SizeBytes())
   227  }
   228  
   229  // WriteTo implements io.WriterTo.WriteTo.
   230  func (v *vdsoParams) WriteTo(writer io.Writer) (int64, error) {
   231  	// Construct a slice backed by dst's underlying memory.
   232  	var buf []byte
   233  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   234  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(v)))
   235  	hdr.Len = v.SizeBytes()
   236  	hdr.Cap = v.SizeBytes()
   237  
   238  	length, err := writer.Write(buf)
   239  	// Since we bypassed the compiler's escape analysis, indicate that v
   240  	// must live until the use above.
   241  	runtime.KeepAlive(v) // escapes: replaced by intrinsic.
   242  	return int64(length), err
   243  }