Improve mxio Ioctl error handling
Change-Id: I42f2d6159541f460a3d242667ddaa81988a971bf
diff --git a/src/syscall/mx/mxio/rio/client.go b/src/syscall/mx/mxio/rio/client.go
index 5bbdd6f..564c751 100644
--- a/src/syscall/mx/mxio/rio/client.go
+++ b/src/syscall/mx/mxio/rio/client.go
@@ -349,7 +349,7 @@
switch mxio.IoctlKind(op) {
case mxio.IoctlKindGetHandle:
if msg.Hcount < 1 {
- return nil, nil
+ return nil, mx.Error{Status: mx.ErrIO, Text: "RemoteIO.Ioctl too few handles"}
}
outh := []mx.Handle{msg.Handle[0]}
msg.Handle[0] = 0
@@ -360,7 +360,8 @@
return outh, nil
case mxio.IoctlKindGetTwoHandles:
if msg.Hcount < 2 {
- return nil, nil
+ msg.DiscardHandles()
+ return nil, mx.Error{Status: mx.ErrIO, Text: "RemoteIO.Ioctl too few handles"}
}
outh := []mx.Handle{msg.Handle[0], msg.Handle[1]}
msg.Handle[0] = 0
@@ -372,7 +373,8 @@
return outh, nil
case mxio.IoctlKindGetThreeHandles:
if msg.Hcount < 3 {
- return nil, nil
+ msg.DiscardHandles()
+ return nil, mx.Error{Status: mx.ErrIO, Text: "RemoteIO.Ioctl too few handles"}
}
outh := []mx.Handle{msg.Handle[0], msg.Handle[1], msg.Handle[2]}
msg.Handle[0] = 0