Skip to content

Commit

Permalink
#2146 fix mach loader for macOS Sonoma 14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Mar 9, 2024
1 parent ab0a249 commit e55dd28
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Combine effects of all matching window rules before applying rule effects [#2123](https://github.com/koekeishiya/yabai/issues/2123)
- Window insert feedback visual should use same layer as parent window [#2132](https://github.com/koekeishiya/yabai/issues/2132)
- Window animations will perform an alpha fade upon end-transition [#2137](https://github.com/koekeishiya/yabai/issues/2137)
- Updated scripting-addition mach loader/injection to work for macOS Sonoma 14.4 [#2146](https://github.com/koekeishiya/yabai/issues/2146)

### Removed
- When adding new window rules, their effects will only apply to *windows that open after the rule has been added*. To restore old behavior, run `yabai -m rule --apply` after adding all rules [#2123](https://github.com/koekeishiya/yabai/issues/2123)
Expand Down
46 changes: 25 additions & 21 deletions src/osax/loader.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,12 @@ int main(int argc, char **argv)
return 1;
}

struct arm_unified_thread_state thread_state = {};
struct arm_unified_thread_state machine_thread_state = {};
arm_thread_state64_t thread_state = {}, machine_thread_state = {};
thread_state_flavor_t thread_flavor = ARM_THREAD_STATE64;
mach_msg_type_number_t thread_flavor_count = ARM_THREAD_STATE64_COUNT, machine_thread_flavor_count = ARM_THREAD_STATE64_COUNT;

thread_state_flavor_t thread_flavor = ARM_UNIFIED_THREAD_STATE;
mach_msg_type_number_t thread_flavor_count = ARM_UNIFIED_THREAD_STATE_COUNT;
mach_msg_type_number_t machine_thread_flavor_count = ARM_UNIFIED_THREAD_STATE_COUNT;

thread_state.ash.flavor = ARM_THREAD_STATE64;
thread_state.ash.count = ARM_THREAD_STATE64_COUNT;

__darwin_arm_thread_state64_set_pc_fptr(thread_state.ts_64, ptrauth_sign_unauthenticated((void *) code, ptrauth_key_asia, 0));
__darwin_arm_thread_state64_set_sp(thread_state.ts_64, stack + (stack_size / 2));
__darwin_arm_thread_state64_set_pc_fptr(thread_state, ptrauth_sign_unauthenticated((void *) code, ptrauth_key_asia, 0));
__darwin_arm_thread_state64_set_sp(thread_state, stack + (stack_size / 2));

kern_return_t error = thread_create(task, &thread);
if (error != KERN_SUCCESS) {
Expand All @@ -235,16 +229,26 @@ int main(int argc, char **argv)
return 1;
}

error = thread_set_state(thread, thread_flavor, (thread_state_t)&machine_thread_state, machine_thread_flavor_count);
if (error != KERN_SUCCESS) {
fprintf(stderr, "could not set thread state: %s\n", mach_error_string(error));
return 1;
}
NSOperatingSystemVersion os_version = [[NSProcessInfo processInfo] operatingSystemVersion];
if (os_version.majorVersion == 14 && os_version.minorVersion >= 4) {
thread_terminate(thread);
error = thread_create_running(task, thread_flavor, (thread_state_t)&machine_thread_state, machine_thread_flavor_count, &thread);
if (error != KERN_SUCCESS) {
fprintf(stderr, "could not spawn remote thread: %s\n", mach_error_string(error));
return 1;
}
} else {
error = thread_set_state(thread, thread_flavor, (thread_state_t)&machine_thread_state, machine_thread_flavor_count);
if (error != KERN_SUCCESS) {
fprintf(stderr, "could not set thread state: %s\n", mach_error_string(error));
return 1;
}

error = thread_resume(thread);
if (error != KERN_SUCCESS) {
fprintf(stderr, "could not resume remote thread: %s\n", mach_error_string(error));
return 1;
error = thread_resume(thread);
if (error != KERN_SUCCESS) {
fprintf(stderr, "could not resume remote thread: %s\n", mach_error_string(error));
return 1;
}
}
#endif

Expand All @@ -261,7 +265,7 @@ int main(int argc, char **argv)
#ifdef __x86_64__
if (thread_state.__rax == 0x79616265) {
#elif __arm64__
if (thread_state.ts_64.__x[0] == 0x79616265) {
if (thread_state.__x[0] == 0x79616265) {
#endif
result = 0;
goto terminate;
Expand Down

0 comments on commit e55dd28

Please sign in to comment.