Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed detecting CPU core count on Intel CPU #6

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
RestrictEvents Changelog
========================
#### v1.0.7
- Fixed detecting CPU core count on Intel CPU

#### v1.0.6
- Fixed memory view restrictions for `MacBookAir` and `MacBookPro10` not being correctly disabled
- Disabled `The disk you inserted was not readable by this computer` message popup
Expand Down
10 changes: 8 additions & 2 deletions RestrictEvents/RestrictEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "SoftwareUpdate.hpp"

extern "C" {
#include <i386/cpuid.h>
#include <i386/pmCPU.h>
}

Expand Down Expand Up @@ -245,8 +246,14 @@ struct RestrictEventsPolicy {
CPUInfo::getCpuid(0, 0, nullptr, &b, &c, &d);
bool isAMD = (b == CPUInfo::signature_AMD_ebx && c == CPUInfo::signature_AMD_ecx && d == CPUInfo::signature_AMD_edx);

pmKextRegister(PM_DISPATCH_VERSION, NULL, &pmCallbacks);
uint32_t cc = 0, pp = 0;
if (!isAMD) {
cc = cpuid_info()->core_count;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpuid_info() is com.apple.kpi.private, but I guess we cannot get there via any other way.

DBGLOG("rev", "calculated %u cores from cpuid_info()", cc);
return cc;
}

pmKextRegister(PM_DISPATCH_VERSION, NULL, &pmCallbacks);
auto pkg = pmCallbacks.GetPkgRoot();
while (pkg != nullptr) {
auto core = pkg->cores;
Expand All @@ -257,7 +264,6 @@ struct RestrictEventsPolicy {
DBGLOG("rev", "calculated %u cores in pkg %u amd %d", cc, pp, isAMD);
pp++;
pkg = pkg->next;
if (!isAMD) break;
}

return cc;
Expand Down