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

Apple Silicon M1 #725

Closed
koekeishiya opened this issue Nov 18, 2020 · 235 comments
Closed

Apple Silicon M1 #725

koekeishiya opened this issue Nov 18, 2020 · 235 comments
Labels
Apple Silicon Only related to Apple Silicon machines discussion Discussion

Comments

@koekeishiya
Copy link
Owner

koekeishiya commented Nov 18, 2020

Placeholder to track support for Apple Silicon M1 at some point in the distant future.

Couple of things to be mentioned..

  1. The scripting-addition obviously needs a full rewrite for the ARM architecture and I do not actually have hands on experience with any ARM processor. This should not be a blocker, but will take time as the Dock.app ARM binary needs to be reverse engineered in the same way we did the x86-64 version.
    The master branch should now compile and run fine on Apple Silicon with Monterey 12.0.0 and 12.0.1.

  2. As this project does not have any external dependencies with the exception of the C standard library and Apple frameworks, I would expect basic support (read: compile and run) for Apple Silicon to work with close to no changes. Considering the performance differences between the models I am also interested in knowing if this will provide a noticeably better user experience when interacting with applications through the accessibility API, as yabai is doing, when managing windows.
    The master branch should now compile and run fine on Apple Silicon with Monterey 12.0.0 and 12.0.1.

Feel free to discuss potential issues or post notable mentions in this issue.
If you are one of the people that have decided to get a first gen. M1 machine and are a developer, it would be great to see how yabai (or similar software) ends up running.

I'm undecided whether to get one of the new machines, or wait for further adjustments to their high-end machines.
Probably won't be getting one any time soon, so don't expect official support for some time.

@koekeishiya koekeishiya added the discussion Discussion label Nov 18, 2020
@koekeishiya koekeishiya pinned this issue Nov 20, 2020
@cxa
Copy link

cxa commented Nov 22, 2020

Wow, so quick and nice!

Does this 4410fef mean we can run script additions on M1 now?

@koekeishiya
Copy link
Owner Author

koekeishiya commented Nov 22, 2020

I don't even know if the method for code injection is still going to work on the M1, and I can't really verify anything as I don't have one. The above commits are mostly just future notes for myself for when I do end up buying one, or if other members in the community want to do the work required to support the M1.

I have made adjustments to the injection process that I believe should work on the M1. If it works; the current master should support things such as window borders, opacity, layers (sticky windows) and such, but none of the spaces functionality will work yet.

Edit:
For people with experience in reverse engineering; basically locate the functions and object instances using the patterns provided in the osax/x86_64/payload.m file in the x86_64 binary, look for patterns that let you identify the same function in the arm64 binary, and fill out osax/arm64/payload.m. These patterns are then resolved in the function init_instances() in osax/payload.m. There is some inline x86_64 specific code in osax/payload.m when both resolving and calling some of these functions that also require changes.

@cxa

This comment has been minimized.

@koekeishiya

This comment has been minimized.

@fielding
Copy link

I have both yabai and skhd up and running on my m1.
Screen Shot 2020-11-22 at 6 24 37 PM

So far so good! Here are a few small things I have noticed so far. Some of this might be my ignorance/configuration, but figured I would report it either way.

Screenshot of the first thing:
Screen Shot 2020-11-22 at 6 17 37 PM

This one is likely me being dumb, but for some reason I felt like the borders worked fine even on windows with a border radius of sorts.

The second thing:
I am seeing borders on workspaces for windows that aren't there/are on other workspaces maybe?/are hidden? ... I'm not entirely sure what is causing that.

Note: I don't have the scripting additions up and running at all, but I am down to try and get it going as well.

Thanks for all your work on this!

@koekeishiya
Copy link
Owner Author

Window borders require the scripting addition to work correctly. The current master should support this, but spaces functionality is not yet implemented for arm.

@cxa
Copy link

cxa commented Nov 23, 2020

I've installed master, I can confirmed that borders are not working (still shows "failed to inject payload into Dock.app!"), but yabai -m window --space N works.

@koekeishiya
Copy link
Owner Author

Can you post the output of the following commands:
Screenshot 2020-11-23 at 17 18 06

@cxa
Copy link

cxa commented Nov 23, 2020

Screen Shot 2020-11-24 at 00 29 17

@koekeishiya
Copy link
Owner Author

koekeishiya commented Nov 23, 2020

