Skip to content

Commit

Permalink
VERSION 1.1.2: Code style changed
Browse files Browse the repository at this point in the history
  • Loading branch information
PMheart committed Oct 22, 2017
1 parent c093745 commit ee79de7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
4 changes: 2 additions & 2 deletions CPUFriend.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
MODULE_NAME = org.vanilla.driver.CPUFriend;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.1.1;
MODULE_VERSION = 1.1.2;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down Expand Up @@ -412,7 +412,7 @@
MODULE_NAME = org.vanilla.driver.CPUFriend;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.1.1;
MODULE_VERSION = 1.1.2;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down
53 changes: 24 additions & 29 deletions CPUFriend/CPUFriend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,35 @@

#include "CPUFriend.hpp"

static const char * binList[] {
"/System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/X86PlatformPlugin.kext/Contents/MacOS/X86PlatformPlugin"
};

static const char * idList[] {
"com.apple.driver.X86PlatformPlugin"
};

static const char * symbolList[] {
"__ZN17X86PlatformPlugin22configResourceCallbackEjiPKvjPv"
};
static const char *kextX86PP[] = { "/System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/X86PlatformPlugin.kext/Contents/MacOS/X86PlatformPlugin" };
static const char *kextX86PPId = "com.apple.driver.X86PlatformPlugin";

static KernelPatcher::KextInfo kextList[] {
{ idList[0], & binList[0], arrsize(binList), { false, false }, {}, KernelPatcher::KextInfo::Unloaded }
{ kextX86PPId, kextX86PP, arrsize(kextX86PP), {}, {}, KernelPatcher::KextInfo::Unloaded }
};

static constexpr size_t kextListSize = arrsize(kextList);

static CPUFriendPlugin * callbackCpuf = nullptr;
static CPUFriendPlugin *callbackCpuf = nullptr;

OSDefineMetaClassAndStructors(CPUFriendPlatform, IOService)
OSDefineMetaClassAndStructors(CPUFriendData, IOService)

