github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/abi/gasket/gasket_abi_autogen_unsafe.go (about)

     1  // Automatically generated marshal implementation. See tools/go_marshal.
     2  
     3  package gasket
     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 = (*GasketInterruptEventFd)(nil)
    18  var _ marshal.Marshallable = (*GasketInterruptMapping)(nil)
    19  var _ marshal.Marshallable = (*GasketPageTableDmaBufIoctl)(nil)
    20  var _ marshal.Marshallable = (*GasketPageTableIoctl)(nil)
    21  
    22  // SizeBytes implements marshal.Marshallable.SizeBytes.
    23  func (g *GasketInterruptEventFd) SizeBytes() int {
    24  	return 16
    25  }
    26  
    27  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
    28  func (g *GasketInterruptEventFd) MarshalBytes(dst []byte) []byte {
    29  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.Interrupt))
    30  	dst = dst[8:]
    31  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.EventFD))
    32  	dst = dst[8:]
    33  	return dst
    34  }
    35  
    36  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
    37  func (g *GasketInterruptEventFd) UnmarshalBytes(src []byte) []byte {
    38  	g.Interrupt = uint64(hostarch.ByteOrder.Uint64(src[:8]))
    39  	src = src[8:]
    40  	g.EventFD = uint64(hostarch.ByteOrder.Uint64(src[:8]))
    41  	src = src[8:]
    42  	return src
    43  }
    44  
    45  // Packed implements marshal.Marshallable.Packed.
    46  //
    47  //go:nosplit
    48  func (g *GasketInterruptEventFd) Packed() bool {
    49  	return true
    50  }
    51  
    52  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
    53  func (g *GasketInterruptEventFd) MarshalUnsafe(dst []byte) []byte {
    54  	size := g.SizeBytes()
    55  	gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(g), uintptr(size))
    56  	return dst[size:]
    57  }
    58  
    59  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
    60  func (g *GasketInterruptEventFd) UnmarshalUnsafe(src []byte) []byte {
    61  	size := g.SizeBytes()
    62  	gohacks.Memmove(unsafe.Pointer(g), unsafe.Pointer(&src[0]), uintptr(size))
    63  	return src[size:]
    64  }
    65  
    66  // CopyOutN implements marshal.Marshallable.CopyOutN.
    67  func (g *GasketInterruptEventFd) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
    68  	// Construct a slice backed by dst's underlying memory.
    69  	var buf []byte
    70  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
    71  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(g)))
    72  	hdr.Len = g.SizeBytes()
    73  	hdr.Cap = g.SizeBytes()
    74  
    75  	length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
    76  	// Since we bypassed the compiler's escape analysis, indicate that g
    77  	// must live until the use above.
    78  	runtime.KeepAlive(g) // escapes: replaced by intrinsic.
    79  	return length, err
    80  }
    81  
    82  // CopyOut implements marshal.Marshallable.CopyOut.
    83  func (g *GasketInterruptEventFd) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
    84  	return g.CopyOutN(cc, addr, g.SizeBytes())
    85  }
    86  
    87  // CopyIn implements marshal.Marshallable.CopyIn.
    88  func (g *GasketInterruptEventFd) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
    89  	// Construct a slice backed by dst's underlying memory.
    90  	var buf []byte
    91  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
    92  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(g)))
    93  	hdr.Len = g.SizeBytes()
    94  	hdr.Cap = g.SizeBytes()
    95  
    96  	length, err := cc.CopyInBytes(addr, buf) // escapes: okay.
    97  	// Since we bypassed the compiler's escape analysis, indicate that g
    98  	// must live until the use above.
    99  	runtime.KeepAlive(g) // escapes: replaced by intrinsic.
   100  	return length, err
   101  }
   102  
   103  // WriteTo implements io.WriterTo.WriteTo.
   104  func (g *GasketInterruptEventFd) 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(g)))
   109  	hdr.Len = g.SizeBytes()
   110  	hdr.Cap = g.SizeBytes()
   111  
   112  	length, err := writer.Write(buf)
   113  	// Since we bypassed the compiler's escape analysis, indicate that g
   114  	// must live until the use above.
   115  	runtime.KeepAlive(g) // escapes: replaced by intrinsic.
   116  	return int64(length), err
   117  }
   118  
   119  // SizeBytes implements marshal.Marshallable.SizeBytes.
   120  func (g *GasketInterruptMapping) SizeBytes() int {
   121  	return 32
   122  }
   123  
   124  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
   125  func (g *GasketInterruptMapping) MarshalBytes(dst []byte) []byte {
   126  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.Interrupt))
   127  	dst = dst[8:]
   128  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.EventFD))
   129  	dst = dst[8:]
   130  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.BarIndex))
   131  	dst = dst[8:]
   132  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.RegOffset))
   133  	dst = dst[8:]
   134  	return dst
   135  }
   136  
   137  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
   138  func (g *GasketInterruptMapping) UnmarshalBytes(src []byte) []byte {
   139  	g.Interrupt = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   140  	src = src[8:]
   141  	g.EventFD = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   142  	src = src[8:]
   143  	g.BarIndex = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   144  	src = src[8:]
   145  	g.RegOffset = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   146  	src = src[8:]
   147  	return src
   148  }
   149  
   150  // Packed implements marshal.Marshallable.Packed.
   151  //
   152  //go:nosplit
   153  func (g *GasketInterruptMapping) Packed() bool {
   154  	return true
   155  }
   156  
   157  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
   158  func (g *GasketInterruptMapping) MarshalUnsafe(dst []byte) []byte {
   159  	size := g.SizeBytes()
   160  	gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(g), uintptr(size))
   161  	return dst[size:]
   162  }
   163  
   164  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
   165  func (g *GasketInterruptMapping) UnmarshalUnsafe(src []byte) []byte {
   166  	size := g.SizeBytes()
   167  	gohacks.Memmove(unsafe.Pointer(g), unsafe.Pointer(&src[0]), uintptr(size))
   168  	return src[size:]
   169  }
   170  
   171  // CopyOutN implements marshal.Marshallable.CopyOutN.
   172  func (g *GasketInterruptMapping) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
   173  	// Construct a slice backed by dst's underlying memory.
   174  	var buf []byte
   175  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   176  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(g)))
   177  	hdr.Len = g.SizeBytes()
   178  	hdr.Cap = g.SizeBytes()
   179  
   180  	length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
   181  	// Since we bypassed the compiler's escape analysis, indicate that g
   182  	// must live until the use above.
   183  	runtime.KeepAlive(g) // escapes: replaced by intrinsic.
   184  	return length, err
   185  }
   186  
   187  // CopyOut implements marshal.Marshallable.CopyOut.
   188  func (g *GasketInterruptMapping) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   189  	return g.CopyOutN(cc, addr, g.SizeBytes())
   190  }
   191  
   192  // CopyIn implements marshal.Marshallable.CopyIn.
   193  func (g *GasketInterruptMapping) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   194  	// Construct a slice backed by dst's underlying memory.
   195  	var buf []byte
   196  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   197  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(g)))
   198  	hdr.Len = g.SizeBytes()
   199  	hdr.Cap = g.SizeBytes()
   200  
   201  	length, err := cc.CopyInBytes(addr, buf) // escapes: okay.
   202  	// Since we bypassed the compiler's escape analysis, indicate that g
   203  	// must live until the use above.
   204  	runtime.KeepAlive(g) // escapes: replaced by intrinsic.
   205  	return length, err
   206  }
   207  
   208  // WriteTo implements io.WriterTo.WriteTo.
   209  func (g *GasketInterruptMapping) WriteTo(writer io.Writer) (int64, 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(g)))
   214  	hdr.Len = g.SizeBytes()
   215  	hdr.Cap = g.SizeBytes()
   216  
   217  	length, err := writer.Write(buf)
   218  	// Since we bypassed the compiler's escape analysis, indicate that g
   219  	// must live until the use above.
   220  	runtime.KeepAlive(g) // escapes: replaced by intrinsic.
   221  	return int64(length), err
   222  }
   223  
   224  // SizeBytes implements marshal.Marshallable.SizeBytes.
   225  func (g *GasketPageTableDmaBufIoctl) SizeBytes() int {
   226  	return 20
   227  }
   228  
   229  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
   230  func (g *GasketPageTableDmaBufIoctl) MarshalBytes(dst []byte) []byte {
   231  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.PageTableIndex))
   232  	dst = dst[8:]
   233  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.DeviceAddress))
   234  	dst = dst[8:]
   235  	hostarch.ByteOrder.PutUint32(dst[:4], uint32(g.DMABufID))
   236  	dst = dst[4:]
   237  	return dst
   238  }
   239  
   240  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
   241  func (g *GasketPageTableDmaBufIoctl) UnmarshalBytes(src []byte) []byte {
   242  	g.PageTableIndex = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   243  	src = src[8:]
   244  	g.DeviceAddress = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   245  	src = src[8:]
   246  	g.DMABufID = int32(hostarch.ByteOrder.Uint32(src[:4]))
   247  	src = src[4:]
   248  	return src
   249  }
   250  
   251  // Packed implements marshal.Marshallable.Packed.
   252  //
   253  //go:nosplit
   254  func (g *GasketPageTableDmaBufIoctl) Packed() bool {
   255  	return false
   256  }
   257  
   258  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
   259  func (g *GasketPageTableDmaBufIoctl) MarshalUnsafe(dst []byte) []byte {
   260  	// Type GasketPageTableDmaBufIoctl doesn't have a packed layout in memory, fallback to MarshalBytes.
   261  	return g.MarshalBytes(dst)
   262  }
   263  
   264  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
   265  func (g *GasketPageTableDmaBufIoctl) UnmarshalUnsafe(src []byte) []byte {
   266  	// Type GasketPageTableDmaBufIoctl doesn't have a packed layout in memory, fallback to UnmarshalBytes.
   267  	return g.UnmarshalBytes(src)
   268  }
   269  
   270  // CopyOutN implements marshal.Marshallable.CopyOutN.
   271  func (g *GasketPageTableDmaBufIoctl) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
   272  	// Type GasketPageTableDmaBufIoctl doesn't have a packed layout in memory, fall back to MarshalBytes.
   273  	buf := cc.CopyScratchBuffer(g.SizeBytes()) // escapes: okay.
   274  	g.MarshalBytes(buf)                        // escapes: fallback.
   275  	return cc.CopyOutBytes(addr, buf[:limit])  // escapes: okay.
   276  }
   277  
   278  // CopyOut implements marshal.Marshallable.CopyOut.
   279  func (g *GasketPageTableDmaBufIoctl) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   280  	return g.CopyOutN(cc, addr, g.SizeBytes())
   281  }
   282  
   283  // CopyIn implements marshal.Marshallable.CopyIn.
   284  func (g *GasketPageTableDmaBufIoctl) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   285  	// Type GasketPageTableDmaBufIoctl doesn't have a packed layout in memory, fall back to UnmarshalBytes.
   286  	buf := cc.CopyScratchBuffer(g.SizeBytes()) // escapes: okay.
   287  	length, err := cc.CopyInBytes(addr, buf)   // escapes: okay.
   288  	// Unmarshal unconditionally. If we had a short copy-in, this results in a
   289  	// partially unmarshalled struct.
   290  	g.UnmarshalBytes(buf) // escapes: fallback.
   291  	return length, err
   292  }
   293  
   294  // WriteTo implements io.WriterTo.WriteTo.
   295  func (g *GasketPageTableDmaBufIoctl) WriteTo(writer io.Writer) (int64, error) {
   296  	// Type GasketPageTableDmaBufIoctl doesn't have a packed layout in memory, fall back to MarshalBytes.
   297  	buf := make([]byte, g.SizeBytes())
   298  	g.MarshalBytes(buf)
   299  	length, err := writer.Write(buf)
   300  	return int64(length), err
   301  }
   302  
   303  // SizeBytes implements marshal.Marshallable.SizeBytes.
   304  func (g *GasketPageTableIoctl) SizeBytes() int {
   305  	return 32
   306  }
   307  
   308  // MarshalBytes implements marshal.Marshallable.MarshalBytes.
   309  func (g *GasketPageTableIoctl) MarshalBytes(dst []byte) []byte {
   310  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.PageTableIndex))
   311  	dst = dst[8:]
   312  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.Size))
   313  	dst = dst[8:]
   314  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.HostAddress))
   315  	dst = dst[8:]
   316  	hostarch.ByteOrder.PutUint64(dst[:8], uint64(g.DeviceAddress))
   317  	dst = dst[8:]
   318  	return dst
   319  }
   320  
   321  // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
   322  func (g *GasketPageTableIoctl) UnmarshalBytes(src []byte) []byte {
   323  	g.PageTableIndex = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   324  	src = src[8:]
   325  	g.Size = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   326  	src = src[8:]
   327  	g.HostAddress = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   328  	src = src[8:]
   329  	g.DeviceAddress = uint64(hostarch.ByteOrder.Uint64(src[:8]))
   330  	src = src[8:]
   331  	return src
   332  }
   333  
   334  // Packed implements marshal.Marshallable.Packed.
   335  //
   336  //go:nosplit
   337  func (g *GasketPageTableIoctl) Packed() bool {
   338  	return true
   339  }
   340  
   341  // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
   342  func (g *GasketPageTableIoctl) MarshalUnsafe(dst []byte) []byte {
   343  	size := g.SizeBytes()
   344  	gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(g), uintptr(size))
   345  	return dst[size:]
   346  }
   347  
   348  // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
   349  func (g *GasketPageTableIoctl) UnmarshalUnsafe(src []byte) []byte {
   350  	size := g.SizeBytes()
   351  	gohacks.Memmove(unsafe.Pointer(g), unsafe.Pointer(&src[0]), uintptr(size))
   352  	return src[size:]
   353  }
   354  
   355  // CopyOutN implements marshal.Marshallable.CopyOutN.
   356  func (g *GasketPageTableIoctl) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) {
   357  	// Construct a slice backed by dst's underlying memory.
   358  	var buf []byte
   359  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   360  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(g)))
   361  	hdr.Len = g.SizeBytes()
   362  	hdr.Cap = g.SizeBytes()
   363  
   364  	length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay.
   365  	// Since we bypassed the compiler's escape analysis, indicate that g
   366  	// must live until the use above.
   367  	runtime.KeepAlive(g) // escapes: replaced by intrinsic.
   368  	return length, err
   369  }
   370  
   371  // CopyOut implements marshal.Marshallable.CopyOut.
   372  func (g *GasketPageTableIoctl) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   373  	return g.CopyOutN(cc, addr, g.SizeBytes())
   374  }
   375  
   376  // CopyIn implements marshal.Marshallable.CopyIn.
   377  func (g *GasketPageTableIoctl) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) {
   378  	// Construct a slice backed by dst's underlying memory.
   379  	var buf []byte
   380  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   381  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(g)))
   382  	hdr.Len = g.SizeBytes()
   383  	hdr.Cap = g.SizeBytes()
   384  
   385  	length, err := cc.CopyInBytes(addr, buf) // escapes: okay.
   386  	// Since we bypassed the compiler's escape analysis, indicate that g
   387  	// must live until the use above.
   388  	runtime.KeepAlive(g) // escapes: replaced by intrinsic.
   389  	return length, err
   390  }
   391  
   392  // WriteTo implements io.WriterTo.WriteTo.
   393  func (g *GasketPageTableIoctl) WriteTo(writer io.Writer) (int64, error) {
   394  	// Construct a slice backed by dst's underlying memory.
   395  	var buf []byte
   396  	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
   397  	hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(g)))
   398  	hdr.Len = g.SizeBytes()
   399  	hdr.Cap = g.SizeBytes()
   400  
   401  	length, err := writer.Write(buf)
   402  	// Since we bypassed the compiler's escape analysis, indicate that g
   403  	// must live until the use above.
   404  	runtime.KeepAlive(g) // escapes: replaced by intrinsic.
   405  	return int64(length), err
   406  }