diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-02-15 02:35:05 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-02-15 02:35:05 +0000 |
commit | 154d861542a4f64cfe49e2671f2c8c8c668bca99 (patch) | |
tree | 2951d2cb92323f6e7408270a0eade94470f142ed /pkg/abi/linux/linux_abi_autogen_unsafe.go | |
parent | 018771a9909fb8c35f179c48d836484571570841 (diff) | |
parent | 3d32ad1367b4e84a0822808f44bd7b9f9351db71 (diff) |
Merge release-20200211.0-26-g3d32ad1 (automated)
Diffstat (limited to 'pkg/abi/linux/linux_abi_autogen_unsafe.go')
-rwxr-xr-x | pkg/abi/linux/linux_abi_autogen_unsafe.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pkg/abi/linux/linux_abi_autogen_unsafe.go b/pkg/abi/linux/linux_abi_autogen_unsafe.go index d8d4cb088..73853a078 100755 --- a/pkg/abi/linux/linux_abi_autogen_unsafe.go +++ b/pkg/abi/linux/linux_abi_autogen_unsafe.go @@ -6,6 +6,7 @@ import ( "gvisor.dev/gvisor/pkg/safecopy" "gvisor.dev/gvisor/pkg/usermem" "gvisor.dev/gvisor/tools/go_marshal/marshal" + "io" "reflect" "runtime" "unsafe" @@ -109,6 +110,29 @@ func (r *RSeqCriticalSection) CopyIn(task marshal.Task, addr usermem.Addr) (int, return len, err } +// WriteTo implements io.WriterTo.WriteTo. +func (r *RSeqCriticalSection) WriteTo(w io.Writer) (int64, error) { + // Bypass escape analysis on r. The no-op arithmetic operation on the + // pointer makes the compiler think val doesn't depend on r. + // See src/runtime/stubs.go:noescape() in the golang toolchain. + ptr := unsafe.Pointer(r) + val := uintptr(ptr) + val = val^0 + + // Construct a slice backed by r's underlying memory. + var buf []byte + hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) + hdr.Data = val + hdr.Len = r.SizeBytes() + hdr.Cap = r.SizeBytes() + + len, err := w.Write(buf) + // Since we bypassed the compiler's escape analysis, indicate that r + // must live until after the Write. + runtime.KeepAlive(r) + return int64(len), err +} + // SizeBytes implements marshal.Marshallable.SizeBytes. func (t *Timespec) SizeBytes() int { return 16 @@ -191,3 +215,26 @@ func (t *Timespec) CopyIn(task marshal.Task, addr usermem.Addr) (int, error) { return len, err } +// WriteTo implements io.WriterTo.WriteTo. +func (t *Timespec) WriteTo(w io.Writer) (int64, error) { + // Bypass escape analysis on t. The no-op arithmetic operation on the + // pointer makes the compiler think val doesn't depend on t. + // See src/runtime/stubs.go:noescape() in the golang toolchain. + ptr := unsafe.Pointer(t) + val := uintptr(ptr) + val = val^0 + + // Construct a slice backed by t's underlying memory. + var buf []byte + hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) + hdr.Data = val + hdr.Len = t.SizeBytes() + hdr.Cap = t.SizeBytes() + + len, err := w.Write(buf) + // Since we bypassed the compiler's escape analysis, indicate that t + // must live until after the Write. + runtime.KeepAlive(t) + return int64(len), err +} + |