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