github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/abi/linux/linux_arm64_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 arm64 && arm64 && arm64 && arm64 && arm64 10 // +build arm64,arm64,arm64,arm64,arm64 11 12 package linux 13 14 import ( 15 "github.com/nicocha30/gvisor-ligolo/pkg/gohacks" 16 "github.com/nicocha30/gvisor-ligolo/pkg/hostarch" 17 "github.com/nicocha30/gvisor-ligolo/pkg/marshal" 18 "io" 19 "reflect" 20 "runtime" 21 "unsafe" 22 ) 23 24 // Marshallable types used by this file. 25 var _ marshal.Marshallable = (*EpollEvent)(nil) 26 var _ marshal.Marshallable = (*IPCPerm)(nil) 27 var _ marshal.Marshallable = (*PtraceRegs)(nil) 28 var _ marshal.Marshallable = (*SemidDS)(nil) 29 var _ marshal.Marshallable = (*Stat)(nil) 30 var _ marshal.Marshallable = (*TimeT)(nil) 31 var _ marshal.Marshallable = (*Timespec)(nil) 32 33 // SizeBytes implements marshal.Marshallable.SizeBytes. 34 func (e *EpollEvent) SizeBytes() int { 35 return 8 + 36 4*2 37 } 38 39 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 40 func (e *EpollEvent) MarshalBytes(dst []byte) []byte { 41 hostarch.ByteOrder.PutUint32(dst[:4], uint32(e.Events)) 42 dst = dst[4:] 43 // Padding: dst[:sizeof(int32)] ~= int32(0) 44 dst = dst[4:] 45 for idx := 0; idx < 2; idx++ { 46 hostarch.ByteOrder.PutUint32(dst[:4], uint32(e.Data[idx])) 47 dst = dst[4:] 48 } 49 return dst 50 } 51 52 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 53 func (e *EpollEvent) UnmarshalBytes(src []byte) []byte { 54 e.Events = uint32(hostarch.ByteOrder.Uint32(src[:4])) 55 src = src[4:] 56 // Padding: var _ int32 ~= src[:sizeof(int32)] 57 src = src[4:] 58 for idx := 0; idx < 2; idx++ { 59 e.Data[idx] = int32(hostarch.ByteOrder.Uint32(src[:4])) 60 src = src[4:] 61 } 62 return src 63 } 64 65 // Packed implements marshal.Marshallable.Packed. 66 //go:nosplit 67 func (e *EpollEvent) Packed() bool { 68 return true 69 } 70 71 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 72 func (e *EpollEvent) MarshalUnsafe(dst []byte) []byte { 73 size := e.SizeBytes() 74 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(e), uintptr(size)) 75 return dst[size:] 76 } 77 78 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 79 func (e *EpollEvent) UnmarshalUnsafe(src []byte) []byte { 80 size := e.SizeBytes() 81 gohacks.Memmove(unsafe.Pointer(e), unsafe.Pointer(&src[0]), uintptr(size)) 82 return src[size:] 83 } 84 85 // CopyOutN implements marshal.Marshallable.CopyOutN. 86 func (e *EpollEvent) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 87 // Construct a slice backed by dst's underlying memory. 88 var buf []byte 89 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 90 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(e))) 91 hdr.Len = e.SizeBytes() 92 hdr.Cap = e.SizeBytes() 93 94 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 95 // Since we bypassed the compiler's escape analysis, indicate that e 96 // must live until the use above. 97 runtime.KeepAlive(e) // escapes: replaced by intrinsic. 98 return length, err 99 } 100 101 // CopyOut implements marshal.Marshallable.CopyOut. 102 func (e *EpollEvent) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 103 return e.CopyOutN(cc, addr, e.SizeBytes()) 104 } 105 106 // CopyIn implements marshal.Marshallable.CopyIn. 107 func (e *EpollEvent) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 108 // Construct a slice backed by dst's underlying memory. 109 var buf []byte 110 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 111 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(e))) 112 hdr.Len = e.SizeBytes() 113 hdr.Cap = e.SizeBytes() 114 115 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 116 // Since we bypassed the compiler's escape analysis, indicate that e 117 // must live until the use above. 118 runtime.KeepAlive(e) // escapes: replaced by intrinsic. 119 return length, err 120 } 121 122 // WriteTo implements io.WriterTo.WriteTo. 123 func (e *EpollEvent) WriteTo(writer io.Writer) (int64, error) { 124 // Construct a slice backed by dst's underlying memory. 125 var buf []byte 126 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 127 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(e))) 128 hdr.Len = e.SizeBytes() 129 hdr.Cap = e.SizeBytes() 130 131 length, err := writer.Write(buf) 132 // Since we bypassed the compiler's escape analysis, indicate that e 133 // must live until the use above. 134 runtime.KeepAlive(e) // escapes: replaced by intrinsic. 135 return int64(length), err 136 } 137 138 // CopyEpollEventSliceIn copies in a slice of EpollEvent objects from the task's memory. 139 func CopyEpollEventSliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []EpollEvent) (int, error) { 140 count := len(dst) 141 if count == 0 { 142 return 0, nil 143 } 144 size := (*EpollEvent)(nil).SizeBytes() 145 146 ptr := unsafe.Pointer(&dst) 147 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 148 149 // Construct a slice backed by dst's underlying memory. 150 var buf []byte 151 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 152 hdr.Data = uintptr(val) 153 hdr.Len = size * count 154 hdr.Cap = size * count 155 156 length, err := cc.CopyInBytes(addr, buf) 157 // Since we bypassed the compiler's escape analysis, indicate that dst 158 // must live until the use above. 159 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 160 return length, err 161 } 162 163 // CopyEpollEventSliceOut copies a slice of EpollEvent objects to the task's memory. 164 func CopyEpollEventSliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []EpollEvent) (int, error) { 165 count := len(src) 166 if count == 0 { 167 return 0, nil 168 } 169 size := (*EpollEvent)(nil).SizeBytes() 170 171 ptr := unsafe.Pointer(&src) 172 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 173 174 // Construct a slice backed by dst's underlying memory. 175 var buf []byte 176 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 177 hdr.Data = uintptr(val) 178 hdr.Len = size * count 179 hdr.Cap = size * count 180 181 length, err := cc.CopyOutBytes(addr, buf) 182 // Since we bypassed the compiler's escape analysis, indicate that src 183 // must live until the use above. 184 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 185 return length, err 186 } 187 188 // MarshalUnsafeEpollEventSlice is like EpollEvent.MarshalUnsafe, but for a []EpollEvent. 189 func MarshalUnsafeEpollEventSlice(src []EpollEvent, dst []byte) []byte { 190 count := len(src) 191 if count == 0 { 192 return dst 193 } 194 195 size := (*EpollEvent)(nil).SizeBytes() 196 buf := dst[:size*count] 197 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 198 return dst[size*count:] 199 } 200 201 // UnmarshalUnsafeEpollEventSlice is like EpollEvent.UnmarshalUnsafe, but for a []EpollEvent. 202 func UnmarshalUnsafeEpollEventSlice(dst []EpollEvent, src []byte) []byte { 203 count := len(dst) 204 if count == 0 { 205 return src 206 } 207 208 size := (*EpollEvent)(nil).SizeBytes() 209 buf := src[:size*count] 210 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 211 return src[size*count:] 212 } 213 214 // SizeBytes implements marshal.Marshallable.SizeBytes. 215 func (s *Stat) SizeBytes() int { 216 return 72 + 217 (*Timespec)(nil).SizeBytes() + 218 (*Timespec)(nil).SizeBytes() + 219 (*Timespec)(nil).SizeBytes() + 220 4*2 221 } 222 223 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 224 func (s *Stat) MarshalBytes(dst []byte) []byte { 225 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Dev)) 226 dst = dst[8:] 227 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Ino)) 228 dst = dst[8:] 229 hostarch.ByteOrder.PutUint32(dst[:4], uint32(s.Mode)) 230 dst = dst[4:] 231 hostarch.ByteOrder.PutUint32(dst[:4], uint32(s.Nlink)) 232 dst = dst[4:] 233 hostarch.ByteOrder.PutUint32(dst[:4], uint32(s.UID)) 234 dst = dst[4:] 235 hostarch.ByteOrder.PutUint32(dst[:4], uint32(s.GID)) 236 dst = dst[4:] 237 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Rdev)) 238 dst = dst[8:] 239 // Padding: dst[:sizeof(uint64)] ~= uint64(0) 240 dst = dst[8:] 241 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Size)) 242 dst = dst[8:] 243 hostarch.ByteOrder.PutUint32(dst[:4], uint32(s.Blksize)) 244 dst = dst[4:] 245 // Padding: dst[:sizeof(int32)] ~= int32(0) 246 dst = dst[4:] 247 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.Blocks)) 248 dst = dst[8:] 249 dst = s.ATime.MarshalUnsafe(dst) 250 dst = s.MTime.MarshalUnsafe(dst) 251 dst = s.CTime.MarshalUnsafe(dst) 252 // Padding: dst[:sizeof(int32)*2] ~= [2]int32{0} 253 dst = dst[4*(2):] 254 return dst 255 } 256 257 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 258 func (s *Stat) UnmarshalBytes(src []byte) []byte { 259 s.Dev = uint64(hostarch.ByteOrder.Uint64(src[:8])) 260 src = src[8:] 261 s.Ino = uint64(hostarch.ByteOrder.Uint64(src[:8])) 262 src = src[8:] 263 s.Mode = uint32(hostarch.ByteOrder.Uint32(src[:4])) 264 src = src[4:] 265 s.Nlink = uint32(hostarch.ByteOrder.Uint32(src[:4])) 266 src = src[4:] 267 s.UID = uint32(hostarch.ByteOrder.Uint32(src[:4])) 268 src = src[4:] 269 s.GID = uint32(hostarch.ByteOrder.Uint32(src[:4])) 270 src = src[4:] 271 s.Rdev = uint64(hostarch.ByteOrder.Uint64(src[:8])) 272 src = src[8:] 273 // Padding: var _ uint64 ~= src[:sizeof(uint64)] 274 src = src[8:] 275 s.Size = int64(hostarch.ByteOrder.Uint64(src[:8])) 276 src = src[8:] 277 s.Blksize = int32(hostarch.ByteOrder.Uint32(src[:4])) 278 src = src[4:] 279 // Padding: var _ int32 ~= src[:sizeof(int32)] 280 src = src[4:] 281 s.Blocks = int64(hostarch.ByteOrder.Uint64(src[:8])) 282 src = src[8:] 283 src = s.ATime.UnmarshalUnsafe(src) 284 src = s.MTime.UnmarshalUnsafe(src) 285 src = s.CTime.UnmarshalUnsafe(src) 286 // Padding: ~ copy([2]int32(s._), src[:sizeof(int32)*2]) 287 src = src[4*(2):] 288 return src 289 } 290 291 // Packed implements marshal.Marshallable.Packed. 292 //go:nosplit 293 func (s *Stat) Packed() bool { 294 return s.ATime.Packed() && s.CTime.Packed() && s.MTime.Packed() 295 } 296 297 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 298 func (s *Stat) MarshalUnsafe(dst []byte) []byte { 299 if s.ATime.Packed() && s.CTime.Packed() && s.MTime.Packed() { 300 size := s.SizeBytes() 301 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(s), uintptr(size)) 302 return dst[size:] 303 } 304 // Type Stat doesn't have a packed layout in memory, fallback to MarshalBytes. 305 return s.MarshalBytes(dst) 306 } 307 308 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 309 func (s *Stat) UnmarshalUnsafe(src []byte) []byte { 310 if s.ATime.Packed() && s.CTime.Packed() && s.MTime.Packed() { 311 size := s.SizeBytes() 312 gohacks.Memmove(unsafe.Pointer(s), unsafe.Pointer(&src[0]), uintptr(size)) 313 return src[size:] 314 } 315 // Type Stat doesn't have a packed layout in memory, fallback to UnmarshalBytes. 316 return s.UnmarshalBytes(src) 317 } 318 319 // CopyOutN implements marshal.Marshallable.CopyOutN. 320 func (s *Stat) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 321 if !s.ATime.Packed() && s.CTime.Packed() && s.MTime.Packed() { 322 // Type Stat doesn't have a packed layout in memory, fall back to MarshalBytes. 323 buf := cc.CopyScratchBuffer(s.SizeBytes()) // escapes: okay. 324 s.MarshalBytes(buf) // escapes: fallback. 325 return cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 326 } 327 328 // Construct a slice backed by dst's underlying memory. 329 var buf []byte 330 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 331 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(s))) 332 hdr.Len = s.SizeBytes() 333 hdr.Cap = s.SizeBytes() 334 335 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 336 // Since we bypassed the compiler's escape analysis, indicate that s 337 // must live until the use above. 338 runtime.KeepAlive(s) // escapes: replaced by intrinsic. 339 return length, err 340 } 341 342 // CopyOut implements marshal.Marshallable.CopyOut. 343 func (s *Stat) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 344 return s.CopyOutN(cc, addr, s.SizeBytes()) 345 } 346 347 // CopyIn implements marshal.Marshallable.CopyIn. 348 func (s *Stat) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 349 if !s.ATime.Packed() && s.CTime.Packed() && s.MTime.Packed() { 350 // Type Stat doesn't have a packed layout in memory, fall back to UnmarshalBytes. 351 buf := cc.CopyScratchBuffer(s.SizeBytes()) // escapes: okay. 352 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 353 // Unmarshal unconditionally. If we had a short copy-in, this results in a 354 // partially unmarshalled struct. 355 s.UnmarshalBytes(buf) // escapes: fallback. 356 return length, err 357 } 358 359 // Construct a slice backed by dst's underlying memory. 360 var buf []byte 361 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 362 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(s))) 363 hdr.Len = s.SizeBytes() 364 hdr.Cap = s.SizeBytes() 365 366 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 367 // Since we bypassed the compiler's escape analysis, indicate that s 368 // must live until the use above. 369 runtime.KeepAlive(s) // escapes: replaced by intrinsic. 370 return length, err 371 } 372 373 // WriteTo implements io.WriterTo.WriteTo. 374 func (s *Stat) WriteTo(writer io.Writer) (int64, error) { 375 if !s.ATime.Packed() && s.CTime.Packed() && s.MTime.Packed() { 376 // Type Stat doesn't have a packed layout in memory, fall back to MarshalBytes. 377 buf := make([]byte, s.SizeBytes()) 378 s.MarshalBytes(buf) 379 length, err := writer.Write(buf) 380 return int64(length), err 381 } 382 383 // Construct a slice backed by dst's underlying memory. 384 var buf []byte 385 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 386 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(s))) 387 hdr.Len = s.SizeBytes() 388 hdr.Cap = s.SizeBytes() 389 390 length, err := writer.Write(buf) 391 // Since we bypassed the compiler's escape analysis, indicate that s 392 // must live until the use above. 393 runtime.KeepAlive(s) // escapes: replaced by intrinsic. 394 return int64(length), err 395 } 396 397 // SizeBytes implements marshal.Marshallable.SizeBytes. 398 func (p *PtraceRegs) SizeBytes() int { 399 return 24 + 400 8*31 401 } 402 403 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 404 func (p *PtraceRegs) MarshalBytes(dst []byte) []byte { 405 for idx := 0; idx < 31; idx++ { 406 hostarch.ByteOrder.PutUint64(dst[:8], uint64(p.Regs[idx])) 407 dst = dst[8:] 408 } 409 hostarch.ByteOrder.PutUint64(dst[:8], uint64(p.Sp)) 410 dst = dst[8:] 411 hostarch.ByteOrder.PutUint64(dst[:8], uint64(p.Pc)) 412 dst = dst[8:] 413 hostarch.ByteOrder.PutUint64(dst[:8], uint64(p.Pstate)) 414 dst = dst[8:] 415 return dst 416 } 417 418 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 419 func (p *PtraceRegs) UnmarshalBytes(src []byte) []byte { 420 for idx := 0; idx < 31; idx++ { 421 p.Regs[idx] = uint64(hostarch.ByteOrder.Uint64(src[:8])) 422 src = src[8:] 423 } 424 p.Sp = uint64(hostarch.ByteOrder.Uint64(src[:8])) 425 src = src[8:] 426 p.Pc = uint64(hostarch.ByteOrder.Uint64(src[:8])) 427 src = src[8:] 428 p.Pstate = uint64(hostarch.ByteOrder.Uint64(src[:8])) 429 src = src[8:] 430 return src 431 } 432 433 // Packed implements marshal.Marshallable.Packed. 434 //go:nosplit 435 func (p *PtraceRegs) Packed() bool { 436 return true 437 } 438 439 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 440 func (p *PtraceRegs) MarshalUnsafe(dst []byte) []byte { 441 size := p.SizeBytes() 442 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(p), uintptr(size)) 443 return dst[size:] 444 } 445 446 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 447 func (p *PtraceRegs) UnmarshalUnsafe(src []byte) []byte { 448 size := p.SizeBytes() 449 gohacks.Memmove(unsafe.Pointer(p), unsafe.Pointer(&src[0]), uintptr(size)) 450 return src[size:] 451 } 452 453 // CopyOutN implements marshal.Marshallable.CopyOutN. 454 func (p *PtraceRegs) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 455 // Construct a slice backed by dst's underlying memory. 456 var buf []byte 457 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 458 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(p))) 459 hdr.Len = p.SizeBytes() 460 hdr.Cap = p.SizeBytes() 461 462 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 463 // Since we bypassed the compiler's escape analysis, indicate that p 464 // must live until the use above. 465 runtime.KeepAlive(p) // escapes: replaced by intrinsic. 466 return length, err 467 } 468 469 // CopyOut implements marshal.Marshallable.CopyOut. 470 func (p *PtraceRegs) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 471 return p.CopyOutN(cc, addr, p.SizeBytes()) 472 } 473 474 // CopyIn implements marshal.Marshallable.CopyIn. 475 func (p *PtraceRegs) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 476 // Construct a slice backed by dst's underlying memory. 477 var buf []byte 478 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 479 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(p))) 480 hdr.Len = p.SizeBytes() 481 hdr.Cap = p.SizeBytes() 482 483 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 484 // Since we bypassed the compiler's escape analysis, indicate that p 485 // must live until the use above. 486 runtime.KeepAlive(p) // escapes: replaced by intrinsic. 487 return length, err 488 } 489 490 // WriteTo implements io.WriterTo.WriteTo. 491 func (p *PtraceRegs) WriteTo(writer io.Writer) (int64, error) { 492 // Construct a slice backed by dst's underlying memory. 493 var buf []byte 494 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 495 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(p))) 496 hdr.Len = p.SizeBytes() 497 hdr.Cap = p.SizeBytes() 498 499 length, err := writer.Write(buf) 500 // Since we bypassed the compiler's escape analysis, indicate that p 501 // must live until the use above. 502 runtime.KeepAlive(p) // escapes: replaced by intrinsic. 503 return int64(length), err 504 } 505 506 // SizeBytes implements marshal.Marshallable.SizeBytes. 507 func (s *SemidDS) SizeBytes() int { 508 return 24 + 509 (*IPCPerm)(nil).SizeBytes() + 510 (*TimeT)(nil).SizeBytes() + 511 (*TimeT)(nil).SizeBytes() 512 } 513 514 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 515 func (s *SemidDS) MarshalBytes(dst []byte) []byte { 516 dst = s.SemPerm.MarshalUnsafe(dst) 517 dst = s.SemOTime.MarshalUnsafe(dst) 518 dst = s.SemCTime.MarshalUnsafe(dst) 519 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.SemNSems)) 520 dst = dst[8:] 521 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.unused3)) 522 dst = dst[8:] 523 hostarch.ByteOrder.PutUint64(dst[:8], uint64(s.unused4)) 524 dst = dst[8:] 525 return dst 526 } 527 528 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 529 func (s *SemidDS) UnmarshalBytes(src []byte) []byte { 530 src = s.SemPerm.UnmarshalUnsafe(src) 531 src = s.SemOTime.UnmarshalUnsafe(src) 532 src = s.SemCTime.UnmarshalUnsafe(src) 533 s.SemNSems = uint64(hostarch.ByteOrder.Uint64(src[:8])) 534 src = src[8:] 535 s.unused3 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 536 src = src[8:] 537 s.unused4 = uint64(hostarch.ByteOrder.Uint64(src[:8])) 538 src = src[8:] 539 return src 540 } 541 542 // Packed implements marshal.Marshallable.Packed. 543 //go:nosplit 544 func (s *SemidDS) Packed() bool { 545 return s.SemCTime.Packed() && s.SemOTime.Packed() && s.SemPerm.Packed() 546 } 547 548 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 549 func (s *SemidDS) MarshalUnsafe(dst []byte) []byte { 550 if s.SemCTime.Packed() && s.SemOTime.Packed() && s.SemPerm.Packed() { 551 size := s.SizeBytes() 552 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(s), uintptr(size)) 553 return dst[size:] 554 } 555 // Type SemidDS doesn't have a packed layout in memory, fallback to MarshalBytes. 556 return s.MarshalBytes(dst) 557 } 558 559 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 560 func (s *SemidDS) UnmarshalUnsafe(src []byte) []byte { 561 if s.SemCTime.Packed() && s.SemOTime.Packed() && s.SemPerm.Packed() { 562 size := s.SizeBytes() 563 gohacks.Memmove(unsafe.Pointer(s), unsafe.Pointer(&src[0]), uintptr(size)) 564 return src[size:] 565 } 566 // Type SemidDS doesn't have a packed layout in memory, fallback to UnmarshalBytes. 567 return s.UnmarshalBytes(src) 568 } 569 570 // CopyOutN implements marshal.Marshallable.CopyOutN. 571 func (s *SemidDS) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 572 if !s.SemCTime.Packed() && s.SemOTime.Packed() && s.SemPerm.Packed() { 573 // Type SemidDS doesn't have a packed layout in memory, fall back to MarshalBytes. 574 buf := cc.CopyScratchBuffer(s.SizeBytes()) // escapes: okay. 575 s.MarshalBytes(buf) // escapes: fallback. 576 return cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 577 } 578 579 // Construct a slice backed by dst's underlying memory. 580 var buf []byte 581 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 582 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(s))) 583 hdr.Len = s.SizeBytes() 584 hdr.Cap = s.SizeBytes() 585 586 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 587 // Since we bypassed the compiler's escape analysis, indicate that s 588 // must live until the use above. 589 runtime.KeepAlive(s) // escapes: replaced by intrinsic. 590 return length, err 591 } 592 593 // CopyOut implements marshal.Marshallable.CopyOut. 594 func (s *SemidDS) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 595 return s.CopyOutN(cc, addr, s.SizeBytes()) 596 } 597 598 // CopyIn implements marshal.Marshallable.CopyIn. 599 func (s *SemidDS) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 600 if !s.SemCTime.Packed() && s.SemOTime.Packed() && s.SemPerm.Packed() { 601 // Type SemidDS doesn't have a packed layout in memory, fall back to UnmarshalBytes. 602 buf := cc.CopyScratchBuffer(s.SizeBytes()) // escapes: okay. 603 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 604 // Unmarshal unconditionally. If we had a short copy-in, this results in a 605 // partially unmarshalled struct. 606 s.UnmarshalBytes(buf) // escapes: fallback. 607 return length, err 608 } 609 610 // Construct a slice backed by dst's underlying memory. 611 var buf []byte 612 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 613 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(s))) 614 hdr.Len = s.SizeBytes() 615 hdr.Cap = s.SizeBytes() 616 617 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 618 // Since we bypassed the compiler's escape analysis, indicate that s 619 // must live until the use above. 620 runtime.KeepAlive(s) // escapes: replaced by intrinsic. 621 return length, err 622 } 623 624 // WriteTo implements io.WriterTo.WriteTo. 625 func (s *SemidDS) WriteTo(writer io.Writer) (int64, error) { 626 if !s.SemCTime.Packed() && s.SemOTime.Packed() && s.SemPerm.Packed() { 627 // Type SemidDS doesn't have a packed layout in memory, fall back to MarshalBytes. 628 buf := make([]byte, s.SizeBytes()) 629 s.MarshalBytes(buf) 630 length, err := writer.Write(buf) 631 return int64(length), err 632 } 633 634 // Construct a slice backed by dst's underlying memory. 635 var buf []byte 636 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 637 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(s))) 638 hdr.Len = s.SizeBytes() 639 hdr.Cap = s.SizeBytes() 640 641 length, err := writer.Write(buf) 642 // Since we bypassed the compiler's escape analysis, indicate that s 643 // must live until the use above. 644 runtime.KeepAlive(s) // escapes: replaced by intrinsic. 645 return int64(length), err 646 } 647