Long Time Ago Refactoring Ideas

Refactoring ideas suggested long time ago from previous jobs Libraries are too tightly coupled with each other Libraries should not depend on each other too much, otherwise you have to update all libraries which misses the entire idea of decoupling. ...

February 7, 2024

OSX kernel simple operations

Getting current information Get current task with: #include <kern/task.h> task_t cur_task = current_task(); Get current thread with: ...

February 19, 2015

OSX IOKit sleep notification

Get sleep notification in your IOKit kext IOReturn yourIOKitDriverClass::powerStateHandler(void *target, void *refCon, UInt32 messageType, IOService *service, void *messageArgs, vm_size_t argSize) { IOPMSystemCapabilityChangeParameters * params; if ( messageType != kIOMessageSystemCapabilityChange ) { // We are not interested in anything other than cap change. return kIOReturnSuccess; } params = (IOPMSystemCapabilityChangeParameters *) messageArgs; if ((params->changeFlags & kIOPMSystemCapabilityWillChange) && (params->fromCapabilities & kIOPMSystemCapabilityGraphics) && (params->toCapabilities & kIOPMSystemCapabilityGraphics) == 0) { // caught a sleep } return kIOReturnSuccess; } bool yourIOKitDriverClass::start(IOService *provider) { IOService *rootDomain = (IOService *)getPMRootDomain(); if (rootDomain) rootDomain->registerInterestedDriver(this); registerPrioritySleepWakeInterest(powerStateHandler, this, 0); } Actually it’s not a sleep notification exactly but it’s good enough if you don’t need to handle power in your kext (and you probably don’t want to handle power in your kext) ...

February 19, 2015