diff options
-rw-r--r-- | smc.c | 36 | ||||
-rw-r--r-- | sudden_motion_sensor.c | 33 |
2 files changed, 53 insertions, 16 deletions
@@ -165,15 +165,33 @@ kern_return_t SMCCall(int index, SMCKeyData_t *inputStructure, SMCKeyData_t *out structureInputSize = sizeof(SMCKeyData_t); structureOutputSize = sizeof(SMCKeyData_t); - - return IOConnectMethodStructureIStructureO( - conn, - index, - structureInputSize, - &structureOutputSize, - inputStructure, - outputStructure - ); +#if !defined(__LP64__) + // Check if Mac OS X 10.5 API is available... + if (IOConnectCallStructMethod != NULL) { + // ...and use it if it is. +#endif + return IOConnectCallStructMethod( + conn, // an io_connect_t returned from IOServiceOpen(). + index, // selector of the function to be called via the user client. + inputStructure, // pointer to the input struct parameter. + structureInputSize, // the size of the input structure parameter. + outputStructure, // pointer to the output struct parameter. + &structureOutputSize// pointer to the size of the output structure parameter. + ); +#if !defined(__LP64__) + } + else { + // Otherwise fall back to older API. + return IOConnectMethodStructureIStructureO( + conn, // an io_connect_t returned from IOServiceOpen(). + index, // an index to the function to be called via the user client. + structureInputSize, // the size of the input struct paramter. + &structureOutputSize, // a pointer to the size of the output struct paramter. + inputStructure, // a pointer to the input struct parameter. + outputStructure // a pointer to the output struct parameter. + ); + } +#endif } kern_return_t SMCReadKey(UInt32Char_t key, SMCVal_t *val) diff --git a/sudden_motion_sensor.c b/sudden_motion_sensor.c index 1ea0a87..a9daa89 100644 --- a/sudden_motion_sensor.c +++ b/sudden_motion_sensor.c @@ -142,13 +142,32 @@ FOUND_SENSOR: memset(&inputStructure, 0, sizeof(inputStructure)); memset(&outputStructure, 0, sizeof(outputStructure)); - kern_return = IOConnectMethodStructureIStructureO( - io_connect, - kernel_function, /* index to kernel function */ - structureInputSize, - &structureOutputSize, - &inputStructure, - &outputStructure); +#if !defined(__LP64__) + // Check if Mac OS X 10.5 API is available... + if (IOConnectCallStructMethod != NULL) { + // ...and use it if it is. +#endif + kern_return = IOConnectCallStructMethod( + io_connect, // an io_connect_t returned from IOServiceOpen(). + kernel_function, // selector of the function to be called via the user client. + &inputStructure, // pointer to the input struct parameter. + structureInputSize, // the size of the input structure parameter. + &outputStructure, // pointer to the output struct parameter. + &structureOutputSize// pointer to the size of the output structure parameter. + ); +#if !defined(__LP64__) + } + else { + // Otherwise fall back to older API. + kern_return = IOConnectMethodStructureIStructureO( + io_connect, // an io_connect_t returned from IOServiceOpen(). + kernel_function, // an index to the function to be called via the user client. + structureInputSize, // the size of the input struct paramter. + &structureOutputSize,// a pointer to the size of the output struct paramter. + &inputStructure, // a pointer to the input struct parameter. + &outputStructure); // a pointer to the output struct parameter. + } +#endif if( kern_return == KERN_SUCCESS) { |