aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encodingexec.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-10-12 19:08:18 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-10-12 19:08:18 +0200
commit66aeb467de80c92a099e49eaad6c25974c96f9cf (patch)
treecde1ee4dca1033104b2b858007c4cd2d5e0b5d12 /prog/encodingexec.go
parent81e199f71969b97c80cbb4473ddd53adeed3b4d4 (diff)
pkg/ipc: don't send program padding to executor
Currently we always send 2MB of data to executor in ipc_simple.go. Send only what's consumed by the program, and don't send the trailing zeros. Serialized programs usually take only few KBs.
Diffstat (limited to 'prog/encodingexec.go')
-rw-r--r--prog/encodingexec.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/prog/encodingexec.go b/prog/encodingexec.go
index b2b173bbe..e45ba1192 100644
--- a/prog/encodingexec.go
+++ b/prog/encodingexec.go
@@ -57,8 +57,9 @@ func (s ByPhysicalAddr) Less(i, j int) bool {
}
// SerializeForExec serializes program p for execution by process pid into the provided buffer.
+// Returns number of bytes written to the buffer.
// If the provided buffer is too small for the program an error is returned.
-func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
+func (p *Prog) SerializeForExec(buffer []byte, pid int) (int, error) {
if debug {
if err := p.validate(); err != nil {
panic(fmt.Errorf("serializing invalid program: %v", err))
@@ -193,9 +194,9 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
}
w.write(ExecInstrEOF)
if w.eof {
- return fmt.Errorf("provided buffer is too small")
+ return 0, fmt.Errorf("provided buffer is too small")
}
- return nil
+ return len(buffer) - len(w.buf), nil
}
func (target *Target) physicalAddr(arg Arg) uint64 {