mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Remove bytes read/written from marshal.Marshallable API.
Users of the API only care about whether the copy in/out succeeds in their entirety, which is already signalled by the returned error. PiperOrigin-RevId: 296297843
This commit is contained in:
committed by
Copybara-Service
parent
1bb0195079
commit
d90d71474f
@@ -304,7 +304,7 @@ func (t *Task) rseqAddrInterrupt() {
|
||||
}
|
||||
|
||||
var cs linux.RSeqCriticalSection
|
||||
if _, err := cs.CopyIn(t, critAddr); err != nil {
|
||||
if err := cs.CopyIn(t, critAddr); err != nil {
|
||||
t.Debugf("Failed to copy critical section from %#x for rseq: %v", critAddr, err)
|
||||
t.forceSignal(linux.SIGSEGV, false /* unconditional */)
|
||||
t.SendSignal(SignalInfoPriv(linux.SIGSEGV))
|
||||
|
||||
@@ -131,8 +131,7 @@ func stat(t *kernel.Task, d *fs.Dirent, dirPath bool, statAddr usermem.Addr) err
|
||||
return err
|
||||
}
|
||||
s := statFromAttrs(t, d.Inode.StableAttr, uattr)
|
||||
_, err = s.CopyOut(t, statAddr)
|
||||
return err
|
||||
return s.CopyOut(t, statAddr)
|
||||
}
|
||||
|
||||
// fstat implements fstat for the given *fs.File.
|
||||
@@ -142,8 +141,7 @@ func fstat(t *kernel.Task, f *fs.File, statAddr usermem.Addr) error {
|
||||
return err
|
||||
}
|
||||
s := statFromAttrs(t, f.Dirent.Inode.StableAttr, uattr)
|
||||
_, err = s.CopyOut(t, statAddr)
|
||||
return err
|
||||
return s.CopyOut(t, statAddr)
|
||||
}
|
||||
|
||||
// Statx implements linux syscall statx(2).
|
||||
|
||||
@@ -507,13 +507,14 @@ func (g *interfaceGenerator) emitMarshallable() {
|
||||
g.emit("// CopyOut implements marshal.Marshallable.CopyOut.\n")
|
||||
g.recordUsedImport("marshal")
|
||||
g.recordUsedImport("usermem")
|
||||
g.emit("func (%s *%s) CopyOut(task marshal.Task, addr usermem.Addr) (int, error) {\n", g.r, g.typeName())
|
||||
g.emit("func (%s *%s) CopyOut(task marshal.Task, addr usermem.Addr) error {\n", g.r, g.typeName())
|
||||
g.inIndent(func() {
|
||||
fallback := func() {
|
||||
g.emit("// Type %s doesn't have a packed layout in memory, fall back to MarshalBytes.\n", g.typeName())
|
||||
g.emit("buf := task.CopyScratchBuffer(%s.SizeBytes())\n", g.r)
|
||||
g.emit("%s.MarshalBytes(buf)\n", g.r)
|
||||
g.emit("return task.CopyOutBytes(addr, buf)\n")
|
||||
g.emit("_, err := task.CopyOutBytes(addr, buf)\n")
|
||||
g.emit("return err\n")
|
||||
}
|
||||
if thisPacked {
|
||||
g.recordUsedImport("reflect")
|
||||
@@ -539,11 +540,11 @@ func (g *interfaceGenerator) emitMarshallable() {
|
||||
g.emit("hdr.Len = %s.SizeBytes()\n", g.r)
|
||||
g.emit("hdr.Cap = %s.SizeBytes()\n\n", g.r)
|
||||
|
||||
g.emit("len, err := task.CopyOutBytes(addr, buf)\n")
|
||||
g.emit("_, err := task.CopyOutBytes(addr, buf)\n")
|
||||
g.emit("// Since we bypassed the compiler's escape analysis, indicate that %s\n", g.r)
|
||||
g.emit("// must live until after the CopyOutBytes.\n")
|
||||
g.emit("runtime.KeepAlive(%s)\n", g.r)
|
||||
g.emit("return len, err\n")
|
||||
g.emit("return err\n")
|
||||
} else {
|
||||
fallback()
|
||||
}
|
||||
@@ -553,20 +554,20 @@ func (g *interfaceGenerator) emitMarshallable() {
|
||||
g.emit("// CopyIn implements marshal.Marshallable.CopyIn.\n")
|
||||
g.recordUsedImport("marshal")
|
||||
g.recordUsedImport("usermem")
|
||||
g.emit("func (%s *%s) CopyIn(task marshal.Task, addr usermem.Addr) (int, error) {\n", g.r, g.typeName())
|
||||
g.emit("func (%s *%s) CopyIn(task marshal.Task, addr usermem.Addr) error {\n", g.r, g.typeName())
|
||||
g.inIndent(func() {
|
||||
fallback := func() {
|
||||
g.emit("// Type %s doesn't have a packed layout in memory, fall back to UnmarshalBytes.\n", g.typeName())
|
||||
g.emit("buf := task.CopyScratchBuffer(%s.SizeBytes())\n", g.r)
|
||||
g.emit("n, err := task.CopyInBytes(addr, buf)\n")
|
||||
g.emit("_, err := task.CopyInBytes(addr, buf)\n")
|
||||
g.emit("if err != nil {\n")
|
||||
g.inIndent(func() {
|
||||
g.emit("return n, err\n")
|
||||
g.emit("return err\n")
|
||||
})
|
||||
g.emit("}\n")
|
||||
|
||||
g.emit("%s.UnmarshalBytes(buf)\n", g.r)
|
||||
g.emit("return n, nil\n")
|
||||
g.emit("return nil\n")
|
||||
}
|
||||
if thisPacked {
|
||||
g.recordUsedImport("reflect")
|
||||
@@ -592,11 +593,11 @@ func (g *interfaceGenerator) emitMarshallable() {
|
||||
g.emit("hdr.Len = %s.SizeBytes()\n", g.r)
|
||||
g.emit("hdr.Cap = %s.SizeBytes()\n\n", g.r)
|
||||
|
||||
g.emit("len, err := task.CopyInBytes(addr, buf)\n")
|
||||
g.emit("_, err := task.CopyInBytes(addr, buf)\n")
|
||||
g.emit("// Since we bypassed the compiler's escape analysis, indicate that %s\n", g.r)
|
||||
g.emit("// must live until after the CopyInBytes.\n")
|
||||
g.emit("runtime.KeepAlive(%s)\n", g.r)
|
||||
g.emit("return len, err\n")
|
||||
g.emit("return err\n")
|
||||
} else {
|
||||
fallback()
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func (g *testGenerator) emitTestNonZeroSize() {
|
||||
g.emit("x := &%s{}\n", g.typeName())
|
||||
g.emit("if x.SizeBytes() == 0 {\n")
|
||||
g.inIndent(func() {
|
||||
g.emit("t.Fatal(\"Marshallable.Size() should not return zero\")\n")
|
||||
g.emit("t.Fatal(\"Marshallable.SizeBytes() should not return zero\")\n")
|
||||
})
|
||||
g.emit("}\n")
|
||||
})
|
||||
|
||||
@@ -91,12 +91,12 @@ type Marshallable interface {
|
||||
// marshalled does not escape. The implementation should avoid creating
|
||||
// extra copies in memory by directly deserializing to the object's
|
||||
// underlying memory.
|
||||
CopyIn(task Task, addr usermem.Addr) (int, error)
|
||||
CopyIn(task Task, addr usermem.Addr) error
|
||||
|
||||
// CopyOut serializes a Marshallable type to a task's memory. This may only
|
||||
// be called from a task goroutine. This is more efficient than calling
|
||||
// MarshalUnsafe on Marshallable.Packed types, as the type being serialized
|
||||
// does not escape. The implementation should avoid creating extra copies in
|
||||
// memory by directly serializing from the object's underlying memory.
|
||||
CopyOut(task Task, addr usermem.Addr) (int, error)
|
||||
CopyOut(task Task, addr usermem.Addr) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user