1 #include <darwintest.h> 2 #include <mach/mach.h> 3 #include <IOKit/IOKitLib.h> 4 #include <Kernel/IOKit/crypto/AppleKeyStoreDefs.h> 5 6 7 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); 8 9 T_DECL(ioconnectasyncmethod_referenceCnt, 10 "Test IOConnectCallAsyncMethod with referenceCnt < 1", 11 T_META_ASROOT(true)) 12 { 13 io_service_t service; 14 io_connect_t conn; 15 mach_port_t wakePort; 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"); 20 } 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"); 27 IOServiceClose(conn); 28 mach_port_mod_refs(mach_task_self(), wakePort, MACH_PORT_RIGHT_RECEIVE, -1); 29 } 30