Sync with Fuchsia (#741)

* Rename Magenta to Zircon
* Update package dependencies to zircon
* Use zircon's status-to-error conversion
* Bump fuchsia-zircon version
diff --git a/Cargo.toml b/Cargo.toml
index 258dc34..d136824 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,8 +29,8 @@
 iovec    = "0.1.0"
 
 [target.'cfg(target_os = "fuchsia")'.dependencies]
-magenta = "0.2.0"
-magenta-sys = "0.2.0"
+fuchsia-zircon = "0.2.1"
+fuchsia-zircon-sys = "0.2.0"
 
 [target.'cfg(unix)'.dependencies]
 libc   = "0.2.19"
diff --git a/src/lib.rs b/src/lib.rs
index 4858b45..beac3a9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -85,9 +85,9 @@
 extern crate iovec;
 
 #[cfg(target_os = "fuchsia")]
-extern crate magenta;
+extern crate fuchsia_zircon as zircon;
 #[cfg(target_os = "fuchsia")]
-extern crate magenta_sys;
+extern crate fuchsia_zircon_sys as zircon_sys;
 
 #[cfg(unix)]
 extern crate libc;
@@ -203,7 +203,7 @@
     pub use sys::{
         EventedHandle,
     };
-    pub use sys::fuchsia::{FuchsiaReady, mx_signals_t};
+    pub use sys::fuchsia::{FuchsiaReady, zx_signals_t};
 }
 
 /// Windows-only extensions to the mio crate.
diff --git a/src/sys/fuchsia/awakener.rs b/src/sys/fuchsia/awakener.rs
index 553e373..19bc762 100644
--- a/src/sys/fuchsia/awakener.rs
+++ b/src/sys/fuchsia/awakener.rs
@@ -1,13 +1,12 @@
 use {io, poll, Evented, Ready, Poll, PollOpt, Token};
-use sys::fuchsia::status_to_io_err;
-use magenta;
+use zircon;
 use std::sync::{Arc, Mutex, Weak};
 
 pub struct Awakener {
     /// Token and weak reference to the port on which Awakener was registered.
     ///
     /// When `Awakener::wakeup` is called, these are used to send a wakeup message to the port.
-    inner: Mutex<Option<(Token, Weak<magenta::Port>)>>,
+    inner: Mutex<Option<(Token, Weak<zircon::Port>)>>,
 }
 
 impl Awakener {
@@ -27,10 +26,10 @@
         let port = weak_port.upgrade().expect("Tried to wakeup a closed port.");
 
         let status = 0; // arbitrary
-        let packet = magenta::Packet::from_user_packet(
-            token.0 as u64, status, magenta::UserPacket::from_u8_array([0; 32]));
+        let packet = zircon::Packet::from_user_packet(
+            token.0 as u64, status, zircon::UserPacket::from_u8_array([0; 32]));
 
-        port.queue(&packet).map_err(status_to_io_err)
+        Ok(port.queue(&packet)?)
     }
 
     pub fn cleanup(&self) {}
diff --git a/src/sys/fuchsia/eventedfd.rs b/src/sys/fuchsia/eventedfd.rs
index e337666..641fc18 100644
--- a/src/sys/fuchsia/eventedfd.rs
+++ b/src/sys/fuchsia/eventedfd.rs
@@ -1,7 +1,7 @@
 use {io, poll, Evented, Ready, Poll, PollOpt, Token};
 use libc;
-use magenta;
-use magenta::AsHandleRef;
+use zircon;
+use zircon::AsHandleRef;
 use sys::fuchsia::{DontDrop, poll_opts_to_wait_async, sys};
 use std::mem;
 use std::os::unix::io::RawFd;
