From 3c362a9bb23d99f2ca6faf0ffe5b4de90fe79edb Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Thu, 16 Apr 2020 14:18:28 +0300 Subject: [PATCH] Implement io_object_get_retain_count() --- src/IOObject.cpp | 16 ++++++++++++++++ src/stubs.c | 10 ---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/IOObject.cpp b/src/IOObject.cpp index 0562f64..408d42a 100644 --- a/src/IOObject.cpp +++ b/src/IOObject.cpp @@ -142,3 +142,19 @@ kern_return_t is_io_object_conforms_to *conforms = o->conformsTo(className); return kIOReturnSuccess; } + +kern_return_t is_io_object_get_retain_count +( + mach_port_t object, + uint32_t *retainCount +) +{ + IOObject* o = IOObject::lookup(object); + if (!o) + { + // Unlike other methods, this just returns 0 for invalid ports. + *retainCount = 0; + return KERN_SUCCESS; + } + return mach_port_get_refs(mach_task_self(), o->port(), MACH_PORT_RIGHT_SEND, retainCount); +} diff --git a/src/stubs.c b/src/stubs.c index ed213be..48f63f3 100644 --- a/src/stubs.c +++ b/src/stubs.c @@ -214,16 +214,6 @@ kern_return_t is_io_registry_entry_in_plane return KERN_NOT_SUPPORTED; } -kern_return_t is_io_object_get_retain_count -( - mach_port_t object, - uint32_t *retainCount -) -{ - STUB(); - return KERN_NOT_SUPPORTED; -} - kern_return_t is_io_service_get_busy_state ( mach_port_t service,