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