IOService * CPUFriendPlatform::probe(IOService * provider, SInt32 * score) {
IOService *CPUFriendData::probe(IOService *provider, SInt32 *score)
{
if (provider) {
if (callbackCpuf) {
if (! callbackCpuf->frequencyData) {
if (!callbackCpuf->frequencyData) {
auto name = provider->getName();
if (! name)
if (!name)
name = "(null)";
DBGLOG("probe", "looking for cf-frequency-data in %s", name);

auto data = OSDynamicCast(OSData, provider->getProperty("cf-frequency-data"));
if (! data) {
if (!data) {
auto cpu = provider->getParentEntry(gIOServicePlane);
if (cpu) {
name = cpu->getName();
if (! name)
if (!name)
name = "(null)";
DBGLOG("probe", "looking for cf-frequency-data in %s", name);
data = OSDynamicCast(OSData, cpu->getProperty("cf-frequency-data"));
Expand All @@ -68,11 +60,12 @@ IOService * CPUFriendPlatform::probe(IOService * provider, SInt32 * score) {
return nullptr;
}

bool CPUFriendPlugin::init() {
bool CPUFriendPlugin::init()
{
callbackCpuf = this;

LiluAPI::Error error = lilu.onKextLoad(kextList, kextListSize, [](void * user, KernelPatcher & patcher, size_t index, mach_vm_address_t address, size_t size) {
static_cast<CPUFriendPlugin * >(user)->processKext(patcher, index, address, size);
LiluAPI::Error error = lilu.onKextLoad(kextList, kextListSize, [](void *user, KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size) {
static_cast<CPUFriendPlugin *>(user)->processKext(patcher, index, address, size);
}, this);

if (error != LiluAPI::Error::NoError) {
Expand All @@ -83,7 +76,8 @@ bool CPUFriendPlugin::init() {
return true;
}

void CPUFriendPlugin::myConfigResourceCallback(uint32_t requestTag, kern_return_t result, const void * resourceData, uint32_t resourceDataLength, void * context) {
void CPUFriendPlugin::myConfigResourceCallback(uint32_t requestTag, kern_return_t result, const void *resourceData, uint32_t resourceDataLength, void *context)
{
if (callbackCpuf && callbackCpuf->orgConfigLoadCallback) {
auto data = callbackCpuf->frequencyData;
auto sz = callbackCpuf->frequencyDataSize;
Expand All @@ -101,24 +95,25 @@ void CPUFriendPlugin::myConfigResourceCallback(uint32_t requestTag, kern_return_
}
}

void CPUFriendPlugin::processKext(KernelPatcher & patcher, size_t index, mach_vm_address_t address, size_t size) {
void CPUFriendPlugin::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size)
{
if (progressState != ProcessingState::EverythingDone) {
for (size_t i = 0; i < kextListSize; i++) {
if (kextList[i].loadIndex == index) {
DBGLOG("processKext", "current kext is %s progressState %d", kextList[i].id, progressState);
// clear error from the very beginning just in case
patcher.clearError();
if (! strcmp(kextList[i].id, idList[0])) {
auto callback = patcher.solveSymbol(index, symbolList[0]);
if (!strcmp(kextList[i].id, kextX86PPId)) {
auto callback = patcher.solveSymbol(index, "__ZN17X86PlatformPlugin22configResourceCallbackEjiPKvjPv");
if (callback) {
orgConfigLoadCallback = reinterpret_cast<t_callback>(patcher.routeFunction(callback, reinterpret_cast<mach_vm_address_t>(myConfigResourceCallback), true));
if (patcher.getError() == KernelPatcher::Error::NoError) {
DBGLOG("processKext", "routed %s", symbolList[0]);
DBGLOG("processKext", "routed %s", "__ZN17X86PlatformPlugin22configResourceCallbackEjiPKvjPv");
} else {
SYSLOG("processKext", "failed to route %s", symbolList[0]);
SYSLOG("processKext", "failed to route %s", "__ZN17X86PlatformPlugin22configResourceCallbackEjiPKvjPv");
}
} else {
SYSLOG("processKext", "failed to find %s", symbolList[0]);
SYSLOG("processKext", "failed to find %s", "__ZN17X86PlatformPlugin22configResourceCallbackEjiPKvjPv");
}
progressState |= ProcessingState::CallbackRouted;
}
Expand Down
12 changes: 6 additions & 6 deletions CPUFriend/CPUFriend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include <Headers/kern_patcher.hpp>
#include <Library/LegacyIOService.h>

class EXPORT CPUFriendPlatform : public IOService {
OSDeclareDefaultStructors(CPUFriendPlatform)
class EXPORT CPUFriendData : public IOService {
OSDeclareDefaultStructors(CPUFriendData)
public:
IOService * probe(IOService * provider, SInt32 *score) override;
IOService *probe(IOService *provider, SInt32 *score) override;
};

class CPUFriendPlugin {
Expand All @@ -34,7 +34,7 @@ class CPUFriendPlugin {
/**
* Loaded user-specified frequency data
*/
const void * frequencyData = nullptr;
const void *frequencyData = nullptr;

/**
* Loaded user-specified frequency data size
Expand All @@ -45,7 +45,7 @@ class CPUFriendPlugin {
/**
* Hooked ResourceLoad callback returning user-specified platform data
*/
static void myConfigResourceCallback(uint32_t requestTag, kern_return_t result, const void * resourceData, uint32_t resourceDataLength, void * context);
static void myConfigResourceCallback(uint32_t requestTag, kern_return_t result, const void *resourceData, uint32_t resourceDataLength, void *context);

/**
* Patch kext if needed and prepare other patches
Expand All @@ -55,7 +55,7 @@ class CPUFriendPlugin {
* @param address kinfo load address
* @param size kinfo memory size
*/
void processKext(KernelPatcher & patcher, size_t index, mach_vm_address_t address, size_t size);
void processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size);

/**
* Current progress mask
Expand Down
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CPUFriend Changelog
===================
#### v1.1.2
- Code style changed

#### v1.1.1
- Various typo fixes

Expand Down

0 comments on commit ee79de7

Please sign in to comment.