Thoughts on shell tools

Below a list of points I believe should be handled when writing shell tools. Exit Status Exit status (exit(0) or exit(1)) is the way for letting the caller know the execution has failed. ...

February 7, 2024 · map[name:latedeployment]

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 · map[name:latedeployment]

Linux User Time

Say we want to measure the number of user space instructions a process is spending at a function. There are number of ways to do so: gettimeofday, times, clock and getrusage, but they give you time and not CPU cycles and not very accurate. ...

April 18, 2017 · map[name:latedeployment]

Old macOS kernel debugging with LLDB

Note: This won’t work anymore, Apple has pretty much disabled any ability to work with kernel extensions. This is just an old blog post. Kext are no longer supported, use System Extensions and similar approach ...

November 4, 2016 · map[name:latedeployment]

Crashing Compilers

The compilers Let’s see if we can crash some compilers. python3 -c "print('{' * 99999)" > test.c && clang test.c Clang SEGFAULT but GCC has made it :) ...

November 11, 2015 · map[name:latedeployment]

Static Inline Mess

It’s a known fact (at least to me), that static inline functions in C++ will generate multiple instances of a function if used in a different translation unit (a file, why call it differently?). ...

September 19, 2015 · map[name:latedeployment]

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 · map[name:latedeployment]

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 · map[name:latedeployment]

OSX Firewire kernel debugging

Introduction If you ever need to debug a newly (Yosemite) OSX kernel using firewire here is a small tutorial to help you through. ...

February 18, 2015 · map[name:latedeployment]