int main(int argc, char **argv) { kern_return_t kr; int ret; io_iterator_t iterator; io_service_t serviceObject; CFDictionaryRef classToMatch; pthread_t dataQueueThread; io_connect_t connection; setbuf(stdout, NULL); if (!(classToMatch = IOServiceMatching(VNODE_WATCHER_IOKIT_CLASS))) PRINT_ERROR_AND_RETURN("failed to create matching dictionary", -1); kr = IOServiceGetMatchingServices(kIOMasterPortDefault, classToMatch, &iterator); if (kr != kIOReturnSuccess) PRINT_ERROR_AND_RETURN("failed to retrieve matching services", -1); serviceObject = IOIteratorNext(iterator); IOObjectRelease(iterator); if (!serviceObject) PRINT_ERROR_AND_RETURN("VnodeWatcher service not found", -1); kr = IOServiceOpen(serviceObject, mach_task_self(), 0, &connection); IOObjectRelease(serviceObject); if (kr != kIOReturnSuccess) PRINT_ERROR_AND_RETURN("failed to open VnodeWatcher service", kr); kr = IOConnectMethodScalarIScalarO(connection, kt_kVnodeWatcherUserClientOpen, 0, 0); if (kr != KERN_SUCCESS) { (void)IOServiceClose(connection); PRINT_ERROR_AND_RETURN("VnodeWatcher service is busy", kr); } ret = pthread_create(&dataQueueThread, (pthread_attr_t *)0, (void *)vnodeNotificationHandler, (void *)connection); if (ret) perror("pthread_create"); else pthread_join(dataQueueThread, (void **)&kr); (void)IOServiceClose(connection); return 0; }
void getBufferSizeAndKeys(int* size, int* keys) { kern_return_t kernResult; UInt32 bufferSize=0; UInt32 kextKeys=0; kernResult = IOConnectMethodScalarIScalarO(userClient, klogKextBuffandKeys, 0, // input count 2, // output count &bufferSize, &kextKeys); // ptr to output structure *size=bufferSize; *keys=kextKeys; return; }
kern_return_t openMSRClient(io_connect_t connect) { kern_return_t kernResult; #if !defined(__LP64__) if (IOConnectCallScalarMethod != NULL) { #endif kernResult = IOConnectCallScalarMethod(connect, kOpenDriver, NULL, 0, NULL, NULL); #if !defined(__LP64__) } else { kernResult = IOConnectMethodScalarIScalarO(connect, kOpenDriver, 0, 0); } #endif return kernResult; }
SCM ambient_light_range(SCM lower_bound, SCM upper_bound) { io_connect_t ioPort; int leftLight, rightLight; io_service_t serviceObject = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleLMUController")); if (serviceObject) { IOServiceOpen(serviceObject, mach_task_self(), 0, &ioPort); IOObjectRelease(serviceObject); } IOConnectMethodScalarIScalarO(ioPort, 0, 0, 2, &leftLight, &rightLight); return scm_from_int(((leftLight+rightLight)/4096.0 > scm_to_double(lower_bound)) && ((leftLight+rightLight)/4096.0 < scm_to_double(upper_bound))); }
kern_return_t decrementNumClients(io_connect_t connect, uint32_t* num_insts) { kern_return_t kernResult; #if !defined(__LP64__) if (IOConnectCallStructMethod != NULL) { #endif uint32_t num_outputs = 1; uint64_t knum_insts; kernResult = IOConnectCallStructMethod(connect, kDecrementNumInstances, NULL, 0, &knum_insts, &num_outputs); *num_insts = (uint32_t)knum_insts; #if !defined(__LP64__) } else { kernResult = IOConnectMethodScalarIScalarO(connect, kDecrementNumInstances, 0, 1, NULL, num_insts); } #endif return kernResult; }
int getLmuData(lmu_data &result) { kern_return_t kr; io_service_t serviceObject; io_connect_t dataPort = 0; serviceObject = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleLMUController")); if (serviceObject) { kr= IOServiceOpen(serviceObject, mach_task_self(), 0, &dataPort); IOObjectRelease(serviceObject); if(kr==KERN_SUCCESS) { uint32_t outputCnt= 2; uint64_t scalarI_64[2]; scalarI_64[0]= 0; scalarI_64[1]= 0; uint32_t left, right; #if defined(__LP64__) //check if 10.5 api available kr= IOConnectCallScalarMethod(dataPort, 0, NULL, 0, scalarI_64, &outputCnt); if(kr==KERN_SUCCESS) { result.left = scalarI_64[0]; result.right = scalarI_64[1]; return 1; } #else //use 10.4 api kr= IOConnectMethodScalarIScalarO(dataPort, 0, 0, 2, &left, &right); if(kr==KERN_SUCCESS) { result.left = left; result.right = right; return 1; } #endif } } return 0; }