@@ -11,24 +11,24 @@
 #[derive(Debug)]
 pub struct EventedFdRegistration {
     token: Token,
-    handle: DontDrop<magenta::Handle>,
-    rereg_signals: Option<(magenta::Signals, magenta::WaitAsyncOpts)>,
+    handle: DontDrop<zircon::Handle>,
+    rereg_signals: Option<(zircon::Signals, zircon::WaitAsyncOpts)>,
 }
 
 impl EventedFdRegistration {
     unsafe fn new(token: Token,
-                  raw_handle: sys::mx_handle_t,
-                  rereg_signals: Option<(magenta::Signals, magenta::WaitAsyncOpts)>,
+                  raw_handle: sys::zx_handle_t,
+                  rereg_signals: Option<(zircon::Signals, zircon::WaitAsyncOpts)>,
                   ) -> Self
     {
         EventedFdRegistration {
             token: token,
-            handle: DontDrop::new(magenta::Handle::from_raw(raw_handle)),
+            handle: DontDrop::new(zircon::Handle::from_raw(raw_handle)),
             rereg_signals: rereg_signals
         }
     }
 
-    pub fn rereg_signals(&self) -> Option<(magenta::Signals, magenta::WaitAsyncOpts)> {
+    pub fn rereg_signals(&self) -> Option<(zircon::Signals, zircon::WaitAsyncOpts)> {
         self.rereg_signals
     }
 }
@@ -44,12 +44,12 @@
     /// `fd` is closed on `Drop`, so modifying `fd` is a memory-unsafe operation.
     fd: RawFd,
 
-    /// Owned `mxio_t` ponter.
-    mxio: *const sys::mxio_t,
+    /// Owned `fdio_t` ponter.
+    fdio: *const sys::fdio_t,
 }
 
 impl EventedFdInner {
-    pub fn rereg_for_level(&self, port: &magenta::Port) {
+    pub fn rereg_for_level(&self, port: &zircon::Port) {
         let registration_opt = self.registration.lock().unwrap();
         if let Some(ref registration) = *registration_opt {
             if let Some((rereg_signals, rereg_opts)) = registration.rereg_signals {
@@ -69,25 +69,25 @@
         &self.registration
     }
 
-    pub fn mxio(&self) -> &sys::mxio_t {
-        unsafe { &*self.mxio }
+    pub fn fdio(&self) -> &sys::fdio_t {
+        unsafe { &*self.fdio }
     }
 }
 
 impl Drop for EventedFdInner {
     fn drop(&mut self) {
         unsafe {
-            sys::__mxio_release(self.mxio);
+            sys::__fdio_release(self.fdio);
             let _ = libc::close(self.fd);
         }
     }
 }
 
 // `EventedInner` must be manually declared `Send + Sync` because it contains a `RawFd` and a
-// `*const sys::mxio_t`. These are only used to make thread-safe system calls, so accessing
+// `*const sys::fdio_t`. These are only used to make thread-safe system calls, so accessing
 // them is entirely thread-safe.
 //
-// Note: one minor exception to this are the calls to `libc::close` and `__mxio_release`, which
+// Note: one minor exception to this are the calls to `libc::close` and `__fdio_release`, which
 // happen on `Drop`. These accesses are safe because `drop` can only be called at most once from
 // a single thread, and after it is called no other functions can be called on the `EventedFdInner`.
 unsafe impl Sync for EventedFdInner {}
@@ -100,27 +100,27 @@
 
 impl EventedFd {
     pub unsafe fn new(fd: RawFd) -> Self {
-        let mxio = sys::__mxio_fd_to_io(fd);
-        assert!(mxio != ::std::ptr::null(), "FileDescriptor given to EventedFd must be valid.");
+        let fdio = sys::__fdio_fd_to_io(fd);
+        assert!(fdio != ::std::ptr::null(), "FileDescriptor given to EventedFd must be valid.");
 
         EventedFd {
             inner: Arc::new(EventedFdInner {
                 registration: Mutex::new(None),
                 fd: fd,
-                mxio: mxio,
+                fdio: fdio,
             })
         }
     }
 
     fn handle_and_signals_for_events(&self, interest: Ready, opts: PollOpt)
-                -> (sys::mx_handle_t, magenta::Signals)
+                -> (sys::zx_handle_t, zircon::Signals)
     {
         let epoll_events = ioevent_to_epoll(interest, opts);
 
         unsafe {
-            let mut raw_handle: sys::mx_handle_t = mem::uninitialized();
-            let mut signals: sys::mx_signals_t = mem::uninitialized();
-            sys::__mxio_wait_begin(self.inner.mxio, epoll_events, &mut raw_handle, &mut signals);
+            let mut raw_handle: sys::zx_handle_t = mem::uninitialized();
+            let mut signals: sys::zx_signals_t = mem::uninitialized();
+            sys::__fdio_wait_begin(self.inner.fdio, epoll_events, &mut raw_handle, &mut signals);
 
             (raw_handle, signals)
         }
@@ -158,7 +158,7 @@
         );
 
         // We don't have ownership of the handle, so we can't drop it
-        let handle = DontDrop::new(unsafe { magenta::Handle::from_raw(raw_handle) });
+        let handle = DontDrop::new(unsafe { zircon::Handle::from_raw(raw_handle) });
 
         let registered = poll::selector(poll)
             .register_fd(handle.inner_ref(), self, token, signals, opts);
diff --git a/src/sys/fuchsia/handles.rs b/src/sys/fuchsia/handles.rs
index 269e272..ae6f07f 100644
--- a/src/sys/fuchsia/handles.rs
+++ b/src/sys/fuchsia/handles.rs
@@ -1,12 +1,12 @@
 use {io, poll, Evented, Ready, Poll, PollOpt, Token};
-use magenta_sys::mx_handle_t;
+use zircon_sys::zx_handle_t;
 use std::sync::Mutex;
 
 /// Wrapper for registering a `HandleBase` type with mio.
 #[derive(Debug)]
 pub struct EventedHandle {
     /// The handle to be registered.
-    handle: mx_handle_t,
+    handle: zx_handle_t,
 
     /// The current `Token` with which the handle is registered with mio.
     token: Mutex<Option<Token>>,
@@ -18,7 +18,7 @@
     ///
     /// The underlying handle must not be dropped while the
     /// `EventedHandle` still exists.
-    pub unsafe fn new(handle: mx_handle_t) -> Self {
+    pub unsafe fn new(handle: zx_handle_t) -> Self {
         EventedHandle {
             handle: handle,
             token: Mutex::new(None),
@@ -26,7 +26,7 @@
     }
 
     /// Get the underlying handle being registered.
-    pub fn get_handle(&self) -> mx_handle_t {
+    pub fn get_handle(&self) -> zx_handle_t {
         self.handle
     }
 }
diff --git a/src/sys/fuchsia/mod.rs b/src/sys/fuchsia/mod.rs
index 5e6b639..10728fc 100644
--- a/src/sys/fuchsia/mod.rs
+++ b/src/sys/fuchsia/mod.rs
@@ -1,6 +1,6 @@
 use {io, Ready, PollOpt};
 use libc;
-use magenta;
+use zircon;
 use std::mem;
 use std::net::{IpAddr, Ipv4Addr, SocketAddr};
 use std::ops::{Deref, DerefMut};
@@ -20,7 +20,7 @@
 pub use self::handles::EventedHandle;
 pub use self::net::{TcpListener, TcpStream, UdpSocket};
 pub use self::selector::{Events, Selector};
-pub use self::ready::{FuchsiaReady, mx_signals_t};
+pub use self::ready::{FuchsiaReady, zx_signals_t};
 
 // Set non-blocking (workaround since the std version doesn't work in fuchsia)
 // TODO: fix the std version and replace this
@@ -47,92 +47,41 @@
 mod sys {
     #![allow(non_camel_case_types)]
     use std::os::unix::io::RawFd;
-    pub use magenta_sys::{mx_handle_t, mx_signals_t};
+    pub use zircon_sys::{zx_handle_t, zx_signals_t};
 
     // 17 fn pointers we don't need for mio :)
-    pub type mxio_ops_t = [usize; 17];
+    pub type fdio_ops_t = [usize; 17];
 
     pub type atomic_int_fast32_t = usize; // TODO: https://github.com/rust-lang/libc/issues/631
 
     #[repr(C)]
-    pub struct mxio_t {
-        pub ops: *const mxio_ops_t,
+    pub struct fdio_t {
+        pub ops: *const fdio_ops_t,
         pub magic: u32,
         pub refcount: atomic_int_fast32_t,
         pub dupcount: u32,
         pub flags: u32,
     }
 
-    #[link(name="mxio")]
+    #[link(name="fdio")]
     extern {
-        pub fn __mxio_fd_to_io(fd: RawFd) -> *const mxio_t;
-        pub fn __mxio_release(io: *const mxio_t);
+        pub fn __fdio_fd_to_io(fd: RawFd) -> *const fdio_t;
+        pub fn __fdio_release(io: *const fdio_t);
 
-        pub fn __mxio_wait_begin(
-            io: *const mxio_t,
+        pub fn __fdio_wait_begin(
+            io: *const fdio_t,
             events: u32,
-            handle_out: &mut mx_handle_t,
-            signals_out: &mut mx_signals_t,
+            handle_out: &mut zx_handle_t,
+            signals_out: &mut zx_signals_t,
         );
-        pub fn __mxio_wait_end(
-            io: *const mxio_t,
-            signals: mx_signals_t,
+        pub fn __fdio_wait_end(
+            io: *const fdio_t,
+            signals: zx_signals_t,
             events_out: &mut u32,
         );
     }
 }
 
-/// Convert from magenta::Status to io::Error.
-///
-/// Note: these conversions are done on a "best-effort" basis and may not necessarily reflect
-/// exactly equivalent error types.
-fn status_to_io_err(status: magenta::Status) -> io::Error {
-    use magenta::Status;
-
-    let err_kind: io::ErrorKind = match status {
-        Status::ErrInterruptedRetry => io::ErrorKind::Interrupted,
-        Status::ErrBadHandle => io::ErrorKind::BrokenPipe,
-        Status::ErrTimedOut => io::ErrorKind::TimedOut,
-        Status::ErrShouldWait => io::ErrorKind::WouldBlock,
-        Status::ErrPeerClosed => io::ErrorKind::ConnectionAborted,
-        Status::ErrNotFound => io::ErrorKind::NotFound,
-        Status::ErrAlreadyExists => io::ErrorKind::AlreadyExists,
-        Status::ErrAlreadyBound => io::ErrorKind::AddrInUse,
-        Status::ErrUnavailable => io::ErrorKind::AddrNotAvailable,
-        Status::ErrAccessDenied => io::ErrorKind::PermissionDenied,
-        Status::ErrIoRefused => io::ErrorKind::ConnectionRefused,
-        Status::ErrIoDataIntegrity => io::ErrorKind::InvalidData,
-
-        Status::ErrBadPath |
-        Status::ErrInvalidArgs |
-        Status::ErrOutOfRange |
-        Status::ErrWrongType => io::ErrorKind::InvalidInput,
-
-        Status::UnknownOther |
-        Status::ErrNext |
-        Status::ErrStop |
-        Status::ErrNoSpace |
-        Status::ErrFileBig |
-        Status::ErrNotFile |
-        Status::ErrNotDir |
-        Status::ErrIoDataLoss |
-        Status::ErrIo |
-        Status::ErrCanceled |
-        Status::ErrBadState |
-        Status::ErrBufferTooSmall |
-        Status::ErrBadSyscall |
-        Status::NoError |
-        Status::ErrInternal |
-        Status::ErrNotSupported |
-        Status::ErrNoResources |
-        Status::ErrNoMemory |
-        Status::ErrCallFailed
-        => io::ErrorKind::Other
-    }.into();
-
-    err_kind.into()
-}
-
 fn epoll_event_to_ready(epoll: u32) -> Ready {
     let epoll = epoll as i32; // casts the bits directly
     let mut kind = Ready::empty();
@@ -159,11 +108,11 @@
     */
 }
 
-fn poll_opts_to_wait_async(poll_opts: PollOpt) -> magenta::WaitAsyncOpts {
+fn poll_opts_to_wait_async(poll_opts: PollOpt) -> zircon::WaitAsyncOpts {
     if poll_opts.is_oneshot() {
-        magenta::WaitAsyncOpts::Once
+        zircon::WaitAsyncOpts::Once
     } else {
-        magenta::WaitAsyncOpts::Repeating
+        zircon::WaitAsyncOpts::Repeating
     }
 }
 
diff --git a/src/sys/fuchsia/ready.rs b/src/sys/fuchsia/ready.rs
index 05126d3..97854f8 100644
--- a/src/sys/fuchsia/ready.rs
+++ b/src/sys/fuchsia/ready.rs
@@ -1,8 +1,8 @@
 use event_imp::{Ready, ready_as_usize, ready_from_usize};
-pub use magenta_sys::{
-    mx_signals_t,
-    MX_OBJECT_READABLE,
-    MX_OBJECT_WRITABLE,
+pub use zircon_sys::{
+    zx_signals_t,
+    ZX_OBJECT_READABLE,
+    ZX_OBJECT_WRITABLE,
 };
 use std::ops;
 
@@ -14,12 +14,12 @@
 #[inline]
 pub fn assert_fuchsia_ready_repr() {
     debug_assert!(
-        MX_OBJECT_READABLE.bits() as usize == ready_as_usize(Ready::readable()),
-        "Magenta MX_OBJECT_READABLE should have the same repr as Ready::readable()"
+        ZX_OBJECT_READABLE.bits() as usize == ready_as_usize(Ready::readable()),
+        "Zircon ZX_OBJECT_READABLE should have the same repr as Ready::readable()"
     );
     debug_assert!(
-        MX_OBJECT_WRITABLE.bits() as usize == ready_as_usize(Ready::writable()),
-        "Magenta MX_OBJECT_WRITABLE should have the same repr as Ready::writable()"
+        ZX_OBJECT_WRITABLE.bits() as usize == ready_as_usize(Ready::writable()),
+        "Zircon ZX_OBJECT_WRITABLE should have the same repr as Ready::writable()"
     );
 }
 
@@ -36,32 +36,32 @@
 pub struct FuchsiaReady(Ready);
 
 impl FuchsiaReady {
-    /// Returns the `FuchsiaReady` as raw magenta signals.
+    /// Returns the `FuchsiaReady` as raw zircon signals.
     /// This function is just a more explicit, non-generic version of
     /// `FuchsiaReady::into`.
     #[inline]
-    pub fn into_mx_signals(self) -> mx_signals_t {
-        mx_signals_t::from_bits_truncate(ready_as_usize(self.0) as u32)
+    pub fn into_zx_signals(self) -> zx_signals_t {
+        zx_signals_t::from_bits_truncate(ready_as_usize(self.0) as u32)
     }
 }
 
-impl Into<mx_signals_t> for FuchsiaReady {
+impl Into<zx_signals_t> for FuchsiaReady {
     #[inline]
-    fn into(self) -> mx_signals_t {
-        self.into_mx_signals()
+    fn into(self) -> zx_signals_t {
+        self.into_zx_signals()
     }
 }
 
-impl From<mx_signals_t> for FuchsiaReady {
+impl From<zx_signals_t> for FuchsiaReady {
     #[inline]
-    fn from(src: mx_signals_t) -> Self {
+    fn from(src: zx_signals_t) -> Self {
         FuchsiaReady(src.into())
     }
 }
 
-impl From<mx_signals_t> for Ready {
+impl From<zx_signals_t> for Ready {
     #[inline]
-    fn from(src: mx_signals_t) -> Self {
+    fn from(src: zx_signals_t) -> Self {
         ready_from_usize(src.bits() as usize)
     }
 }
@@ -144,38 +144,38 @@
     }
 }
 
-impl ops::BitOr<mx_signals_t> for FuchsiaReady {
+impl ops::BitOr<zx_signals_t> for FuchsiaReady {
     type Output = FuchsiaReady;
 
     #[inline]
-    fn bitor(self, other: mx_signals_t) -> FuchsiaReady {
+    fn bitor(self, other: zx_signals_t) -> FuchsiaReady {
         self | FuchsiaReady::from(other)
     }
 }
 
-impl ops::BitXor<mx_signals_t> for FuchsiaReady {
+impl ops::BitXor<zx_signals_t> for FuchsiaReady {
     type Output = FuchsiaReady;
 
     #[inline]
-    fn bitxor(self, other: mx_signals_t) -> FuchsiaReady {
+    fn bitxor(self, other: zx_signals_t) -> FuchsiaReady {
         self ^ FuchsiaReady::from(other)
     }
 }
 
-impl ops::BitAnd<mx_signals_t> for FuchsiaReady {
+impl ops::BitAnd<zx_signals_t> for FuchsiaReady {
     type Output = FuchsiaReady;
 
     #[inline]
-    fn bitand(self, other: mx_signals_t) -> FuchsiaReady {
+    fn bitand(self, other: zx_signals_t) -> FuchsiaReady {
         self & FuchsiaReady::from(other)
     }
 }
 
-impl ops::Sub<mx_signals_t> for FuchsiaReady {
+impl ops::Sub<zx_signals_t> for FuchsiaReady {
     type Output = FuchsiaReady;
 
     #[inline]
-    fn sub(self, other: mx_signals_t) -> FuchsiaReady {
+    fn sub(self, other: zx_signals_t) -> FuchsiaReady {
         self - FuchsiaReady::from(other)
     }
 }
diff --git a/src/sys/fuchsia/selector.rs b/src/sys/fuchsia/selector.rs
index caba672..f15c8eb 100644
--- a/src/sys/fuchsia/selector.rs
+++ b/src/sys/fuchsia/selector.rs
@@ -3,14 +3,13 @@
     assert_fuchsia_ready_repr,
     epoll_event_to_ready,
     poll_opts_to_wait_async,
-    status_to_io_err,
     EventedFd,
     EventedFdInner,
     FuchsiaReady,
 };
-use magenta;
-use magenta::AsHandleRef;
-use magenta_sys::mx_handle_t;
+use zircon;
+use zircon::AsHandleRef;
+use zircon_sys::zx_handle_t;
 use std::collections::hash_map;
 use std::fmt;
 use std::mem;
@@ -65,8 +64,8 @@
 pub struct Selector {
     id: usize,
 
-    /// Magenta object on which the handles have been registered, and on which events occur
-    port: Arc<magenta::Port>,
+    /// Zircon object on which the handles have been registered, and on which events occur
+    port: Arc<zircon::Port>,
 
     /// Whether or not `tokens_to_rereg` contains any elements. This is a best-effort attempt
     /// used to prevent having to lock `tokens_to_rereg` when it is empty.
@@ -85,7 +84,7 @@
     tokens_to_rereg: Mutex<Vec<Token>>,
 
     /// Map from tokens to weak references to `EventedFdInner`-- a structure describing a
-    /// file handle, its associated `mxio` object, and its current registration.
+    /// file handle, its associated `fdio` object, and its current registration.
     token_to_fd: Mutex<hash_map::HashMap<Token, Weak<EventedFdInner>>>,
 }
 
@@ -96,8 +95,7 @@
         assert_fuchsia_ready_repr();
 
         let port = Arc::new(
-            magenta::Port::create(magenta::PortOpts::Default)
-                .map_err(status_to_io_err)?
+            zircon::Port::create(zircon::PortOpts::Default)?
         );
 
         // offset by 1 to avoid choosing 0 as the id of a selector
@@ -121,7 +119,7 @@
     }
 
     /// Returns a reference to the underlying port `Arc`.
-    pub fn port(&self) -> &Arc<magenta::Port> { &self.port }
+    pub fn port(&self) -> &Arc<zircon::Port> { &self.port }
 
     /// Reregisters all registrations pointed to by the `tokens_to_rereg` list
     /// if `has_tokens_to_rereg`.
@@ -156,25 +154,25 @@
                 let nanos = duration.as_secs().saturating_mul(1_000_000_000)
                                 .saturating_add(duration.subsec_nanos() as u64);
 
-                magenta::deadline_after(nanos)
+                zircon::deadline_after(nanos)
             }
-            None => magenta::MX_TIME_INFINITE,
+            None => zircon::ZX_TIME_INFINITE,
         };
 
         let packet = match self.port.wait(deadline) {
             Ok(packet) => packet,
-            Err(magenta::Status::ErrTimedOut) => return Ok(false),
-            Err(e) => return Err(status_to_io_err(e)),
+            Err(zircon::Status::ErrTimedOut) => return Ok(false),
+            Err(e) => Err(e)?,
         };
 
         let observed_signals = match packet.contents() {
-            magenta::PacketContents::SignalOne(signal_packet) => {
+            zircon::PacketContents::SignalOne(signal_packet) => {
                 signal_packet.observed()
             }
-            magenta::PacketContents::SignalRep(signal_packet) => {
+            zircon::PacketContents::SignalRep(signal_packet) => {
                 signal_packet.observed()
             }
-            magenta::PacketContents::User(_user_packet) => {
+            zircon::PacketContents::User(_user_packet) => {
                 // User packets are only ever sent by an Awakener
                 return Ok(true);
             }
@@ -190,7 +188,7 @@
                 Ok(false)
             },
             RegType::Fd => {
-                // Convert the signals to epoll events using __mxio_wait_end,
+                // Convert the signals to epoll events using __fdio_wait_end,
                 // and add to reregistration list if necessary.
                 let events: u32;
                 {
@@ -207,7 +205,7 @@
 
                     events = unsafe {
                         let mut events: u32 = mem::uninitialized();
-                        sys::fuchsia::sys::__mxio_wait_end(handle.mxio(), observed_signals, &mut events);
+                        sys::fuchsia::sys::__fdio_wait_end(handle.fdio(), observed_signals, &mut events);
                         events
                     };
 
@@ -238,10 +236,10 @@
 
     /// Register event interests for the given IO handle with the OS
     pub fn register_fd(&self,
-                       handle: &magenta::Handle,
+                       handle: &zircon::Handle,
                        fd: &EventedFd,
                        token: Token,
-                       signals: magenta::Signals,
+                       signals: zircon::Signals,
                        poll_opts: PollOpt) -> io::Result<()>
     {
         {
@@ -256,24 +254,23 @@
 
         let wait_async_opts = poll_opts_to_wait_async(poll_opts);
 
-        let wait_res = handle.wait_async_handle(&self.port, token.0 as u64, signals, wait_async_opts)
-            .map_err(status_to_io_err);
+        let wait_res = handle.wait_async_handle(&self.port, token.0 as u64, signals, wait_async_opts);
 
         if wait_res.is_err() {
             self.token_to_fd.lock().unwrap().remove(&token);
         }
 
-        wait_res
+        Ok(wait_res?)
     }
 
     /// Deregister event interests for the given IO handle with the OS
-    pub fn deregister_fd(&self, handle: &magenta::Handle, token: Token) -> io::Result<()> {
+    pub fn deregister_fd(&self, handle: &zircon::Handle, token: Token) -> io::Result<()> {
         self.token_to_fd.lock().unwrap().remove(&token);
 
         // We ignore NotFound errors since oneshots are automatically deregistered,
         // but mio will attempt to deregister them manually.
         self.port.cancel(&*handle, token.0 as u64)
-            .map_err(status_to_io_err)
+            .map_err(io::Error::from)
             .or_else(|e| if e.kind() == io::ErrorKind::NotFound {
                 Ok(())
             } else {
@@ -282,7 +279,7 @@
     }
 
     pub fn register_handle(&self,
-                           handle: mx_handle_t,
+                           handle: zx_handle_t,
                            token: Token,
                            interests: Ready,
                            poll_opts: PollOpt) -> io::Result<()>
@@ -292,30 +289,28 @@
                       "Repeated level-triggered events are not supported on Fuchsia handles."));
         }
 
-        let temp_handle = unsafe { magenta::Handle::from_raw(handle) };
+        let temp_handle = unsafe { zircon::Handle::from_raw(handle) };
 
         let res = temp_handle.wait_async_handle(
                     &self.port,
                     key_from_token_and_type(token, RegType::Handle)?,
-                    FuchsiaReady::from(interests).into_mx_signals(),
-                    poll_opts_to_wait_async(poll_opts))
-              .map_err(status_to_io_err);
+                    FuchsiaReady::from(interests).into_zx_signals(),
+                    poll_opts_to_wait_async(poll_opts));
 
         mem::forget(temp_handle);
 
-        res
+        Ok(res?)
     }
 
 
-    pub fn deregister_handle(&self, handle: mx_handle_t, token: Token) -> io::Result<()>
+    pub fn deregister_handle(&self, handle: zx_handle_t, token: Token) -> io::Result<()>
     {
-        let temp_handle = unsafe { magenta::Handle::from_raw(handle) };
-        let res = self.port.cancel(&temp_handle, key_from_token_and_type(token, RegType::Handle)?)
-                 .map_err(status_to_io_err);
+        let temp_handle = unsafe { zircon::Handle::from_raw(handle) };
+        let res = self.port.cancel(&temp_handle, key_from_token_and_type(token, RegType::Handle)?);
 
         mem::forget(temp_handle);
 
-        res
+        Ok(res?)
     }
 }
 
diff --git a/test/mod.rs b/test/mod.rs
index ad79234..75cda53 100644
--- a/test/mod.rs
+++ b/test/mod.rs
@@ -12,7 +12,7 @@
 extern crate tempdir;
 
 #[cfg(target_os = "fuchsia")]
-extern crate magenta;
+extern crate fuchsia_zircon as zircon;
 
 pub use ports::localhost;
 
diff --git a/test/test_fuchsia_handles.rs b/test/test_fuchsia_handles.rs
index 589471f..85a1432 100644
--- a/test/test_fuchsia_handles.rs
+++ b/test/test_fuchsia_handles.rs
@@ -1,6 +1,6 @@
 use mio::*;
 use mio::fuchsia::EventedHandle;
-use magenta::{self, AsHandleRef};
+use zircon::{self, AsHandleRef};
 use std::time::Duration;
 
 const MS: u64 = 1_000;
@@ -11,7 +11,7 @@
     let mut event_buffer = Events::with_capacity(1);
     let event_buffer = &mut event_buffer;
 
-    let (channel0, channel1) = magenta::Channel::create(magenta::ChannelOpts::Normal).unwrap();
+    let (channel0, channel1) = zircon::Channel::create(zircon::ChannelOpts::Normal).unwrap();
     let channel1_evented = unsafe { EventedHandle::new(channel1.raw_handle()) };
 
     poll.register(&channel1_evented, Token(1), Ready::readable(), PollOpt::edge()).unwrap();