inet.af/netstack@v0.0.0-20220214151720-7585b01ddccf/marshal/primitive/primitive_abi_autogen_unsafe.go (about) 1 // Automatically generated marshal implementation. See tools/go_marshal. 2 3 package primitive 4 5 import ( 6 "inet.af/netstack/gohacks" 7 "inet.af/netstack/hostarch" 8 "inet.af/netstack/marshal" 9 "io" 10 "reflect" 11 "runtime" 12 "unsafe" 13 ) 14 15 // Marshallable types used by this file. 16 var _ marshal.Marshallable = (*Int16)(nil) 17 var _ marshal.Marshallable = (*Int32)(nil) 18 var _ marshal.Marshallable = (*Int64)(nil) 19 var _ marshal.Marshallable = (*Int8)(nil) 20 var _ marshal.Marshallable = (*Uint16)(nil) 21 var _ marshal.Marshallable = (*Uint32)(nil) 22 var _ marshal.Marshallable = (*Uint64)(nil) 23 var _ marshal.Marshallable = (*Uint8)(nil) 24 25 // SizeBytes implements marshal.Marshallable.SizeBytes. 26 //go:nosplit 27 func (i *Int16) SizeBytes() int { 28 return 2 29 } 30 31 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 32 func (i *Int16) MarshalBytes(dst []byte) []byte { 33 hostarch.ByteOrder.PutUint16(dst[:2], uint16(*i)) 34 return dst[2:] 35 } 36 37 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 38 func (i *Int16) UnmarshalBytes(src []byte) []byte { 39 *i = Int16(int16(hostarch.ByteOrder.Uint16(src[:2]))) 40 return src[2:] 41 } 42 43 // Packed implements marshal.Marshallable.Packed. 44 //go:nosplit 45 func (i *Int16) Packed() bool { 46 // Scalar newtypes are always packed. 47 return true 48 } 49 50 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 51 func (i *Int16) MarshalUnsafe(dst []byte) []byte { 52 size := i.SizeBytes() 53 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) 54 return dst[size:] 55 } 56 57 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 58 func (i *Int16) UnmarshalUnsafe(src []byte) []byte { 59 size := i.SizeBytes() 60 gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) 61 return src[size:] 62 } 63 64 // CopyOutN implements marshal.Marshallable.CopyOutN. 65 //go:nosplit 66 func (i *Int16) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 67 // Construct a slice backed by dst's underlying memory. 68 var buf []byte 69 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 70 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 71 hdr.Len = i.SizeBytes() 72 hdr.Cap = i.SizeBytes() 73 74 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 75 // Since we bypassed the compiler's escape analysis, indicate that i 76 // must live until the use above. 77 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 78 return length, err 79 } 80 81 // CopyOut implements marshal.Marshallable.CopyOut. 82 //go:nosplit 83 func (i *Int16) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 84 return i.CopyOutN(cc, addr, i.SizeBytes()) 85 } 86 87 // CopyIn implements marshal.Marshallable.CopyIn. 88 //go:nosplit 89 func (i *Int16) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 90 // Construct a slice backed by dst's underlying memory. 91 var buf []byte 92 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 93 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 94 hdr.Len = i.SizeBytes() 95 hdr.Cap = i.SizeBytes() 96 97 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 98 // Since we bypassed the compiler's escape analysis, indicate that i 99 // must live until the use above. 100 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 101 return length, err 102 } 103 104 // WriteTo implements io.WriterTo.WriteTo. 105 func (i *Int16) WriteTo(writer io.Writer) (int64, error) { 106 // Construct a slice backed by dst's underlying memory. 107 var buf []byte 108 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 109 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 110 hdr.Len = i.SizeBytes() 111 hdr.Cap = i.SizeBytes() 112 113 length, err := writer.Write(buf) 114 // Since we bypassed the compiler's escape analysis, indicate that i 115 // must live until the use above. 116 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 117 return int64(length), err 118 } 119 120 // CheckedMarshal implements marshal.CheckedMarshallable.CheckedMarshal. 121 func (i *Int16) CheckedMarshal(dst []byte) ([]byte, bool) { 122 size := i.SizeBytes() 123 if size > len(dst) { 124 return dst, false 125 } 126 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) 127 return dst[size:], true 128 } 129 130 // CheckedUnmarshal implements marshal.CheckedMarshallable.CheckedUnmarshal. 131 func (i *Int16) CheckedUnmarshal(src []byte) ([]byte, bool) { 132 size := i.SizeBytes() 133 if size > len(src) { 134 return src, false 135 } 136 gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) 137 return src[size:], true 138 } 139 140 // CopyInt16SliceIn copies in a slice of int16 objects from the task's memory. 141 //go:nosplit 142 func CopyInt16SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []int16) (int, error) { 143 count := len(dst) 144 if count == 0 { 145 return 0, nil 146 } 147 size := (*Int16)(nil).SizeBytes() 148 149 ptr := unsafe.Pointer(&dst) 150 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 151 152 // Construct a slice backed by dst's underlying memory. 153 var buf []byte 154 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 155 hdr.Data = uintptr(val) 156 hdr.Len = size * count 157 hdr.Cap = size * count 158 159 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 160 // Since we bypassed the compiler's escape analysis, indicate that dst 161 // must live until the use above. 162 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 163 return length, err 164 } 165 166 // CopyInt16SliceOut copies a slice of int16 objects to the task's memory. 167 //go:nosplit 168 func CopyInt16SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []int16) (int, error) { 169 count := len(src) 170 if count == 0 { 171 return 0, nil 172 } 173 size := (*Int16)(nil).SizeBytes() 174 175 ptr := unsafe.Pointer(&src) 176 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 177 178 // Construct a slice backed by dst's underlying memory. 179 var buf []byte 180 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 181 hdr.Data = uintptr(val) 182 hdr.Len = size * count 183 hdr.Cap = size * count 184 185 length, err := cc.CopyOutBytes(addr, buf) // escapes: okay. 186 // Since we bypassed the compiler's escape analysis, indicate that src 187 // must live until the use above. 188 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 189 return length, err 190 } 191 192 // MarshalUnsafeInt16Slice is like Int16.MarshalUnsafe, but for a []Int16. 193 func MarshalUnsafeInt16Slice(src []Int16, dst []byte) []byte { 194 count := len(src) 195 if count == 0 { 196 return dst 197 } 198 size := (*Int16)(nil).SizeBytes() 199 200 buf := dst[:size*count] 201 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 202 return dst[size*count:] 203 } 204 205 // UnmarshalUnsafeInt16Slice is like Int16.UnmarshalUnsafe, but for a []Int16. 206 func UnmarshalUnsafeInt16Slice(dst []Int16, src []byte) []byte { 207 count := len(dst) 208 if count == 0 { 209 return src 210 } 211 size := (*Int16)(nil).SizeBytes() 212 213 buf := src[:size*count] 214 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 215 return src[size*count:] 216 } 217 218 // SizeBytes implements marshal.Marshallable.SizeBytes. 219 //go:nosplit 220 func (i *Int32) SizeBytes() int { 221 return 4 222 } 223 224 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 225 func (i *Int32) MarshalBytes(dst []byte) []byte { 226 hostarch.ByteOrder.PutUint32(dst[:4], uint32(*i)) 227 return dst[4:] 228 } 229 230 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 231 func (i *Int32) UnmarshalBytes(src []byte) []byte { 232 *i = Int32(int32(hostarch.ByteOrder.Uint32(src[:4]))) 233 return src[4:] 234 } 235 236 // Packed implements marshal.Marshallable.Packed. 237 //go:nosplit 238 func (i *Int32) Packed() bool { 239 // Scalar newtypes are always packed. 240 return true 241 } 242 243 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 244 func (i *Int32) MarshalUnsafe(dst []byte) []byte { 245 size := i.SizeBytes() 246 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) 247 return dst[size:] 248 } 249 250 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 251 func (i *Int32) UnmarshalUnsafe(src []byte) []byte { 252 size := i.SizeBytes() 253 gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) 254 return src[size:] 255 } 256 257 // CopyOutN implements marshal.Marshallable.CopyOutN. 258 //go:nosplit 259 func (i *Int32) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 260 // Construct a slice backed by dst's underlying memory. 261 var buf []byte 262 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 263 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 264 hdr.Len = i.SizeBytes() 265 hdr.Cap = i.SizeBytes() 266 267 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 268 // Since we bypassed the compiler's escape analysis, indicate that i 269 // must live until the use above. 270 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 271 return length, err 272 } 273 274 // CopyOut implements marshal.Marshallable.CopyOut. 275 //go:nosplit 276 func (i *Int32) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 277 return i.CopyOutN(cc, addr, i.SizeBytes()) 278 } 279 280 // CopyIn implements marshal.Marshallable.CopyIn. 281 //go:nosplit 282 func (i *Int32) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 283 // Construct a slice backed by dst's underlying memory. 284 var buf []byte 285 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 286 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 287 hdr.Len = i.SizeBytes() 288 hdr.Cap = i.SizeBytes() 289 290 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 291 // Since we bypassed the compiler's escape analysis, indicate that i 292 // must live until the use above. 293 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 294 return length, err 295 } 296 297 // WriteTo implements io.WriterTo.WriteTo. 298 func (i *Int32) WriteTo(writer io.Writer) (int64, error) { 299 // Construct a slice backed by dst's underlying memory. 300 var buf []byte 301 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 302 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 303 hdr.Len = i.SizeBytes() 304 hdr.Cap = i.SizeBytes() 305 306 length, err := writer.Write(buf) 307 // Since we bypassed the compiler's escape analysis, indicate that i 308 // must live until the use above. 309 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 310 return int64(length), err 311 } 312 313 // CheckedMarshal implements marshal.CheckedMarshallable.CheckedMarshal. 314 func (i *Int32) CheckedMarshal(dst []byte) ([]byte, bool) { 315 size := i.SizeBytes() 316 if size > len(dst) { 317 return dst, false 318 } 319 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) 320 return dst[size:], true 321 } 322 323 // CheckedUnmarshal implements marshal.CheckedMarshallable.CheckedUnmarshal. 324 func (i *Int32) CheckedUnmarshal(src []byte) ([]byte, bool) { 325 size := i.SizeBytes() 326 if size > len(src) { 327 return src, false 328 } 329 gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) 330 return src[size:], true 331 } 332 333 // CopyInt32SliceIn copies in a slice of int32 objects from the task's memory. 334 //go:nosplit 335 func CopyInt32SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []int32) (int, error) { 336 count := len(dst) 337 if count == 0 { 338 return 0, nil 339 } 340 size := (*Int32)(nil).SizeBytes() 341 342 ptr := unsafe.Pointer(&dst) 343 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 344 345 // Construct a slice backed by dst's underlying memory. 346 var buf []byte 347 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 348 hdr.Data = uintptr(val) 349 hdr.Len = size * count 350 hdr.Cap = size * count 351 352 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 353 // Since we bypassed the compiler's escape analysis, indicate that dst 354 // must live until the use above. 355 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 356 return length, err 357 } 358 359 // CopyInt32SliceOut copies a slice of int32 objects to the task's memory. 360 //go:nosplit 361 func CopyInt32SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []int32) (int, error) { 362 count := len(src) 363 if count == 0 { 364 return 0, nil 365 } 366 size := (*Int32)(nil).SizeBytes() 367 368 ptr := unsafe.Pointer(&src) 369 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 370 371 // Construct a slice backed by dst's underlying memory. 372 var buf []byte 373 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 374 hdr.Data = uintptr(val) 375 hdr.Len = size * count 376 hdr.Cap = size * count 377 378 length, err := cc.CopyOutBytes(addr, buf) // escapes: okay. 379 // Since we bypassed the compiler's escape analysis, indicate that src 380 // must live until the use above. 381 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 382 return length, err 383 } 384 385 // MarshalUnsafeInt32Slice is like Int32.MarshalUnsafe, but for a []Int32. 386 func MarshalUnsafeInt32Slice(src []Int32, dst []byte) []byte { 387 count := len(src) 388 if count == 0 { 389 return dst 390 } 391 size := (*Int32)(nil).SizeBytes() 392 393 buf := dst[:size*count] 394 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 395 return dst[size*count:] 396 } 397 398 // UnmarshalUnsafeInt32Slice is like Int32.UnmarshalUnsafe, but for a []Int32. 399 func UnmarshalUnsafeInt32Slice(dst []Int32, src []byte) []byte { 400 count := len(dst) 401 if count == 0 { 402 return src 403 } 404 size := (*Int32)(nil).SizeBytes() 405 406 buf := src[:size*count] 407 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 408 return src[size*count:] 409 } 410 411 // SizeBytes implements marshal.Marshallable.SizeBytes. 412 //go:nosplit 413 func (i *Int64) SizeBytes() int { 414 return 8 415 } 416 417 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 418 func (i *Int64) MarshalBytes(dst []byte) []byte { 419 hostarch.ByteOrder.PutUint64(dst[:8], uint64(*i)) 420 return dst[8:] 421 } 422 423 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 424 func (i *Int64) UnmarshalBytes(src []byte) []byte { 425 *i = Int64(int64(hostarch.ByteOrder.Uint64(src[:8]))) 426 return src[8:] 427 } 428 429 // Packed implements marshal.Marshallable.Packed. 430 //go:nosplit 431 func (i *Int64) Packed() bool { 432 // Scalar newtypes are always packed. 433 return true 434 } 435 436 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 437 func (i *Int64) MarshalUnsafe(dst []byte) []byte { 438 size := i.SizeBytes() 439 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) 440 return dst[size:] 441 } 442 443 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 444 func (i *Int64) UnmarshalUnsafe(src []byte) []byte { 445 size := i.SizeBytes() 446 gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) 447 return src[size:] 448 } 449 450 // CopyOutN implements marshal.Marshallable.CopyOutN. 451 //go:nosplit 452 func (i *Int64) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 453 // Construct a slice backed by dst's underlying memory. 454 var buf []byte 455 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 456 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 457 hdr.Len = i.SizeBytes() 458 hdr.Cap = i.SizeBytes() 459 460 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 461 // Since we bypassed the compiler's escape analysis, indicate that i 462 // must live until the use above. 463 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 464 return length, err 465 } 466 467 // CopyOut implements marshal.Marshallable.CopyOut. 468 //go:nosplit 469 func (i *Int64) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 470 return i.CopyOutN(cc, addr, i.SizeBytes()) 471 } 472 473 // CopyIn implements marshal.Marshallable.CopyIn. 474 //go:nosplit 475 func (i *Int64) 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(i))) 480 hdr.Len = i.SizeBytes() 481 hdr.Cap = i.SizeBytes() 482 483 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 484 // Since we bypassed the compiler's escape analysis, indicate that i 485 // must live until the use above. 486 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 487 return length, err 488 } 489 490 // WriteTo implements io.WriterTo.WriteTo. 491 func (i *Int64) 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(i))) 496 hdr.Len = i.SizeBytes() 497 hdr.Cap = i.SizeBytes() 498 499 length, err := writer.Write(buf) 500 // Since we bypassed the compiler's escape analysis, indicate that i 501 // must live until the use above. 502 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 503 return int64(length), err 504 } 505 506 // CheckedMarshal implements marshal.CheckedMarshallable.CheckedMarshal. 507 func (i *Int64) CheckedMarshal(dst []byte) ([]byte, bool) { 508 size := i.SizeBytes() 509 if size > len(dst) { 510 return dst, false 511 } 512 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) 513 return dst[size:], true 514 } 515 516 // CheckedUnmarshal implements marshal.CheckedMarshallable.CheckedUnmarshal. 517 func (i *Int64) CheckedUnmarshal(src []byte) ([]byte, bool) { 518 size := i.SizeBytes() 519 if size > len(src) { 520 return src, false 521 } 522 gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) 523 return src[size:], true 524 } 525 526 // CopyInt64SliceIn copies in a slice of int64 objects from the task's memory. 527 //go:nosplit 528 func CopyInt64SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []int64) (int, error) { 529 count := len(dst) 530 if count == 0 { 531 return 0, nil 532 } 533 size := (*Int64)(nil).SizeBytes() 534 535 ptr := unsafe.Pointer(&dst) 536 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 537 538 // Construct a slice backed by dst's underlying memory. 539 var buf []byte 540 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 541 hdr.Data = uintptr(val) 542 hdr.Len = size * count 543 hdr.Cap = size * count 544 545 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 546 // Since we bypassed the compiler's escape analysis, indicate that dst 547 // must live until the use above. 548 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 549 return length, err 550 } 551 552 // CopyInt64SliceOut copies a slice of int64 objects to the task's memory. 553 //go:nosplit 554 func CopyInt64SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []int64) (int, error) { 555 count := len(src) 556 if count == 0 { 557 return 0, nil 558 } 559 size := (*Int64)(nil).SizeBytes() 560 561 ptr := unsafe.Pointer(&src) 562 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 563 564 // Construct a slice backed by dst's underlying memory. 565 var buf []byte 566 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 567 hdr.Data = uintptr(val) 568 hdr.Len = size * count 569 hdr.Cap = size * count 570 571 length, err := cc.CopyOutBytes(addr, buf) // escapes: okay. 572 // Since we bypassed the compiler's escape analysis, indicate that src 573 // must live until the use above. 574 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 575 return length, err 576 } 577 578 // MarshalUnsafeInt64Slice is like Int64.MarshalUnsafe, but for a []Int64. 579 func MarshalUnsafeInt64Slice(src []Int64, dst []byte) []byte { 580 count := len(src) 581 if count == 0 { 582 return dst 583 } 584 size := (*Int64)(nil).SizeBytes() 585 586 buf := dst[:size*count] 587 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 588 return dst[size*count:] 589 } 590 591 // UnmarshalUnsafeInt64Slice is like Int64.UnmarshalUnsafe, but for a []Int64. 592 func UnmarshalUnsafeInt64Slice(dst []Int64, src []byte) []byte { 593 count := len(dst) 594 if count == 0 { 595 return src 596 } 597 size := (*Int64)(nil).SizeBytes() 598 599 buf := src[:size*count] 600 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 601 return src[size*count:] 602 } 603 604 // SizeBytes implements marshal.Marshallable.SizeBytes. 605 //go:nosplit 606 func (i *Int8) SizeBytes() int { 607 return 1 608 } 609 610 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 611 func (i *Int8) MarshalBytes(dst []byte) []byte { 612 dst[0] = byte(*i) 613 return dst[1:] 614 } 615 616 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 617 func (i *Int8) UnmarshalBytes(src []byte) []byte { 618 *i = Int8(int8(src[0])) 619 return src[1:] 620 } 621 622 // Packed implements marshal.Marshallable.Packed. 623 //go:nosplit 624 func (i *Int8) Packed() bool { 625 // Scalar newtypes are always packed. 626 return true 627 } 628 629 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 630 func (i *Int8) MarshalUnsafe(dst []byte) []byte { 631 size := i.SizeBytes() 632 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) 633 return dst[size:] 634 } 635 636 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 637 func (i *Int8) UnmarshalUnsafe(src []byte) []byte { 638 size := i.SizeBytes() 639 gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) 640 return src[size:] 641 } 642 643 // CopyOutN implements marshal.Marshallable.CopyOutN. 644 //go:nosplit 645 func (i *Int8) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 646 // Construct a slice backed by dst's underlying memory. 647 var buf []byte 648 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 649 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 650 hdr.Len = i.SizeBytes() 651 hdr.Cap = i.SizeBytes() 652 653 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 654 // Since we bypassed the compiler's escape analysis, indicate that i 655 // must live until the use above. 656 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 657 return length, err 658 } 659 660 // CopyOut implements marshal.Marshallable.CopyOut. 661 //go:nosplit 662 func (i *Int8) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 663 return i.CopyOutN(cc, addr, i.SizeBytes()) 664 } 665 666 // CopyIn implements marshal.Marshallable.CopyIn. 667 //go:nosplit 668 func (i *Int8) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 669 // Construct a slice backed by dst's underlying memory. 670 var buf []byte 671 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 672 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 673 hdr.Len = i.SizeBytes() 674 hdr.Cap = i.SizeBytes() 675 676 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 677 // Since we bypassed the compiler's escape analysis, indicate that i 678 // must live until the use above. 679 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 680 return length, err 681 } 682 683 // WriteTo implements io.WriterTo.WriteTo. 684 func (i *Int8) WriteTo(writer io.Writer) (int64, error) { 685 // Construct a slice backed by dst's underlying memory. 686 var buf []byte 687 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 688 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) 689 hdr.Len = i.SizeBytes() 690 hdr.Cap = i.SizeBytes() 691 692 length, err := writer.Write(buf) 693 // Since we bypassed the compiler's escape analysis, indicate that i 694 // must live until the use above. 695 runtime.KeepAlive(i) // escapes: replaced by intrinsic. 696 return int64(length), err 697 } 698 699 // CheckedMarshal implements marshal.CheckedMarshallable.CheckedMarshal. 700 func (i *Int8) CheckedMarshal(dst []byte) ([]byte, bool) { 701 size := i.SizeBytes() 702 if size > len(dst) { 703 return dst, false 704 } 705 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) 706 return dst[size:], true 707 } 708 709 // CheckedUnmarshal implements marshal.CheckedMarshallable.CheckedUnmarshal. 710 func (i *Int8) CheckedUnmarshal(src []byte) ([]byte, bool) { 711 size := i.SizeBytes() 712 if size > len(src) { 713 return src, false 714 } 715 gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) 716 return src[size:], true 717 } 718 719 // CopyInt8SliceIn copies in a slice of int8 objects from the task's memory. 720 //go:nosplit 721 func CopyInt8SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []int8) (int, error) { 722 count := len(dst) 723 if count == 0 { 724 return 0, nil 725 } 726 size := (*Int8)(nil).SizeBytes() 727 728 ptr := unsafe.Pointer(&dst) 729 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 730 731 // Construct a slice backed by dst's underlying memory. 732 var buf []byte 733 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 734 hdr.Data = uintptr(val) 735 hdr.Len = size * count 736 hdr.Cap = size * count 737 738 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 739 // Since we bypassed the compiler's escape analysis, indicate that dst 740 // must live until the use above. 741 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 742 return length, err 743 } 744 745 // CopyInt8SliceOut copies a slice of int8 objects to the task's memory. 746 //go:nosplit 747 func CopyInt8SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []int8) (int, error) { 748 count := len(src) 749 if count == 0 { 750 return 0, nil 751 } 752 size := (*Int8)(nil).SizeBytes() 753 754 ptr := unsafe.Pointer(&src) 755 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 756 757 // Construct a slice backed by dst's underlying memory. 758 var buf []byte 759 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 760 hdr.Data = uintptr(val) 761 hdr.Len = size * count 762 hdr.Cap = size * count 763 764 length, err := cc.CopyOutBytes(addr, buf) // escapes: okay. 765 // Since we bypassed the compiler's escape analysis, indicate that src 766 // must live until the use above. 767 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 768 return length, err 769 } 770 771 // MarshalUnsafeInt8Slice is like Int8.MarshalUnsafe, but for a []Int8. 772 func MarshalUnsafeInt8Slice(src []Int8, dst []byte) []byte { 773 count := len(src) 774 if count == 0 { 775 return dst 776 } 777 size := (*Int8)(nil).SizeBytes() 778 779 buf := dst[:size*count] 780 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 781 return dst[size*count:] 782 } 783 784 // UnmarshalUnsafeInt8Slice is like Int8.UnmarshalUnsafe, but for a []Int8. 785 func UnmarshalUnsafeInt8Slice(dst []Int8, src []byte) []byte { 786 count := len(dst) 787 if count == 0 { 788 return src 789 } 790 size := (*Int8)(nil).SizeBytes() 791 792 buf := src[:size*count] 793 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 794 return src[size*count:] 795 } 796 797 // SizeBytes implements marshal.Marshallable.SizeBytes. 798 //go:nosplit 799 func (u *Uint16) SizeBytes() int { 800 return 2 801 } 802 803 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 804 func (u *Uint16) MarshalBytes(dst []byte) []byte { 805 hostarch.ByteOrder.PutUint16(dst[:2], uint16(*u)) 806 return dst[2:] 807 } 808 809 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 810 func (u *Uint16) UnmarshalBytes(src []byte) []byte { 811 *u = Uint16(uint16(hostarch.ByteOrder.Uint16(src[:2]))) 812 return src[2:] 813 } 814 815 // Packed implements marshal.Marshallable.Packed. 816 //go:nosplit 817 func (u *Uint16) Packed() bool { 818 // Scalar newtypes are always packed. 819 return true 820 } 821 822 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 823 func (u *Uint16) MarshalUnsafe(dst []byte) []byte { 824 size := u.SizeBytes() 825 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) 826 return dst[size:] 827 } 828 829 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 830 func (u *Uint16) UnmarshalUnsafe(src []byte) []byte { 831 size := u.SizeBytes() 832 gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) 833 return src[size:] 834 } 835 836 // CopyOutN implements marshal.Marshallable.CopyOutN. 837 //go:nosplit 838 func (u *Uint16) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 839 // Construct a slice backed by dst's underlying memory. 840 var buf []byte 841 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 842 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 843 hdr.Len = u.SizeBytes() 844 hdr.Cap = u.SizeBytes() 845 846 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 847 // Since we bypassed the compiler's escape analysis, indicate that u 848 // must live until the use above. 849 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 850 return length, err 851 } 852 853 // CopyOut implements marshal.Marshallable.CopyOut. 854 //go:nosplit 855 func (u *Uint16) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 856 return u.CopyOutN(cc, addr, u.SizeBytes()) 857 } 858 859 // CopyIn implements marshal.Marshallable.CopyIn. 860 //go:nosplit 861 func (u *Uint16) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 862 // Construct a slice backed by dst's underlying memory. 863 var buf []byte 864 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 865 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 866 hdr.Len = u.SizeBytes() 867 hdr.Cap = u.SizeBytes() 868 869 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 870 // Since we bypassed the compiler's escape analysis, indicate that u 871 // must live until the use above. 872 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 873 return length, err 874 } 875 876 // WriteTo implements io.WriterTo.WriteTo. 877 func (u *Uint16) WriteTo(writer io.Writer) (int64, error) { 878 // Construct a slice backed by dst's underlying memory. 879 var buf []byte 880 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 881 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 882 hdr.Len = u.SizeBytes() 883 hdr.Cap = u.SizeBytes() 884 885 length, err := writer.Write(buf) 886 // Since we bypassed the compiler's escape analysis, indicate that u 887 // must live until the use above. 888 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 889 return int64(length), err 890 } 891 892 // CheckedMarshal implements marshal.CheckedMarshallable.CheckedMarshal. 893 func (u *Uint16) CheckedMarshal(dst []byte) ([]byte, bool) { 894 size := u.SizeBytes() 895 if size > len(dst) { 896 return dst, false 897 } 898 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) 899 return dst[size:], true 900 } 901 902 // CheckedUnmarshal implements marshal.CheckedMarshallable.CheckedUnmarshal. 903 func (u *Uint16) CheckedUnmarshal(src []byte) ([]byte, bool) { 904 size := u.SizeBytes() 905 if size > len(src) { 906 return src, false 907 } 908 gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) 909 return src[size:], true 910 } 911 912 // CopyUint16SliceIn copies in a slice of uint16 objects from the task's memory. 913 //go:nosplit 914 func CopyUint16SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []uint16) (int, error) { 915 count := len(dst) 916 if count == 0 { 917 return 0, nil 918 } 919 size := (*Uint16)(nil).SizeBytes() 920 921 ptr := unsafe.Pointer(&dst) 922 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 923 924 // Construct a slice backed by dst's underlying memory. 925 var buf []byte 926 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 927 hdr.Data = uintptr(val) 928 hdr.Len = size * count 929 hdr.Cap = size * count 930 931 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 932 // Since we bypassed the compiler's escape analysis, indicate that dst 933 // must live until the use above. 934 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 935 return length, err 936 } 937 938 // CopyUint16SliceOut copies a slice of uint16 objects to the task's memory. 939 //go:nosplit 940 func CopyUint16SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []uint16) (int, error) { 941 count := len(src) 942 if count == 0 { 943 return 0, nil 944 } 945 size := (*Uint16)(nil).SizeBytes() 946 947 ptr := unsafe.Pointer(&src) 948 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 949 950 // Construct a slice backed by dst's underlying memory. 951 var buf []byte 952 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 953 hdr.Data = uintptr(val) 954 hdr.Len = size * count 955 hdr.Cap = size * count 956 957 length, err := cc.CopyOutBytes(addr, buf) // escapes: okay. 958 // Since we bypassed the compiler's escape analysis, indicate that src 959 // must live until the use above. 960 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 961 return length, err 962 } 963 964 // MarshalUnsafeUint16Slice is like Uint16.MarshalUnsafe, but for a []Uint16. 965 func MarshalUnsafeUint16Slice(src []Uint16, dst []byte) []byte { 966 count := len(src) 967 if count == 0 { 968 return dst 969 } 970 size := (*Uint16)(nil).SizeBytes() 971 972 buf := dst[:size*count] 973 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 974 return dst[size*count:] 975 } 976 977 // UnmarshalUnsafeUint16Slice is like Uint16.UnmarshalUnsafe, but for a []Uint16. 978 func UnmarshalUnsafeUint16Slice(dst []Uint16, src []byte) []byte { 979 count := len(dst) 980 if count == 0 { 981 return src 982 } 983 size := (*Uint16)(nil).SizeBytes() 984 985 buf := src[:size*count] 986 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 987 return src[size*count:] 988 } 989 990 // SizeBytes implements marshal.Marshallable.SizeBytes. 991 //go:nosplit 992 func (u *Uint32) SizeBytes() int { 993 return 4 994 } 995 996 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 997 func (u *Uint32) MarshalBytes(dst []byte) []byte { 998 hostarch.ByteOrder.PutUint32(dst[:4], uint32(*u)) 999 return dst[4:] 1000 } 1001 1002 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 1003 func (u *Uint32) UnmarshalBytes(src []byte) []byte { 1004 *u = Uint32(uint32(hostarch.ByteOrder.Uint32(src[:4]))) 1005 return src[4:] 1006 } 1007 1008 // Packed implements marshal.Marshallable.Packed. 1009 //go:nosplit 1010 func (u *Uint32) Packed() bool { 1011 // Scalar newtypes are always packed. 1012 return true 1013 } 1014 1015 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 1016 func (u *Uint32) MarshalUnsafe(dst []byte) []byte { 1017 size := u.SizeBytes() 1018 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) 1019 return dst[size:] 1020 } 1021 1022 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 1023 func (u *Uint32) UnmarshalUnsafe(src []byte) []byte { 1024 size := u.SizeBytes() 1025 gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) 1026 return src[size:] 1027 } 1028 1029 // CopyOutN implements marshal.Marshallable.CopyOutN. 1030 //go:nosplit 1031 func (u *Uint32) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 1032 // Construct a slice backed by dst's underlying memory. 1033 var buf []byte 1034 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1035 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 1036 hdr.Len = u.SizeBytes() 1037 hdr.Cap = u.SizeBytes() 1038 1039 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 1040 // Since we bypassed the compiler's escape analysis, indicate that u 1041 // must live until the use above. 1042 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 1043 return length, err 1044 } 1045 1046 // CopyOut implements marshal.Marshallable.CopyOut. 1047 //go:nosplit 1048 func (u *Uint32) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 1049 return u.CopyOutN(cc, addr, u.SizeBytes()) 1050 } 1051 1052 // CopyIn implements marshal.Marshallable.CopyIn. 1053 //go:nosplit 1054 func (u *Uint32) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 1055 // Construct a slice backed by dst's underlying memory. 1056 var buf []byte 1057 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1058 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 1059 hdr.Len = u.SizeBytes() 1060 hdr.Cap = u.SizeBytes() 1061 1062 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 1063 // Since we bypassed the compiler's escape analysis, indicate that u 1064 // must live until the use above. 1065 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 1066 return length, err 1067 } 1068 1069 // WriteTo implements io.WriterTo.WriteTo. 1070 func (u *Uint32) WriteTo(writer io.Writer) (int64, error) { 1071 // Construct a slice backed by dst's underlying memory. 1072 var buf []byte 1073 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1074 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 1075 hdr.Len = u.SizeBytes() 1076 hdr.Cap = u.SizeBytes() 1077 1078 length, err := writer.Write(buf) 1079 // Since we bypassed the compiler's escape analysis, indicate that u 1080 // must live until the use above. 1081 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 1082 return int64(length), err 1083 } 1084 1085 // CheckedMarshal implements marshal.CheckedMarshallable.CheckedMarshal. 1086 func (u *Uint32) CheckedMarshal(dst []byte) ([]byte, bool) { 1087 size := u.SizeBytes() 1088 if size > len(dst) { 1089 return dst, false 1090 } 1091 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) 1092 return dst[size:], true 1093 } 1094 1095 // CheckedUnmarshal implements marshal.CheckedMarshallable.CheckedUnmarshal. 1096 func (u *Uint32) CheckedUnmarshal(src []byte) ([]byte, bool) { 1097 size := u.SizeBytes() 1098 if size > len(src) { 1099 return src, false 1100 } 1101 gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) 1102 return src[size:], true 1103 } 1104 1105 // CopyUint32SliceIn copies in a slice of uint32 objects from the task's memory. 1106 //go:nosplit 1107 func CopyUint32SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []uint32) (int, error) { 1108 count := len(dst) 1109 if count == 0 { 1110 return 0, nil 1111 } 1112 size := (*Uint32)(nil).SizeBytes() 1113 1114 ptr := unsafe.Pointer(&dst) 1115 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 1116 1117 // Construct a slice backed by dst's underlying memory. 1118 var buf []byte 1119 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1120 hdr.Data = uintptr(val) 1121 hdr.Len = size * count 1122 hdr.Cap = size * count 1123 1124 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 1125 // Since we bypassed the compiler's escape analysis, indicate that dst 1126 // must live until the use above. 1127 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 1128 return length, err 1129 } 1130 1131 // CopyUint32SliceOut copies a slice of uint32 objects to the task's memory. 1132 //go:nosplit 1133 func CopyUint32SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []uint32) (int, error) { 1134 count := len(src) 1135 if count == 0 { 1136 return 0, nil 1137 } 1138 size := (*Uint32)(nil).SizeBytes() 1139 1140 ptr := unsafe.Pointer(&src) 1141 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 1142 1143 // Construct a slice backed by dst's underlying memory. 1144 var buf []byte 1145 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1146 hdr.Data = uintptr(val) 1147 hdr.Len = size * count 1148 hdr.Cap = size * count 1149 1150 length, err := cc.CopyOutBytes(addr, buf) // escapes: okay. 1151 // Since we bypassed the compiler's escape analysis, indicate that src 1152 // must live until the use above. 1153 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 1154 return length, err 1155 } 1156 1157 // MarshalUnsafeUint32Slice is like Uint32.MarshalUnsafe, but for a []Uint32. 1158 func MarshalUnsafeUint32Slice(src []Uint32, dst []byte) []byte { 1159 count := len(src) 1160 if count == 0 { 1161 return dst 1162 } 1163 size := (*Uint32)(nil).SizeBytes() 1164 1165 buf := dst[:size*count] 1166 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 1167 return dst[size*count:] 1168 } 1169 1170 // UnmarshalUnsafeUint32Slice is like Uint32.UnmarshalUnsafe, but for a []Uint32. 1171 func UnmarshalUnsafeUint32Slice(dst []Uint32, src []byte) []byte { 1172 count := len(dst) 1173 if count == 0 { 1174 return src 1175 } 1176 size := (*Uint32)(nil).SizeBytes() 1177 1178 buf := src[:size*count] 1179 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 1180 return src[size*count:] 1181 } 1182 1183 // SizeBytes implements marshal.Marshallable.SizeBytes. 1184 //go:nosplit 1185 func (u *Uint64) SizeBytes() int { 1186 return 8 1187 } 1188 1189 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 1190 func (u *Uint64) MarshalBytes(dst []byte) []byte { 1191 hostarch.ByteOrder.PutUint64(dst[:8], uint64(*u)) 1192 return dst[8:] 1193 } 1194 1195 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 1196 func (u *Uint64) UnmarshalBytes(src []byte) []byte { 1197 *u = Uint64(uint64(hostarch.ByteOrder.Uint64(src[:8]))) 1198 return src[8:] 1199 } 1200 1201 // Packed implements marshal.Marshallable.Packed. 1202 //go:nosplit 1203 func (u *Uint64) Packed() bool { 1204 // Scalar newtypes are always packed. 1205 return true 1206 } 1207 1208 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 1209 func (u *Uint64) MarshalUnsafe(dst []byte) []byte { 1210 size := u.SizeBytes() 1211 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) 1212 return dst[size:] 1213 } 1214 1215 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 1216 func (u *Uint64) UnmarshalUnsafe(src []byte) []byte { 1217 size := u.SizeBytes() 1218 gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) 1219 return src[size:] 1220 } 1221 1222 // CopyOutN implements marshal.Marshallable.CopyOutN. 1223 //go:nosplit 1224 func (u *Uint64) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 1225 // Construct a slice backed by dst's underlying memory. 1226 var buf []byte 1227 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1228 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 1229 hdr.Len = u.SizeBytes() 1230 hdr.Cap = u.SizeBytes() 1231 1232 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 1233 // Since we bypassed the compiler's escape analysis, indicate that u 1234 // must live until the use above. 1235 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 1236 return length, err 1237 } 1238 1239 // CopyOut implements marshal.Marshallable.CopyOut. 1240 //go:nosplit 1241 func (u *Uint64) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 1242 return u.CopyOutN(cc, addr, u.SizeBytes()) 1243 } 1244 1245 // CopyIn implements marshal.Marshallable.CopyIn. 1246 //go:nosplit 1247 func (u *Uint64) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 1248 // Construct a slice backed by dst's underlying memory. 1249 var buf []byte 1250 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1251 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 1252 hdr.Len = u.SizeBytes() 1253 hdr.Cap = u.SizeBytes() 1254 1255 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 1256 // Since we bypassed the compiler's escape analysis, indicate that u 1257 // must live until the use above. 1258 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 1259 return length, err 1260 } 1261 1262 // WriteTo implements io.WriterTo.WriteTo. 1263 func (u *Uint64) WriteTo(writer io.Writer) (int64, error) { 1264 // Construct a slice backed by dst's underlying memory. 1265 var buf []byte 1266 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1267 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 1268 hdr.Len = u.SizeBytes() 1269 hdr.Cap = u.SizeBytes() 1270 1271 length, err := writer.Write(buf) 1272 // Since we bypassed the compiler's escape analysis, indicate that u 1273 // must live until the use above. 1274 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 1275 return int64(length), err 1276 } 1277 1278 // CheckedMarshal implements marshal.CheckedMarshallable.CheckedMarshal. 1279 func (u *Uint64) CheckedMarshal(dst []byte) ([]byte, bool) { 1280 size := u.SizeBytes() 1281 if size > len(dst) { 1282 return dst, false 1283 } 1284 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) 1285 return dst[size:], true 1286 } 1287 1288 // CheckedUnmarshal implements marshal.CheckedMarshallable.CheckedUnmarshal. 1289 func (u *Uint64) CheckedUnmarshal(src []byte) ([]byte, bool) { 1290 size := u.SizeBytes() 1291 if size > len(src) { 1292 return src, false 1293 } 1294 gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) 1295 return src[size:], true 1296 } 1297 1298 // CopyUint64SliceIn copies in a slice of uint64 objects from the task's memory. 1299 //go:nosplit 1300 func CopyUint64SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []uint64) (int, error) { 1301 count := len(dst) 1302 if count == 0 { 1303 return 0, nil 1304 } 1305 size := (*Uint64)(nil).SizeBytes() 1306 1307 ptr := unsafe.Pointer(&dst) 1308 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 1309 1310 // Construct a slice backed by dst's underlying memory. 1311 var buf []byte 1312 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1313 hdr.Data = uintptr(val) 1314 hdr.Len = size * count 1315 hdr.Cap = size * count 1316 1317 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 1318 // Since we bypassed the compiler's escape analysis, indicate that dst 1319 // must live until the use above. 1320 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 1321 return length, err 1322 } 1323 1324 // CopyUint64SliceOut copies a slice of uint64 objects to the task's memory. 1325 //go:nosplit 1326 func CopyUint64SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []uint64) (int, error) { 1327 count := len(src) 1328 if count == 0 { 1329 return 0, nil 1330 } 1331 size := (*Uint64)(nil).SizeBytes() 1332 1333 ptr := unsafe.Pointer(&src) 1334 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 1335 1336 // Construct a slice backed by dst's underlying memory. 1337 var buf []byte 1338 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1339 hdr.Data = uintptr(val) 1340 hdr.Len = size * count 1341 hdr.Cap = size * count 1342 1343 length, err := cc.CopyOutBytes(addr, buf) // escapes: okay. 1344 // Since we bypassed the compiler's escape analysis, indicate that src 1345 // must live until the use above. 1346 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 1347 return length, err 1348 } 1349 1350 // MarshalUnsafeUint64Slice is like Uint64.MarshalUnsafe, but for a []Uint64. 1351 func MarshalUnsafeUint64Slice(src []Uint64, dst []byte) []byte { 1352 count := len(src) 1353 if count == 0 { 1354 return dst 1355 } 1356 size := (*Uint64)(nil).SizeBytes() 1357 1358 buf := dst[:size*count] 1359 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 1360 return dst[size*count:] 1361 } 1362 1363 // UnmarshalUnsafeUint64Slice is like Uint64.UnmarshalUnsafe, but for a []Uint64. 1364 func UnmarshalUnsafeUint64Slice(dst []Uint64, src []byte) []byte { 1365 count := len(dst) 1366 if count == 0 { 1367 return src 1368 } 1369 size := (*Uint64)(nil).SizeBytes() 1370 1371 buf := src[:size*count] 1372 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 1373 return src[size*count:] 1374 } 1375 1376 // SizeBytes implements marshal.Marshallable.SizeBytes. 1377 //go:nosplit 1378 func (u *Uint8) SizeBytes() int { 1379 return 1 1380 } 1381 1382 // MarshalBytes implements marshal.Marshallable.MarshalBytes. 1383 func (u *Uint8) MarshalBytes(dst []byte) []byte { 1384 dst[0] = byte(*u) 1385 return dst[1:] 1386 } 1387 1388 // UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. 1389 func (u *Uint8) UnmarshalBytes(src []byte) []byte { 1390 *u = Uint8(uint8(src[0])) 1391 return src[1:] 1392 } 1393 1394 // Packed implements marshal.Marshallable.Packed. 1395 //go:nosplit 1396 func (u *Uint8) Packed() bool { 1397 // Scalar newtypes are always packed. 1398 return true 1399 } 1400 1401 // MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe. 1402 func (u *Uint8) MarshalUnsafe(dst []byte) []byte { 1403 size := u.SizeBytes() 1404 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) 1405 return dst[size:] 1406 } 1407 1408 // UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe. 1409 func (u *Uint8) UnmarshalUnsafe(src []byte) []byte { 1410 size := u.SizeBytes() 1411 gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) 1412 return src[size:] 1413 } 1414 1415 // CopyOutN implements marshal.Marshallable.CopyOutN. 1416 //go:nosplit 1417 func (u *Uint8) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { 1418 // Construct a slice backed by dst's underlying memory. 1419 var buf []byte 1420 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1421 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 1422 hdr.Len = u.SizeBytes() 1423 hdr.Cap = u.SizeBytes() 1424 1425 length, err := cc.CopyOutBytes(addr, buf[:limit]) // escapes: okay. 1426 // Since we bypassed the compiler's escape analysis, indicate that u 1427 // must live until the use above. 1428 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 1429 return length, err 1430 } 1431 1432 // CopyOut implements marshal.Marshallable.CopyOut. 1433 //go:nosplit 1434 func (u *Uint8) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 1435 return u.CopyOutN(cc, addr, u.SizeBytes()) 1436 } 1437 1438 // CopyIn implements marshal.Marshallable.CopyIn. 1439 //go:nosplit 1440 func (u *Uint8) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { 1441 // Construct a slice backed by dst's underlying memory. 1442 var buf []byte 1443 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1444 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 1445 hdr.Len = u.SizeBytes() 1446 hdr.Cap = u.SizeBytes() 1447 1448 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 1449 // Since we bypassed the compiler's escape analysis, indicate that u 1450 // must live until the use above. 1451 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 1452 return length, err 1453 } 1454 1455 // WriteTo implements io.WriterTo.WriteTo. 1456 func (u *Uint8) WriteTo(writer io.Writer) (int64, error) { 1457 // Construct a slice backed by dst's underlying memory. 1458 var buf []byte 1459 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1460 hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) 1461 hdr.Len = u.SizeBytes() 1462 hdr.Cap = u.SizeBytes() 1463 1464 length, err := writer.Write(buf) 1465 // Since we bypassed the compiler's escape analysis, indicate that u 1466 // must live until the use above. 1467 runtime.KeepAlive(u) // escapes: replaced by intrinsic. 1468 return int64(length), err 1469 } 1470 1471 // CheckedMarshal implements marshal.CheckedMarshallable.CheckedMarshal. 1472 func (u *Uint8) CheckedMarshal(dst []byte) ([]byte, bool) { 1473 size := u.SizeBytes() 1474 if size > len(dst) { 1475 return dst, false 1476 } 1477 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) 1478 return dst[size:], true 1479 } 1480 1481 // CheckedUnmarshal implements marshal.CheckedMarshallable.CheckedUnmarshal. 1482 func (u *Uint8) CheckedUnmarshal(src []byte) ([]byte, bool) { 1483 size := u.SizeBytes() 1484 if size > len(src) { 1485 return src, false 1486 } 1487 gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) 1488 return src[size:], true 1489 } 1490 1491 // CopyUint8SliceIn copies in a slice of uint8 objects from the task's memory. 1492 //go:nosplit 1493 func CopyUint8SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []uint8) (int, error) { 1494 count := len(dst) 1495 if count == 0 { 1496 return 0, nil 1497 } 1498 size := (*Uint8)(nil).SizeBytes() 1499 1500 ptr := unsafe.Pointer(&dst) 1501 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 1502 1503 // Construct a slice backed by dst's underlying memory. 1504 var buf []byte 1505 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1506 hdr.Data = uintptr(val) 1507 hdr.Len = size * count 1508 hdr.Cap = size * count 1509 1510 length, err := cc.CopyInBytes(addr, buf) // escapes: okay. 1511 // Since we bypassed the compiler's escape analysis, indicate that dst 1512 // must live until the use above. 1513 runtime.KeepAlive(dst) // escapes: replaced by intrinsic. 1514 return length, err 1515 } 1516 1517 // CopyUint8SliceOut copies a slice of uint8 objects to the task's memory. 1518 //go:nosplit 1519 func CopyUint8SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []uint8) (int, error) { 1520 count := len(src) 1521 if count == 0 { 1522 return 0, nil 1523 } 1524 size := (*Uint8)(nil).SizeBytes() 1525 1526 ptr := unsafe.Pointer(&src) 1527 val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) 1528 1529 // Construct a slice backed by dst's underlying memory. 1530 var buf []byte 1531 hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) 1532 hdr.Data = uintptr(val) 1533 hdr.Len = size * count 1534 hdr.Cap = size * count 1535 1536 length, err := cc.CopyOutBytes(addr, buf) // escapes: okay. 1537 // Since we bypassed the compiler's escape analysis, indicate that src 1538 // must live until the use above. 1539 runtime.KeepAlive(src) // escapes: replaced by intrinsic. 1540 return length, err 1541 } 1542 1543 // MarshalUnsafeUint8Slice is like Uint8.MarshalUnsafe, but for a []Uint8. 1544 func MarshalUnsafeUint8Slice(src []Uint8, dst []byte) []byte { 1545 count := len(src) 1546 if count == 0 { 1547 return dst 1548 } 1549 size := (*Uint8)(nil).SizeBytes() 1550 1551 buf := dst[:size*count] 1552 gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) 1553 return dst[size*count:] 1554 } 1555 1556 // UnmarshalUnsafeUint8Slice is like Uint8.UnmarshalUnsafe, but for a []Uint8. 1557 func UnmarshalUnsafeUint8Slice(dst []Uint8, src []byte) []byte { 1558 count := len(dst) 1559 if count == 0 { 1560 return src 1561 } 1562 size := (*Uint8)(nil).SizeBytes() 1563 1564 buf := src[:size*count] 1565 gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) 1566 return src[size*count:] 1567 } 1568