Skip to content

Commit

Permalink
Fixed an extremely rare crash on 10.12.
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Oct 20, 2016
1 parent ee82ff3 commit 4415b08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -23,6 +23,7 @@ AppleALC Changelog
- Added ALC887 layout-id 33 for GA-Q87TN by klblk
- Added ALC256 (3246) codec support layout-id 13 by InsanelyDeepak
- Added ALC255 layout-id 13 and 17 by InsanelyDeepak
- Fixed an extremely rare crash on 10.12

#### v1.0.16
- Fixed a rare lock acquisition issue on 10.12
Expand Down
25 changes: 14 additions & 11 deletions Common/kern_patcher.cpp
Expand Up @@ -214,27 +214,30 @@ void KernelPatcher::applyLookupPatch(const LookupPatch *patch) {
curr = off;
off += size - patch->size;
size_t changes {0};

if (kinfo->setKernelWriting(true) != KERN_SUCCESS) {
SYSLOG("patcher @ lookup patching failed to write to kernel");
code = Error::MemoryProtection;
return;
}

for (size_t i = 0; curr < off && (i < patch->count || patch->count == 0); i++) {
while (curr < off && memcmp(curr, patch->find, patch->size))
curr++;

if (curr != off) {
if (kinfo->setKernelWriting(true) != KERN_SUCCESS) {
SYSLOG("patcher @ lookup patching failed to write to kernel");
code = Error::MemoryProtection;
return;
}
for (size_t j = 0; j < patch->size; j++) {
curr[j] = patch->replace[j];
}
if (kinfo->setKernelWriting(false) != KERN_SUCCESS) {
SYSLOG("patcher @ lookup patching failed to disable kernel writing");
code = Error::MemoryProtection;
return;
}
changes++;
}
}

if (kinfo->setKernelWriting(false) != KERN_SUCCESS) {
SYSLOG("patcher @ lookup patching failed to disable kernel writing");
code = Error::MemoryProtection;
return;
}

if (changes != patch->count) {
SYSLOG("patcher @ lookup patching applied only %zu patches out of %zu", changes, patch->count);
Expand Down Expand Up @@ -424,4 +427,4 @@ void KernelPatcher::onKextSummariesUpdated() {
}
}
}
#endif /* KEXTPATCH_SUPPORT */
#endif /* KEXTPATCH_SUPPORT */

0 comments on commit 4415b08

Please sign in to comment.