Skip to content

Commit

Permalink
SoftwareUpdate.cpp: Fix hw.optional reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
khronokernel committed Apr 13, 2023
1 parent d725f95 commit 495f4d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
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.1.1
- Fixed `f16c` patch misreporting other `hw.optional` features

#### v1.1.0
- Added `hw.optional.f16c` disabling for macOS 13.3+
- Resolves CoreGraphics.framework invoking AVX2.0 code paths on Ivy Bridge CPUs
Expand Down
19 changes: 14 additions & 5 deletions RestrictEvents/SoftwareUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,16 @@ static int my_sysctl_vmm_present(__unused struct sysctl_oid *oidp, __unused void
return FunctionCast(my_sysctl_vmm_present, org_sysctl_vmm_present)(oidp, arg1, arg2, req);
}

static int my_sysctl_f16c(__unused struct sysctl_oid *oidp, __unused void *arg1, int arg2, struct sysctl_req *req) {
int f16c_off = 0;
return SYSCTL_OUT(req, &f16c_off, sizeof(f16c_off));

static mach_vm_address_t org_sysctl_f16c;
static int my_sysctl_f16c(__unused struct sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req) {
// Strip F16C bit from arg1
// Ref: https://github.com/apple-oss-distributions/xnu/blob/xnu-8020.101.4/bsd/kern/kern_mib.c#L935-L946
int mask = (uint64_t) (uintptr_t) arg1 & ~kHasF16C;

// Convert back
arg1 = (void *) (uintptr_t) mask;
return FunctionCast(my_sysctl_f16c, org_sysctl_f16c)(oidp, arg1, arg2, req);
}


Expand Down Expand Up @@ -200,8 +207,10 @@ void reroutef16c(KernelPatcher &patcher) {
SYSLOG("supd", "failed to resolve hw.optional.f16c sysctl");
return;
}

if (!patcher.routeFunction(reinterpret_cast<mach_vm_address_t>(f16c->oid_handler), reinterpret_cast<mach_vm_address_t>(my_sysctl_f16c), true)) {

org_sysctl_f16c = patcher.routeFunction(reinterpret_cast<mach_vm_address_t>(f16c->oid_handler), reinterpret_cast<mach_vm_address_t>(my_sysctl_f16c), true);

if (!org_sysctl_f16c) {
SYSLOG("supd", "failed to route hw.optional.f16c sysctl");
patcher.clearError();
return;
Expand Down
2 changes: 2 additions & 0 deletions RestrictEvents/SoftwareUpdate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#define HW_PRODUCT 27

#define kHasF16C 0x04000000

typedef int (* sysctl_handler_t)(struct sysctl_oid *oidp __unused, void *arg1 __unused, int arg2 __unused, struct sysctl_req *req);

struct sysctl_oid {
Expand Down

0 comments on commit 495f4d5

Please sign in to comment.