Right, so it seems to me like it should be working fine. I'm probably just doing something wrong when setting up the thread state for arm64 here: https://github.com/koekeishiya/yabai/blob/master/src/osax/mach_loader.c#L94

@koekeishiya
Copy link
Owner Author

Added a commit to master that will print the error; could you fetch that, compile and run sudo yabai --load-sa again and post the output?

@cxa
Copy link

cxa commented Nov 23, 2020

sudo yabai --load-sa
could not spawn remote thread: (os/kern) protection failure
yabai: scripting-addition failed to inject payload into Dock.app!

@koekeishiya
Copy link
Owner Author

Hmm how about now? I don't think it should matter, but it is my last idea as of now.

@cxa
Copy link

cxa commented Nov 23, 2020

Still the same.

koekeishiya added a commit that referenced this issue Nov 23, 2020
@koekeishiya
Copy link
Owner Author

@cxa Can you try the latest commit? clean, make and reinstall the scripting addition before finally trying to load it.

@cxa
Copy link

cxa commented Nov 23, 2020

I installed latest commit with brew install koekeishiya/formulae/yabai --HEAD, this should be a clean rebuild? After that I run

sudo yabai --uninstall-sa
sudo yabai --install-sa
sudo yabai --load-sa

Unfortunately it was still the same result.

@koekeishiya
Copy link
Owner Author

Hmm aight, I give up for now; I don't see what I'm doing wrong.

@cxa
Copy link

cxa commented Nov 23, 2020

Thanks for your hard working! Wish you a good day.

@koekeishiya
Copy link
Owner Author

This seems like it could be relevant for the M1: https://bazad.github.io/2018/10/bypassing-platform-binary-task-threads/

@AurevoirXavier
Copy link

AurevoirXavier commented Nov 19, 2021

xavier in ~ takes 173ms
Fri Nov 19 16:35:33 2021 - 30%
λ sudo yabai --load-sa
could not set thread state: (os/kern) protection failure
yabai: scripting-addition failed to inject payload into Dock.app!

xavier in ~ takes 58ms
Fri Nov 19 16:35:36 2021 - 31%
✗ csrutil status
System Integrity Protection status: disabled.

# And I also set the boot-args + reboot.

Any idea on this?

I follow the latest wiki that you mentioned above.

@koekeishiya
Copy link
Owner Author

koekeishiya commented Nov 19, 2021

I am unable to reproduce that error. What's the output of the following:

cat /Library/ScriptingAdditions/yabai.osax/Contents/Info.plist | grep -A 1 CFBundleVersion

file /Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload

file /Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader

@AurevoirXavier
Copy link

xavier in ~
Fri Nov 19 16:50:30 2021 - 36%
✗ cat /Library/ScriptingAdditions/yabai.osax/Contents/Info.plist | grep -A 1 CFBundleVersion

<key>CFBundleVersion</key>
<string>2.0.0</string>

xavier in ~ takes 21ms
Fri Nov 19 16:50:31 2021 - 36%
λ file /Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload
/Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload: Mach-O 64-bit dynamically linked shared library arm64

xavier in ~ takes 26ms
Fri Nov 19 16:50:39 2021 - 36%
λ file /Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader
/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader: Mach-O 64-bit executable arm64

@koekeishiya
Copy link
Owner Author

Well that is weird, my output is:

~ cat /Library/ScriptingAdditions/yabai.osax/Contents/Info.plist | grep -A 1 CFBundleVersion                 9:57
<key>CFBundleVersion</key>
<string>2.0.0</string>
~ file /Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload       9:57
/Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64e:Mach-O 64-bit dynamically linked shared library arm64e]
/Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload (for architecture x86_64):	Mach-O 64-bit dynamically linked shared library x86_64
/Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload (for architecture arm64e):	Mach-O 64-bit dynamically linked shared library arm64e
~ file /Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader                                     9:57
/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader (for architecture x86_64):	Mach-O 64-bit executable x86_64
/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader (for architecture arm64e):	Mach-O 64-bit executable arm64e

@AurevoirXavier
Copy link

Well that is weird, my output is:

