@@ -12,14 +12,12 @@ use self::mach_sys::{kern_return_t, mach_msg_body_t, mach_msg_header_t, mach_msg
1212use self :: mach_sys:: { mach_msg_ool_descriptor_t, mach_msg_port_descriptor_t, mach_msg_type_name_t} ;
1313use self :: mach_sys:: { mach_msg_timeout_t, mach_port_limits_t, mach_port_msgcount_t} ;
1414use self :: mach_sys:: { mach_port_right_t, mach_port_t, mach_task_self_, vm_inherit_t} ;
15- use crate :: ipc:: { self , IpcMessage } ;
15+ use crate :: ipc:: IpcMessage ;
1616
17- use bincode;
1817use libc:: { self , c_char, c_uint, c_void, size_t} ;
1918use rand:: { self , Rng } ;
2019use std:: cell:: Cell ;
2120use std:: convert:: TryInto ;
22- use std:: error:: Error as StdError ;
2321use std:: ffi:: CString ;
2422use std:: fmt:: { self , Debug , Formatter } ;
2523use std:: io;
@@ -30,6 +28,7 @@ use std::ptr;
3028use std:: slice;
3129use std:: sync:: RwLock ;
3230use std:: time:: Duration ;
31+ use thiserror:: Error ;
3332
3433mod mach_sys;
3534
@@ -997,43 +996,28 @@ impl Message {
997996 }
998997}
999998
1000- #[ derive( Clone , Copy , Debug , PartialEq ) ]
999+ #[ derive( Clone , Copy , Debug , Error , PartialEq ) ]
10011000pub enum KernelError {
1001+ #[ error( "Success" ) ]
10021002 Success ,
1003+ #[ error( "No room in IPC name space for another right." ) ]
10031004 NoSpace ,
1005+ #[ error( "Name doesn't denote a right in the task" ) ]
10041006 InvalidName ,
1007+ #[ error( "Name denotes a right, but not an appropiate right." ) ]
10051008 InvalidRight ,
1009+ #[ error( "Blatant range error" ) ]
10061010 InvalidValue ,
1011+ #[ error( "The supplied (port) capability is improper" ) ]
10071012 InvalidCapability ,
1013+ #[ error( "Operation would overflow limit on user-references" ) ]
10081014 UrefsOverflow ,
1015+ #[ error( "Receive right is not a member of a port set." ) ]
10091016 NotInSet ,
1017+ #[ error( "Unkown kernel error. {0}" ) ]
10101018 Unknown ( kern_return_t ) ,
10111019}
10121020
1013- impl fmt:: Display for KernelError {
1014- fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
1015- match * self {
1016- KernelError :: Success => write ! ( fmt, "Success." ) ,
1017- KernelError :: NoSpace => write ! ( fmt, "No room in IPC name space for another right." ) ,
1018- KernelError :: InvalidName => write ! ( fmt, "Name doesn't denote a right in the task." ) ,
1019- KernelError :: InvalidRight => {
1020- write ! ( fmt, "Name denotes a right, but not an appropriate right." )
1021- } ,
1022- KernelError :: InvalidValue => write ! ( fmt, "Blatant range error." ) ,
1023- KernelError :: InvalidCapability => {
1024- write ! ( fmt, "The supplied (port) capability is improper." )
1025- } ,
1026- KernelError :: UrefsOverflow => {
1027- write ! ( fmt, "Operation would overflow limit on user-references." )
1028- } ,
1029- KernelError :: NotInSet => write ! ( fmt, "Receive right is not a member of a port set." ) ,
1030- KernelError :: Unknown ( code) => write ! ( fmt, "Unknown kernel error: {:x}" , code) ,
1031- }
1032- }
1033- }
1034-
1035- impl StdError for KernelError { }
1036-
10371021impl From < kern_return_t > for KernelError {
10381022 fn from ( code : kern_return_t ) -> KernelError {
10391023 match code {
@@ -1050,10 +1034,10 @@ impl From<kern_return_t> for KernelError {
10501034 }
10511035}
10521036
1053- #[ derive( Clone , Copy , Debug , PartialEq ) ]
1037+ #[ derive( Clone , Copy , Debug , Error , PartialEq ) ]
10541038pub enum MachError {
10551039 Success ,
1056- Kernel ( KernelError ) ,
1040+ Kernel ( # [ from ] KernelError ) ,
10571041 IpcSpace ,
10581042 VmSpace ,
10591043 IpcKernel ,
@@ -1185,14 +1169,6 @@ impl fmt::Display for MachError {
11851169 }
11861170}
11871171
1188- impl StdError for MachError { }
1189-
1190- impl From < MachError > for bincode:: Error {
1191- fn from ( mach_error : MachError ) -> Self {
1192- io:: Error :: from ( mach_error) . into ( )
1193- }
1194- }
1195-
11961172impl From < mach_msg_return_t > for MachError {
11971173 fn from ( code : mach_msg_return_t ) -> MachError {
11981174 match code {
@@ -1240,27 +1216,23 @@ impl From<mach_msg_return_t> for MachError {
12401216 }
12411217}
12421218
1243- impl From < KernelError > for MachError {
1244- fn from ( kernel_error : KernelError ) -> MachError {
1245- MachError :: Kernel ( kernel_error)
1246- }
1247- }
1248-
1249- impl From < MachError > for ipc:: TryRecvError {
1219+ impl From < MachError > for crate :: TryRecvError {
12501220 fn from ( error : MachError ) -> Self {
12511221 match error {
1252- MachError :: NotifyNoSenders => ipc:: TryRecvError :: IpcError ( ipc:: IpcError :: Disconnected ) ,
1253- MachError :: RcvTimedOut => ipc:: TryRecvError :: Empty ,
1254- e => ipc:: TryRecvError :: IpcError ( ipc:: IpcError :: Io ( io:: Error :: from ( e) ) ) ,
1222+ MachError :: NotifyNoSenders => {
1223+ crate :: TryRecvError :: IpcError ( crate :: IpcError :: Disconnected )
1224+ } ,
1225+ MachError :: RcvTimedOut => crate :: TryRecvError :: Empty ,
1226+ e => crate :: TryRecvError :: IpcError ( crate :: IpcError :: Io ( io:: Error :: from ( e) ) ) ,
12551227 }
12561228 }
12571229}
12581230
1259- impl From < MachError > for ipc :: IpcError {
1231+ impl From < MachError > for crate :: IpcError {
12601232 fn from ( error : MachError ) -> Self {
12611233 match error {
1262- MachError :: NotifyNoSenders => ipc :: IpcError :: Disconnected ,
1263- e => ipc :: IpcError :: Io ( io:: Error :: from ( e) ) ,
1234+ MachError :: NotifyNoSenders => crate :: IpcError :: Disconnected ,
1235+ e => crate :: IpcError :: Io ( io:: Error :: from ( e) ) ,
12641236 }
12651237 }
12661238}
0 commit comments