             events.1.flags = UInt16(Int16(EV_ADD))
         }
         
-        return withUnsafeMutableBytes(of: &events) { event_ptr -> Int32 in
+        let _ = try withUnsafeMutableBytes(of: &events) { event_ptr -> Int32 in
             precondition(MemoryLayout<kevent>.size * 2 == event_ptr.count)
             let ptr = event_ptr.baseAddress?.bindMemory(to: kevent.self, capacity: 2)
-            return kevent(self.fd, ptr, 2, ptr, 2, nil)
+            
+            return try wrapSyscall({ $0 >= 0 }, function: "kevent") {
+                kevent(self.fd, ptr, 2, ptr, 2, nil)
+            }
         }
     }
 #endif

        ev.events = toEpollEvents(interested: interested)
        ev.data.fd = selectable.descriptor

        let res = CEpoll.epoll_ctl(self.fd, EPOLL_CTL_ADD, selectable.descriptor, &ev)
        guard res == 0 else {
            throw ioError(errno: errno, function: "epoll_ctl")
        }
        registrations[Int(selectable.descriptor)] = Registration(selectable: selectable, attachment: attachment)
#else
        let res = register_kqueue(selectable: selectable, interested: interested)
    
        guard res != -1 else {
            throw ioError(errno: errno, function: "kevent")
        }
        registrations[Int(selectable.descriptor)] = Registration(selectable: selectable, attachment: attachment)
#endif
    }
    
    public func reregister(selectable: Selectable, interested: InterestedEvent) throws {

        evs.1.udata = nil
        evs.1.flags = UInt16(Int16(EV_DELETE))

        let _ = try withUnsafeMutableBytes(of: &evs) { event_ptr -> Int32 in
            precondition(MemoryLayout<kevent>.size * 2 == event_ptr.count)
            let ptr = event_ptr.baseAddress?.bindMemory(to: kevent.self, capacity: 2)
            
            return try wrapSyscall({ $0 >= 0 }, function: "kevent") {
                kevent(self.fd, ptr, 2, ptr, 2, nil)
            }
        }
#endif
        registrations.removeValue(forKey: Int(selectable.descriptor))

    }
    
    public func awaitReady() throws -> Array<SelectorEvent>? {
#if os(Linux)
        let ready = try wrapSyscall({ $0 >= 0 }, function: "epoll_wait") {
            CEpoll.epoll_wait(self.fd, events, 2048, 0)
        }
        if (ready > 0) {
            var sEvents = [SelectorEvent]()
            var i = 0;