~ cat /Library/ScriptingAdditions/yabai.osax/Contents/Info.plist | grep -A 1 CFBundleVersion                 9:57
<key>CFBundleVersion</key>
<string>2.0.0</string>
~ file /Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload       9:57
/Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64e:Mach-O 64-bit dynamically linked shared library arm64e]
/Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload (for architecture x86_64):	Mach-O 64-bit dynamically linked shared library x86_64
/Library/ScriptingAdditions/yabai.osax/Contents/Resources/payload.bundle/Contents/MacOS/payload (for architecture arm64e):	Mach-O 64-bit dynamically linked shared library arm64e
~ file /Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader                                     9:57
/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader (for architecture x86_64):	Mach-O 64-bit executable x86_64
/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader (for architecture arm64e):	Mach-O 64-bit executable arm64e

I have also tried uninstall&install.

@koekeishiya
Copy link
Owner Author

If you use the prebuilt binary I posted in: #923 (comment) to install the scripting-addition. Run the same check as above. Does it show as a universal binary? I suspect there is an issue with brew compilation for whatever reason???

@cxa
Copy link

cxa commented Nov 19, 2021

I've confirmed installing with brew install koekeishiya/formulae/yabai --HEAD will cause arch to be arm64 not arm64e. With cloning to local and manual makeing, every thing is fine.

@cxa
Copy link

cxa commented Nov 19, 2021

I enabled window border and there's inner shadows, as I investigated before, kCGSDisableShadowTagBit does not work anymore. You can check my workaround here https://github.com/donaldguy/yabai/pull/2/files if you would interest. @koekeishiya

@AurevoirXavier
Copy link

I've confirmed installing with brew install koekeishiya/formulae/yabai --HEAD will cause arch to be arm64 not arm64e. With cloning to local and manual makeing, every thing is fine.

Fixed by building from source then replacing the binary.

@storopoli
Copy link

There are some lines in the makefile at master which states -arch arm64 instead of -arch arm64e. Couldn't that be the culprit?

@koekeishiya
Copy link
Owner Author

koekeishiya commented Nov 19, 2021

@cxa Borders cause the window server and/or random applications to crash; you probably should not use these. Regarding the shadow; I'll investigate that if I am able to get borders working properly. Chances are that borders will be removed for Monterey, as I think the API we rely on is just not reliable anymore.

@storopoli The yabai binary itself is built as arm64 & x86_64, but the scripting-addition is built as arm64e & x86_64

@storopoli
Copy link

Might be something related to this? In my machine homebrew clang takes over as the main compiler:

❯ which clang
/opt/homebrew/opt/llvm/bin/clang
❯ type -a clang
clang is /opt/homebrew/opt/llvm/bin/clang
clang is /usr/bin/clang

@storopoli
Copy link

Ok, I think I got this. I've installed with brew install yabai --HEAD and them downloaded the prebuilt binary I posted in: #923 (comment) .

Then I did this (a kinda hack):

cd Desktop/archive/bin/
mv yabai /opt/homebrew/Cellar/yabai/HEAD-6bcf544/bin/yabai
override r-xr-xr-x  storopoli/admin for /opt/homebrew/Cellar/yabai/HEAD-6bcf544/bin/yabai? (y/n [n]) y

It seem to be working now.

@koekeishiya
Copy link
Owner Author

Closing in favour of #1054.

@koekeishiya koekeishiya unpinned this issue Nov 19, 2021
unrevre pushed a commit to unrevre/yabai that referenced this issue Jan 26, 2022
unrevre pushed a commit to unrevre/yabai that referenced this issue Jan 26, 2022
unrevre pushed a commit to unrevre/yabai that referenced this issue Jan 26, 2022
unrevre pushed a commit to unrevre/yabai that referenced this issue Jan 26, 2022
unrevre pushed a commit to unrevre/yabai that referenced this issue Jan 26, 2022
unrevre pushed a commit to unrevre/yabai that referenced this issue Jan 26, 2022
unrevre pushed a commit to unrevre/yabai that referenced this issue Jan 26, 2022
@koekeishiya koekeishiya removed the addressed not released Fixed upstream, but not yet released label Mar 17, 2022
@zxhTom
Copy link

zxhTom commented Mar 20, 2023

file /Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader

file /Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader
/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader: cannot open `/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader' (No such file or directory)

m1 monterey 12.0.1 why ?

@koekeishiya
Copy link
Owner Author

file /Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader
/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader: cannot open `/Library/ScriptingAdditions/yabai.osax/Contents/MacOS/mach_loader' (No such file or directory)

m1 monterey 12.0.1 why ?

Because there have been changes since 2021.

#1287

#1515 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apple Silicon Only related to Apple Silicon machines discussion Discussion
Projects
None yet
Development

No branches or pull requests