1 #include <darwintest.h>
3 #include <IOKit/IOKitLib.h>
4 #include <Kernel/IOKit/crypto/AppleKeyStoreDefs.h>
7 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
9 T_DECL(ioconnectasyncmethod_referenceCnt
,
10 "Test IOConnectCallAsyncMethod with referenceCnt < 1",
16 uint64_t reference
= 0;
17 service
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching(kAppleKeyStoreServiceName
));
18 if (service
== IO_OBJECT_NULL
) {
19 T_SKIP("Service " kAppleKeyStoreServiceName
" could not be opened. skipping test");
21 T_ASSERT_NE(service
, MACH_PORT_NULL
, "got " kAppleKeyStoreServiceName
" service");
22 T_ASSERT_MACH_SUCCESS(IOServiceOpen(service
, mach_task_self(), 0, &conn
), "opened connection to service");
23 T_ASSERT_MACH_SUCCESS(mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE
, &wakePort
), "allocated wake port");
24 T_ASSERT_MACH_ERROR(IOConnectCallAsyncMethod(conn
, 0 /* selector */, wakePort
, &reference
, 0 /* referenceCnt */,
25 NULL
/* input */, 0 /* inputCnt */, NULL
/* inputStruct */, 0 /* inputStructCnt */,
26 NULL
/* output */, 0 /* outputCnt */, NULL
/* outputStruct */, 0 /* outputStructCntP */), kIOReturnBadArgument
, "IOConnectCallAsyncMethod should fail with kIOReturnBadArgument");
28 mach_port_mod_refs(mach_task_self(), wakePort
, MACH_PORT_RIGHT_RECEIVE
, -1);