github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/sentry/arch/arch_amd64_abi_autogen_unsafe.go (about) 1 // Automatically generated marshal implementation. See tools/go_marshal. 2 3 // If there are issues with build constraint aggregation, see 4 // tools/go_marshal/gomarshal/generator.go:writeHeader(). The constraints here 5 // come from the input set of files used to generate this file. This input set 6 // is filtered based on pre-defined file suffixes related to build constraints, 7 // see tools/defs.bzl:calculate_sets(). 8 9 //go:build amd64 && amd64 && amd64 10 // +build amd64,amd64,amd64 11 12 package arch 13 14 import ( 15 "github.com/ttpreport/gvisor-ligolo/pkg/abi/linux" 16 "github.com/ttpreport/gvisor-ligolo/pkg/gohacks" 17 "github.com/ttpreport/gvisor-ligolo/pkg/hostarch" 18 "github.com/ttpreport/gvisor-ligolo/pkg/marshal" 19 "io" 20 "reflect" 21 "runtime" 22 "unsafe" 23 ) 24 25 // Marshallable types used by this file. 26 var _ marshal.Marshallable = (*SignalContext64)(nil) 27 var _ marshal.Marshallable = (*UContext64)(nil) 28 var _ marshal.Marshallable = (*linux.SignalSet)(nil) 29 var _ marshal.Marshallable = (*linux.SignalStack)(nil) 30 31 // SizeBytes implements marshal.Marshallable.SizeBytes. 32 func (s *SignalContext64) SizeBytes() int { 33 return 184 + 34 (*linux.SignalSet)(nil).SizeBytes() + 35 8*8 36 } 37 38 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 39 func (s *SignalContext64) MarshalBytes(dst []byte) []byte { 40 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.R8)) 41 dst = dst[8:] 42 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.R9)) 43 dst = dst[8:] 44 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.R10)) 45 dst = dst[8:] 46 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.R11)) 47 dst = dst[8:] 48 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.R12)) 49 dst = dst[8:] 50 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.R13)) 51 dst = dst[8:] 52 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.R14)) 53 dst = dst[8:] 54 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.R15)) 55 dst = dst[8:] 56 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rdi)) 57 dst = dst[8:] 58 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rsi)) 59 dst = dst[8:] 60 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rbp)) 61 dst = dst[8:] 62 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rbx)) 63 dst = dst[8:] 64 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rdx)) 65 dst = dst[8:] 66 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rax)) 67 dst = dst[8:] 68 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rcx)) 69 dst = dst[8:] 70 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rsp)) 71 dst = dst[8:] 72 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rip)) 73 dst = dst[8:] 74 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Eflags)) 75 dst = dst[8:] 76 hostarch.ByteOrder.PutUint16(dst[:2], uint16(s.Cs)) 77 dst = dst[2:] 78 hostarch.ByteOrder.PutUint16(dst[:2], uint16(s.Gs)) 79 dst = dst[2:] 80 hostarch.ByteOrder.PutUint16(dst[:2], uint16(s.Fs)) 81 dst = dst[2:] 82 hostarch.ByteOrder.PutUint16(dst[:2], uint16(s.Ss)) 83 dst = dst[2:] 84 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Err)) 85 dst = dst[8:] 86 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Trapno)) 87 dst = dst[8:] 88 dst = s.Oldmask.MarshalUnsafe(dst) 89 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Cr2)) 90 dst = dst[8:] 91 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Fpstate)) 92 dst = dst[8:] 93 for idx := 0; idx < 8; idx++ { 94 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Reserved[idx])) 95 dst = dst[8:] 96 } 97 return dst 98 } 99 100 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 101 func (s *SignalContext64) UnmarshalBytes(src []byte) []byte { 102 s.R8 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 103 src = src[8:] 104 s.R9 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 105 src = src[8:] 106 s.R10 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 107 src = src[8:] 108 s.R11 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 109 src = src[8:] 110 s.R12 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 111 src = src[8:] 112 s.R13 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 113 src = src[8:] 114 s.R14 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 115 src = src[8:] 116 s.R15 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 117 src = src[8:] 118 s.Rdi = uint64(hostarch.ByteOrder.Uint64(src[:8])) 119 src = src[8:] 120 s.Rsi = uint64(hostarch.ByteOrder.Uint64(src[:8])) 121 src = src[8:] 122 s.Rbp = uint64(hostarch.ByteOrder.Uint64(src[:8])) 123 src = src[8:] 124 s.Rbx = uint64(hostarch.ByteOrder.Uint64(src[:8])) 125 src = src[8:] 126 s.Rdx = uint64(hostarch.ByteOrder.Uint64(src[:8])) 127 src = src[8:] 128 s.Rax = uint64(hostarch.ByteOrder.Uint64(src[:8])) 129 src = src[8:] 130 s.Rcx = uint64(hostarch.ByteOrder.Uint64(src[:8])) 131 src = src[8:] 132 s.Rsp = uint64(hostarch.ByteOrder.Uint64(src[:8])) 133 src = src[8:] 134 s.Rip = uint64(hostarch.ByteOrder.Uint64(src[:8])) 135 src = src[8:] 136 s.Eflags = uint64(hostarch.ByteOrder.Uint64(src[:8])) 137 src = src[8:] 138 s.Cs = uint16(hostarch.ByteOrder.Uint16(src[:2])) 139 src = src[2:] 140 s.Gs = uint16(hostarch.ByteOrder.Uint16(src[:2])) 141 src = src[2:] 142 s.Fs = uint16(hostarch.ByteOrder.Uint16(src[:2])) 143 src = src[2:] 144 s.Ss = uint16(hostarch.ByteOrder.Uint16(src[:2])) 145 src = src[2:] 146 s.Err = uint64(hostarch.ByteOrder.Uint64(src[:8])) 147 src = src[8:] 148 s.Trapno = uint64(hostarch.ByteOrder.Uint64(src[:8])) 149 src = src[8:] 150 src = s.Oldmask.UnmarshalUnsafe(src) 151 s.Cr2 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 152 src = src[8:] 153 s.Fpstate = uint64(hostarch.ByteOrder.Uint64(src[:8])) 154 src = src[8:] 155 for idx := 0; idx < 8; idx++ { 156 s.Reserved[idx] = uint64(hostarch.ByteOrder.Uint64(src[:8])) 157 src = src[8:] 158 } 159 return src 160 } 161 162 // Packed implements marshal.Marshallable.Packed. 163 // 164 //go:nosplit 165 func (s *SignalContext64) Packed() bool { 166 return s.Oldmask.Packed() 167 } 168 169 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 170 func (s *SignalContext64) MarshalUnsafe(dst []byte) []byte { 171 if s.Oldmask.Packed() { 172 size := s.SizeBytes() 173 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(s), uintptr(size)) 174 return dst[size:] 175 } 176 // Type SignalContext64 doesn't have a packed layout in memory, fallback to MarshalBytes. 177 return s.MarshalBytes(dst) 178 } 179 180 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 181 func (s *SignalContext64) UnmarshalUnsafe(src []byte) []byte { 182 if s.Oldmask.Packed() { 183 size := s.SizeBytes() 184 gohacks.Memmove(unsafe.Pointer(s), unsafe.Pointer(&src[0]), uintptr(size)) 185 return src[size:] 186 } 187 // Type SignalContext64 doesn't have a packed layout in memory, fallback to UnmarshalBytes. 188 return s.UnmarshalBytes(src) 189 } 190 191 // CopyOutN implements marshal.Marshallable.CopyOutN. 192 func (s *SignalContext64) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 193 if !s.Oldmask.Packed() { 194 // Type SignalContext64 doesn't have a packed layout in memory, fall back to MarshalBytes. 195 buf := cc.CopyScratchBuffer(s.SizeBytes()) // escapes: okay. 196 s.MarshalBytes(buf) // escapes: fallback. 197 return cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 198 } 199 200 // Construct a slice backed by dst's underlying memory. 201 var buf []byte 202 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 203 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(s))) 204 hdr.Len = s.SizeBytes() 205 hdr.Cap = s.SizeBytes() 206 207 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 208 // Since we bypassed the compiler's escape analysis, indicate that s 209 // must live until the use above. 210 runtime.KeepAlive(s) // escapes: replaced by intrinsic. 211 return length, err 212 } 213 214 // CopyOut implements marshal.Marshallable.CopyOut. 215 func (s *SignalContext64) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 216 return s.CopyOutN(cc, addr, s.SizeBytes()) 217 } 218 219 // CopyIn implements marshal.Marshallable.CopyIn. 220 func (s *SignalContext64) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 221 if !s.Oldmask.Packed() { 222 // Type SignalContext64 doesn't have a packed layout in memory, fall back to UnmarshalBytes. 223 buf := cc.CopyScratchBuffer(s.SizeBytes()) // escapes: okay. 224 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 225 // Unmarshal unconditionally. If we had a short copy-in, this results in a 226 // partially unmarshalled struct. 227 s.UnmarshalBytes(buf) // escapes: fallback. 228 return length, err 229 } 230 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(s))) 235 hdr.Len = s.SizeBytes() 236 hdr.Cap = s.SizeBytes() 237 238 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 239 // Since we bypassed the compiler's escape analysis, indicate that s 240 // must live until the use above. 241 runtime.KeepAlive(s) // escapes: replaced by intrinsic. 242 return length, err 243 } 244 245 // WriteTo implements io.WriterTo.WriteTo. 246 func (s *SignalContext64) WriteTo(writer io.Writer) (int64, error) { 247 if !s.Oldmask.Packed() { 248 // Type SignalContext64 doesn't have a packed layout in memory, fall back to MarshalBytes. 249 buf := make([]byte, s.SizeBytes()) 250 s.MarshalBytes(buf) 251 length, err := writer.Write(buf) 252 return int64(length), err 253 } 254 255 // Construct a slice backed by dst's underlying memory. 256 var buf []byte 257 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 258 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(s))) 259 hdr.Len = s.SizeBytes() 260 hdr.Cap = s.SizeBytes() 261 262 length, err := writer.Write(buf) 263 // Since we bypassed the compiler's escape analysis, indicate that s 264 // must live until the use above. 265 runtime.KeepAlive(s) // escapes: replaced by intrinsic. 266 return int64(length), err 267 } 268 269 // SizeBytes implements marshal.Marshallable.SizeBytes. 270 func (u *UContext64) SizeBytes() int { 271 return 16 + 272 (*linux.SignalStack)(nil).SizeBytes() + 273 (*SignalContext64)(nil).SizeBytes() + 274 (*linux.SignalSet)(nil).SizeBytes() 275 } 276 277 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 278 func (u *UContext64) MarshalBytes(dst []byte) []byte { 279 hostarch.ByteOrder.PutUint64(dst[:8], uint64(u.Flags)) 280 dst = dst[8:] 281 hostarch.ByteOrder.PutUint64(dst[:8], uint64(u.Link)) 282 dst = dst[8:] 283 dst = u.Stack.MarshalUnsafe(dst) 284 dst = u.MContext.MarshalUnsafe(dst) 285 dst = u.Sigset.MarshalUnsafe(dst) 286 return dst 287 } 288 289 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 290 func (u *UContext64) UnmarshalBytes(src []byte) []byte { 291 u.Flags = uint64(hostarch.ByteOrder.Uint64(src[:8])) 292 src = src[8:] 293 u.Link = uint64(hostarch.ByteOrder.Uint64(src[:8])) 294 src = src[8:] 295 src = u.Stack.UnmarshalUnsafe(src) 296 src = u.MContext.UnmarshalUnsafe(src) 297 src = u.Sigset.UnmarshalUnsafe(src) 298 return src 299 } 300 301 // Packed implements marshal.Marshallable.Packed. 302 // 303 //go:nosplit 304 func (u *UContext64) Packed() bool { 305 return u.MContext.Packed() && u.Sigset.Packed() && u.Stack.Packed() 306 } 307 308 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 309 func (u *UContext64) MarshalUnsafe(dst []byte) []byte { 310 if u.MContext.Packed() && u.Sigset.Packed() && u.Stack.Packed() { 311 size := u.SizeBytes() 312 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) 313 return dst[size:] 314 } 315 // Type UContext64 doesn't have a packed layout in memory, fallback to MarshalBytes. 316 return u.MarshalBytes(dst) 317 } 318 319 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 320 func (u *UContext64) UnmarshalUnsafe(src []byte) []byte { 321 if u.MContext.Packed() && u.Sigset.Packed() && u.Stack.Packed() { 322 size := u.SizeBytes() 323 gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) 324 return src[size:] 325 } 326 // Type UContext64 doesn't have a packed layout in memory, fallback to UnmarshalBytes. 327 return u.UnmarshalBytes(src) 328 } 329 330 // CopyOutN implements marshal.Marshallable.CopyOutN. 331 func (u *UContext64) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 332 if !u.MContext.Packed() && u.Sigset.Packed() && u.Stack.Packed() { 333 // Type UContext64 doesn't have a packed layout in memory, fall back to MarshalBytes. 334 buf := cc.CopyScratchBuffer(u.SizeBytes()) // escapes: okay. 335 u.MarshalBytes(buf) // escapes: fallback. 336 return cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 337 } 338 339 // Construct a slice backed by dst's underlying memory. 340 var buf []byte 341 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 342 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 343 hdr.Len = u.SizeBytes() 344 hdr.Cap = u.SizeBytes() 345 346 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 347 // Since we bypassed the compiler's escape analysis, indicate that u 348 // must live until the use above. 349 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 350 return length, err 351 } 352 353 // CopyOut implements marshal.Marshallable.CopyOut. 354 func (u *UContext64) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 355 return u.CopyOutN(cc, addr, u.SizeBytes()) 356 } 357 358 // CopyIn implements marshal.Marshallable.CopyIn. 359 func (u *UContext64) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 360 if !u.MContext.Packed() && u.Sigset.Packed() && u.Stack.Packed() { 361 // Type UContext64 doesn't have a packed layout in memory, fall back to UnmarshalBytes. 362 buf := cc.CopyScratchBuffer(u.SizeBytes()) // escapes: okay. 363 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 364 // Unmarshal unconditionally. If we had a short copy-in, this results in a 365 // partially unmarshalled struct. 366 u.UnmarshalBytes(buf) // escapes: fallback. 367 return length, err 368 } 369 370 // Construct a slice backed by dst's underlying memory. 371 var buf []byte 372 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 373 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 374 hdr.Len = u.SizeBytes() 375 hdr.Cap = u.SizeBytes() 376 377 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 378 // Since we bypassed the compiler's escape analysis, indicate that u 379 // must live until the use above. 380 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 381 return length, err 382 } 383 384 // WriteTo implements io.WriterTo.WriteTo. 385 func (u *UContext64) WriteTo(writer io.Writer) (int64, error) { 386 if !u.MContext.Packed() && u.Sigset.Packed() && u.Stack.Packed() { 387 // Type UContext64 doesn't have a packed layout in memory, fall back to MarshalBytes. 388 buf := make([]byte, u.SizeBytes()) 389 u.MarshalBytes(buf) 390 length, err := writer.Write(buf) 391 return int64(length), err 392 } 393 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(u))) 398 hdr.Len = u.SizeBytes() 399 hdr.Cap = u.SizeBytes() 400 401 length, err := writer.Write(buf) 402 // Since we bypassed the compiler's escape analysis, indicate that u 403 // must live until the use above. 404 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 405 return int64(length), err 406 }