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