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

M1 arm64 deadlock #43

Open
fzwoch opened this issue Jul 29, 2022 · 46 comments
Open

M1 arm64 deadlock #43

fzwoch opened this issue Jul 29, 2022 · 46 comments
Labels
help wanted Extra attention is needed

Comments

@fzwoch
Copy link
Owner

fzwoch commented Jul 29, 2022

Looks like interacting with the the frontend API is deadlocking/crashing OBS.

Can be reproduced with the following plugin:

package main

// #include <obs-module.h>
// #include <obs-frontend-api.h>
//
// extern void frontend_event_cb(enum obs_frontend_event event, void* data);
//
import "C"
import (
	"log"
	"unsafe"
)

var obsModulePointer *C.obs_module_t

//export obs_module_set_pointer
func obs_module_set_pointer(module *C.obs_module_t) {
	obsModulePointer = module
}

//export obs_current_module
func obs_current_module() *C.obs_module_t {
	return obsModulePointer
}

//export obs_module_ver
func obs_module_ver() C.uint32_t {
	return C.LIBOBS_API_VER
}

//export frontend_event_cb
func frontend_event_cb(event C.enum_obs_frontend_event, data unsafe.Pointer) {
	log.Println("event:", event)
}

//export obs_module_load
func obs_module_load() C.bool {
	C.obs_frontend_add_event_callback(C.obs_frontend_event_cb(unsafe.Pointer(C.frontend_event_cb)), nil)

	return true
}

func main() {}

Could be a Go runtime issue when using cgo. But I have no idea..

@fzwoch
Copy link
Owner Author

fzwoch commented Jul 29, 2022

Process 2159 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x000000013fe00634 obs-test.so`notok + 4
obs-test.so`notok:
->  0x13fe00634 <+4>:  str    x8, [x8]
    0x13fe00638 <+8>:  b      0x13fe00638               ; <+8>
    0x13fe0063c <+12>: udf    #0x0

obs-test.so`runtime.open_trampoline.abi0:
    0x13fe00640 <+0>:  str    x30, [sp, #-0x10]!
Target 0: (OBS) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x000000013fe00634 obs-test.so`notok + 4
    frame #1: 0x000000013fe00c30 obs-test.so`runtime.sigaltstack_trampoline.abi0 + 32
    frame #2: 0x000000013fdff908 obs-test.so`runtime.asmcgocall.abi0 + 200
    frame #3: 0x000000013fdff908 obs-test.so`runtime.asmcgocall.abi0 + 200
    frame #4: 0x000000013fdff908 obs-test.so`runtime.asmcgocall.abi0 + 200

@arcreigh
Copy link

I also believe I am running into this on OBS 28 beta 2 on an M1 mini.

@fzwoch fzwoch mentioned this issue Sep 2, 2022
@fzwoch
Copy link
Owner Author

fzwoch commented Sep 2, 2022

I wonder if anyone with a beta of macOS Ventura wants to check if the issue persists.

@fzwoch
Copy link
Owner Author

fzwoch commented Sep 2, 2022

obs-teleport.plugin.zip

@kilinbox
Copy link

kilinbox commented Sep 5, 2022

obs-teleport.plugin.zip

I tried it.
OBS will not start after installing the plugin(obs-teleport.plugin).

macOS Ventura 13.0 Beta
OBS 28.0.1 arm64

@fzwoch
Copy link
Owner Author

fzwoch commented Sep 5, 2022

Thanks for checking. It does not take us much further - but is a good piece of information.

@fzwoch
Copy link
Owner Author

fzwoch commented Sep 15, 2022

A custom build of OBS with enabled Address-Sanitizer loads the plugin just fine. Without the sanitizer the same crash as above happens.

@fzwoch
Copy link
Owner Author

fzwoch commented Nov 16, 2022

Things are getting wild. With this OBS patch applied it seems to run fine:

--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -3055,6 +3055,19 @@ void ctrlc_handler(int s)
 
 int main(int argc, char *argv[])
 {
+#if defined __APPLE__ && defined __arm64__
+    char signalStack[SIGSTKSZ];
+    stack_t ss;
+    memset(&ss, 0, sizeof(ss));
+    ss.ss_sp = signalStack;
+    ss.ss_flags = 0;
+    ss.ss_size = SIGSTKSZ;
+    if (sigaltstack(&ss, NULL) < 0) {
+        perror("sigaltstack");
+        abort();
+    }
+#endif
+
 #ifndef _WIN32
 	signal(SIGPIPE, SIG_IGN);
 

Not sure though whether this breaks any existing signals/signal handlers.

@fzwoch fzwoch added the help wanted Extra attention is needed label Dec 5, 2022
@fzwoch
Copy link
Owner Author

fzwoch commented Jan 5, 2023

Here is a 0.6.1 version of the macOS plugin for M1/M2 if anyone interested. You will need to apply the patch below to OBS Studio and build it yourself to make it work though.

diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp
index 02cf48d6c016a..d1143603f93c0 100644
--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -3165,13 +3165,28 @@ void ctrlc_handler(int s)
 int main(int argc, char *argv[])
 {
 #ifndef _WIN32
-	signal(SIGPIPE, SIG_IGN);
+	stack_t ss;
+	ss.ss_sp = malloc(SIGSTKSZ);
+	if (ss.ss_sp == NULL) {
+		fprintf(stderr, "ss_sp alloc failed\n");
+		exit(1);
+	}
+	ss.ss_size = SIGSTKSZ;
+	ss.ss_flags = 0;
+	if (sigaltstack(&ss, NULL) < 0) {
+		perror("sigaltstack");
+		exit(1);
+	}
 
 	struct sigaction sig_handler;
 
-	sig_handler.sa_handler = ctrlc_handler;
+	sig_handler.sa_handler = SIG_IGN;
 	sigemptyset(&sig_handler.sa_mask);
-	sig_handler.sa_flags = 0;
+	sig_handler.sa_flags = SA_ONSTACK;
+
+	sigaction(SIGPIPE, &sig_handler, NULL);
+
+	sig_handler.sa_handler = ctrlc_handler;
 
 	sigaction(SIGINT, &sig_handler, NULL);
 

obs-teleport-0.6.1.zip

@fzwoch
Copy link
Owner Author

fzwoch commented Jan 19, 2023

For everyone trying this out. Please write back your macOS version and hardware configuration, and whether it has been working for you or not. (You didn't have to have the patch applied, I just want to collect information what may be the root cause of the original problem)

@jbaylies
Copy link

jbaylies commented Feb 15, 2023

When launching OBS 29.0.2 native with obs-teleport-0.6.1 or 0.6.5 on m1 mac 13.2.1, OBS bounces in the dock forever and doesn't appear.

@fzwoch
Copy link
Owner Author

fzwoch commented Feb 16, 2023

Yes, this is what thich ticket is about..

I can start up OBS when I connect a 2nd monitor and close my Macbook Air's lid.

@Dmitrycroft
Copy link

To date (February 20, 2023), the only fully working option for how you can play on a PC and stream through a macbook m1 is: Download the obs version for intel on a macbook m1 and install this plugin (teleport) according to the instructions. Since the teleport didn’t start through the obs version of apple silicon, I found a way out in installing the obs version for intel, which works great on the M1. Good luck to all! And thanks for the great alternative to the buggy NDI. P.S. If you have no sound through the teleport plugin when recording a video / broadcast from the obs, then just add your audio sources through the teleport filter. This link works flawlessly.

@boob1e
Copy link

boob1e commented Mar 12, 2023

Here is a 0.6.1 version of the macOS plugin for M1/M2 if anyone interested. You will need to apply the patch below to OBS Studio and build it yourself to make it work though.

diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp
index 02cf48d6c016a..d1143603f93c0 100644
--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -3165,13 +3165,28 @@ void ctrlc_handler(int s)
 int main(int argc, char *argv[])
 {
 #ifndef _WIN32
-	signal(SIGPIPE, SIG_IGN);
+	stack_t ss;
+	ss.ss_sp = malloc(SIGSTKSZ);
+	if (ss.ss_sp == NULL) {
+		fprintf(stderr, "ss_sp alloc failed\n");
+		exit(1);
+	}
+	ss.ss_size = SIGSTKSZ;
+	ss.ss_flags = 0;
+	if (sigaltstack(&ss, NULL) < 0) {
+		perror("sigaltstack");
+		exit(1);
+	}
 
 	struct sigaction sig_handler;
 
-	sig_handler.sa_handler = ctrlc_handler;
+	sig_handler.sa_handler = SIG_IGN;
 	sigemptyset(&sig_handler.sa_mask);
-	sig_handler.sa_flags = 0;
+	sig_handler.sa_flags = SA_ONSTACK;
+
+	sigaction(SIGPIPE, &sig_handler, NULL);
+
+	sig_handler.sa_handler = ctrlc_handler;
 
 	sigaction(SIGINT, &sig_handler, NULL);
 

obs-teleport-0.6.1.zip

this worked for me thank you

@the-maty
Copy link

Hello,
how does it look with support for apple silicon?
I tried it on my macbook pro with m2 max chip and can't even start obs.
I'm really looking forward to a possible fix.

@andrewmriv
Copy link

Here is a 0.6.1 version of the macOS plugin for M1/M2 if anyone interested. You will need to apply the patch below to OBS Studio and build it yourself to make it work though.

diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp
index 02cf48d6c016a..d1143603f93c0 100644
--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -3165,13 +3165,28 @@ void ctrlc_handler(int s)
 int main(int argc, char *argv[])
 {
 #ifndef _WIN32
-	signal(SIGPIPE, SIG_IGN);
+	stack_t ss;
+	ss.ss_sp = malloc(SIGSTKSZ);
+	if (ss.ss_sp == NULL) {
+		fprintf(stderr, "ss_sp alloc failed\n");
+		exit(1);
+	}
+	ss.ss_size = SIGSTKSZ;
+	ss.ss_flags = 0;
+	if (sigaltstack(&ss, NULL) < 0) {
+		perror("sigaltstack");
+		exit(1);
+	}
 
 	struct sigaction sig_handler;
 
-	sig_handler.sa_handler = ctrlc_handler;
+	sig_handler.sa_handler = SIG_IGN;
 	sigemptyset(&sig_handler.sa_mask);
-	sig_handler.sa_flags = 0;
+	sig_handler.sa_flags = SA_ONSTACK;
+
+	sigaction(SIGPIPE, &sig_handler, NULL);
+
+	sig_handler.sa_handler = ctrlc_handler;
 
 	sigaction(SIGINT, &sig_handler, NULL);
 

obs-teleport-0.6.1.zip

Re-rolling this patch for 29.x version.

diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp
index e0b9d114a..b48a0d11c 100644
--- a/UI/obs-app.cpp
+++ b/UI/obs-app.cpp
@@ -3245,13 +3245,27 @@ void OBSApp::ProcessSigInt(void)
 int main(int argc, char *argv[])
 {
 #ifndef _WIN32
-	signal(SIGPIPE, SIG_IGN);
+	stack_t ss;
+	ss.ss_sp = malloc(SIGSTKSZ);
+	if (ss.ss_sp == NULL) {
+		fprintf(stderr, "ss_sp alloc failed\n");
+		exit(1);
+	}
+	ss.ss_size = SIGSTKSZ;
+	ss.ss_flags = 0;
+	if (sigaltstack(&ss, NULL) < 0) {
+		perror("sigaltstack");
+		exit(1);
+	}
 
 	struct sigaction sig_handler;
 
-	sig_handler.sa_handler = OBSApp::SigIntSignalHandler;
+	sig_handler.sa_handler = SIG_IGN;
 	sigemptyset(&sig_handler.sa_mask);
-	sig_handler.sa_flags = 0;
+	sig_handler.sa_flags = SA_ONSTACK;
+	sigaction(SIGPIPE, &sig_handler, NULL);
+
+	sig_handler.sa_handler = OBSApp::SigIntSignalHandler;
 
 	sigaction(SIGINT, &sig_handler, NULL);

I am on a Mac Studio 2022, M1 Max with 32gb of RAM on MacOS Ventura 13.3.1.

@fzwoch
Copy link
Owner Author

fzwoch commented May 1, 2023

Thanks, I haven't noticed they did some changes in that area.

I have updated the original PR here:
obsproject/obs-studio#7973

Check the branch here:
https://github.com/fzwoch/obs-studio/tree/sigaltstack

Note that I don't expect it to me merged ever.

Apple also does not seem to care about the issue, or they consider it a user-space issue but are not telling.

@the-maty
Copy link

the-maty commented May 1, 2023

Thanks, I haven't noticed they did some changes in that area.

I have updated the original PR here: obsproject/obs-studio#7973

Note that I don't expect it to me merged ever.

Apple also does not seem to care about the issue, or they consider it a user-space issue but are not telling.

Does it mean that I have to edit something inside obs?
Sorry for my stupid questions :)

@fzwoch
Copy link
Owner Author

fzwoch commented May 1, 2023

Does it mean that I have to edit something inside obs? Sorry for my stupid questions :)

Yes.

@the-maty
Copy link

the-maty commented May 1, 2023

Does it mean that I have to edit something inside obs? Sorry for my stupid questions :)

Yes.

Is there a guide somewhere? I'm not that experienced.

@fzwoch
Copy link
Owner Author

fzwoch commented May 1, 2023

Is there a guide somewhere? I'm not that experienced.

Start here:
https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Mac

In general you will have to build OBS with the patch in the PR, or the pasted one above applied. It can be quite an en-devour for the inexperienced I guess. But you will have to check OBS guides, or guides for these developer tools in general. It is way out of the scope than I can do here..

@andrewmriv
Copy link

andrewmriv commented May 1, 2023

Is there a guide somewhere? I'm not that experienced.

Start here: https://github.com/obsproject/obs-studio/wiki/Build-Instructions-For-Mac

In general you will have to build OBS with the patch in the PR, or the pasted one above applied. It can be quite an en-devour for the inexperienced I guess. But you will have to check OBS guides, or guides for these developer tools in general. It is way out of the scope than I can do here..

Agree with this.

If anyone is inexperienced, the Prerequisites sections at the top of the guide might be confusing.

  1. If you are new to this, start by installing Homebrew by following the instructions here. You can use that to install the last 2 listed prerequisites: https://brew.sh/
  2. For xcode, you can download that from the Mac's App Store. If you aren't sure of your Mac version, click the Apple icon at the top left of the screen and then click About this Mac. At the time of writing this, you need to at least be on MacOS 12.0. So if the number listed is lower, consider upgrading to MacOS Ventura.
  3. For CMake, you can install it on your system by running brew install cmake
  4. For CCache, you can install it on your system by running brew install ccache

After that, you can follow the first step from the Configuring Build Project which is cloning the project. Copy the git clone --recursive https://github.com/obsproject/obs-studio.git command into your terminal and then run cd obs-studio to go the new directory from git.
Note: It is important that you use the --recursive flag so that all of the submodules are pulled in too.

Run git fetch origin pull/7973/head:bugfix/7973 to pull in the code from fzwoch's PR and put it into a new local branch named bugfix/7973.

Run git checkout bugfix/7973 to switch to the new local branch.

After that, you can continue to follow the steps in the official wiki's instructions without any issues.

My only issue when following the guide was that building from the command line did not work in the Build obs-studio section.
When running xcodebuild -configuration <Debug|Release|RelWithDebInfo|MinSizeRel> -scheme obs-studio -parallelizeTargets -destination "generic/platform=macOS,name=Any Mac", I got an error saying:

xcodebuild: error: Unknown build action 'obs-studio'

But to get around that:

  1. Open the build_arm64 folder that is generated from running cmake --preset macos-arm64.
  2. Open the obs-studio.xcodeproj file.
  3. (Optional) If you want the newly generated OBS.app file to go to your Applications folder, click Product at the top, then Scheme and then Choose Scheme and then select install from the list.

I wouldn't mind sharing the build I created, but I'm not sure if that is against the rules or anything.

@fzwoch
Copy link
Owner Author

fzwoch commented May 4, 2023

There is also a CI/build-macos.sh script that does the right thing sometimes..

@snwfdhmp
Copy link

@andrewmriv can you share ?

@the-maty
Copy link

There is also a CI/build-macos.sh script that does the right thing sometimes..

Hello, what script do you mean?

@fzwoch
Copy link
Owner Author

fzwoch commented Jul 30, 2023

It has been removed in the meantime from the OBS repository. Check with the OBS team on how to build OBS for macOS.

@charset404
Copy link

charset404 commented Sep 3, 2023

Same problem, this was my last outing, I hate NDI, I'm going to get a capture card at once:

MAC M1, 2020 - Ventura 13.5
OBS 29.0.2 (64 bit)

@FinalPrecursor
Copy link

Is this change being pushed to the OBS branch? I would like to see a work around that does not require people to manually build both OBS and the plugin. I am switching to MacOS for streaming and could really use this plugin.

@fzwoch
Copy link
Owner Author

fzwoch commented Nov 26, 2023

I tried getting a fix upstream, but i ran again into issues when trying to remove the signal stack and restoring the old one on exit. Then I hit another documentaion issue on Apple's side and I gave up. But anyone can try getting a proper change upstream..

@fzwoch
Copy link
Owner Author

fzwoch commented Nov 29, 2023

One can do it without patching OBS. It is still annoying though.

  1. Make sure System Integrity Protection is off:
% csrutil status
System Integrity Protection status: disabled.

If it is not check https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection?language=objc

  1. Run OBS with loaded address sanitizer:
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib /Applications/OBS.app/Contents/MacOS/OBS

You will have to check what Xcode version you have installed. So you will need an installation of Xcode. Change the directory for the file location where the sanitizer library is found.

Eventually startup fails with something similar to this:

signal 16 received but handler not on signal stack
mp.gsignal stack [0x106d50000 0x106dd0000], mp.g0 stack [0x16afa0000 0x16b79c000], sp=0x114000058768
fatal error: non-Go code set up signal handler without SA_ONSTACK flag

I guess that can happen since the signals are not properly set up now (which the patch does). Just try again, its seems to be working most of the time for me (but only God knows what impacts this behavior).

Not sure why this signal would sometimes be triggered though, and I'm not sure if it can happen again while OBS is running.. someone will find out?

@RadicalRingtail
Copy link

RadicalRingtail commented Dec 8, 2023

i tried out the workaround mentioned above, and while OBS did open and the plugin loaded, i wasnt able to transmit video via the plugin, nothing would show up in a teleport source (both locally and on another computer)

i was able to receive video from another OBS instance on the other computer though

edit: my bad, i acidentally had NDI enabled at the same time as teleport so it didnt work, got it fully working now, the fix above seems to be stable

@RadicalRingtail
Copy link

update: experiencing stability issues with the workaround, the stream isnt always picked up by another OBS instance, and lag issues keep happening as well at random (cant replicate it with changing settings either)

@fzwoch
Copy link
Owner Author

fzwoch commented Dec 9, 2023

Check the logs in the case of stability issues. It could very likely be a network congestion (WLAN?).

There may indeed be a problem on first start where the plugin is not work correctly. I have not found the reason for it happening. It seems to happen after first installation normally. So I blame Apple's security systems - but could very well be a bug in the plugin, but I don't think it is related to this bug or the workaround. I never found a reliable way to trigger it.

@animation31
Copy link

Hey everyone, so I manage to get it to "work"

Here is what I did:

  1. Downloaded the Intel Mac version of OBS from their site. (I have a m2 mac, but try it)
    As of writing this, version 30.0.0 is what I used. [https://obsproject.com/kb/macos-versions](Check it here)
  2. Downloaded the latest version of Teleport which was 0.7.0
  3. Installed OBS first, then Teleport using the install.command file
  4. Initially, macOS gave me a pop-up saying "Developer cannot verify," just pressed Cancel to open OBS.
  5. Then went to System Settings > Privacy and Security > scroll down and find Security, there were 2 messages regarding OBS and OBS plugin not being permitted to be opened or something (I can't remember at the top of my head), but press ALLOW for both.
  6. Open OBS and hopefully it works.

Now, I tried recording my PC via Teleport on my Macbook Pro, quality is good (set to 90) but the audio was laggy. So I'm going to check my settings on that.

Here is my MBP info btw:
Macbook Pro - M2 Pro
macOS Sonoma 14.2.1
OBS 30.0.0 (for the Mac), 30.0.2 (for the Windows PC)

Please forgive me as I don't know the proper use of lingo, quotations, etc in Github

@fzwoch
Copy link
Owner Author

fzwoch commented Jan 3, 2024

Yeah, running inside Rosetta is fine. But ideally one could run it natively without the translation layer.

@Doty1154
Copy link

Doty1154 commented Jan 5, 2024

Hey I'm running into this issue on my m1 as well. Here are the log files during startup with the latest plugin release and the latest obs. I started without the plugin as well so you can see the full log
logs.zip

please dm me if you want help troubleshooting 1:1

@nunowonder
Copy link

Hello all... so I´m one of those NDI users that LOVED to have teleport on his M1 Max machine, but because Teleport didn´t work on OBS M1 version, never really tried. Since yesterday that the NDI plugin just got messed out - there´s tons of people dealing with this and no one knows what´s happening - I really had to make sure I got teleport, and hey, what a BEAST! In spite of I only got it working on OBS Intel version (so it´s not using my resources of M1 Max and not optimized so I need to use more CPU power to have this working), I can tell that Teleport is THE thing! I only needed Alpha Transparency but... well seems that may take some time, so I am working with Color Key. Not ideal, but it makes what it´s needed, of course with a lack of quality but, it´s damn fast and damn good! Great Quality on transmission!
My question is: I don´t know how to "build" obs. I´m really noob in that matter. I really don´t know, even following those guides you posted above, how or even what to do. Shall I build an OBS that have the plugins already that I need? and sources and scenes already? And then, I can change something so that teleport is recognized with my M1 OBS version? Or maybe you are just releasing a version that WILL work on M1 computers? Please do.... I truly appreciate that...

@fzwoch
Copy link
Owner Author

fzwoch commented Feb 11, 2024 via email

@nunowonder
Copy link

@fzwoch Thank you very much for your answer, but what I was asking for was a Teleport version that would work on M1 OBS, not the build itself, that would be asking too much! ehehe :)
Anyway, of course having alpha transparency, it it was something you could do easily, would be actually more important than M1 version, because I can work with OBS (intel mode) on my M1, so... Well, I will be here for anything, any tests needed, I can help as you want so we can go through this :)

@fzwoch
Copy link
Owner Author

fzwoch commented Feb 11, 2024

The Teleport version available is all it can do to work on M1. Due to an Apple bug it is not. So it requires a patched OBS version or the workaround loading address sanitizer libraries.

There will be no alpha channel support.

@nunowonder
Copy link

nunowonder commented Feb 11, 2024

Ups I didn´t read about alpha channel. Can I ask why? Sorry it's only because I really don´t know why, because we get it with NDI. If it was like a "filter" on source, or sources, or scenes, that would send instead of Main Output?

@fzwoch
Copy link
Owner Author

fzwoch commented Mar 29, 2024

Here is another workaround that does not require running with Apple's address sanitizer or building a patched OBS version. I'll also attach a binary, so you won't even need Xcode to be installed. Check the SIP note below though!

signalstack.c

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

stack_t stack;

__attribute__((constructor))
void init()
{
	printf("SET UP SIGALTSTACK.. ");
	stack.ss_sp = malloc(SIGSTKSZ);
	if (stack.ss_sp == NULL) {
		printf("ss_sp alloc failed\n");
		exit(1);
	}
	stack.ss_size = SIGSTKSZ;
	stack.ss_flags = 0;
	if (sigaltstack(&stack, NULL) != 0) {
		printf("sigaltstack failed\n");
		exit(1);
	}
	printf("DONE\n");
}

Compile with:

clang -shared signalstack.c -o signalstack.dylib

Run with:

DYLD_INSERT_LIBRARIES=/path/to/signalstack.dylib /Applications/OBS.app/Contents/MacOS/OBS

You will probably still have to tinker with Apple's SIP to allow injection of shared libraries.
https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection

Check the output for the SET UP SIGALTSTACK.. DONE line to verify the loading is successful.

signalstack.zip

@nunowonder
Copy link

@fzwoch thank you so much for your help! The problem for me is: I don´t understand anything that you wrote... :)

@fzwoch
Copy link
Owner Author

fzwoch commented May 14, 2024

As another side note: It works just fine with PRISM Live Studio ¯\(ツ)

Was thinking about another try checking address sanitizer and thread sanitizer.. but OBS Studio does not compile with these options enabled.

@dillera
Copy link

dillera commented Oct 6, 2024

Still an issue in 2024, with OSX 15.1 Sequoia and M3. OBS locks up hard launching. The only way I've gotten it to work is download the x86 version of OBS and then have it run (using rosetta) with the compiled switcher dylib as above...

$ DYLD_INSERT_LIBRARIES=/Users/dillera/scratch/signalstack.dylib /Applications/OBS.app/Contents/MacOS/OBS

But that OBS is the x86 version, not ARM.

It will load after you give Teleport plugin the magic crap in Security Prefpane... and you can add remote teleports, and record- however the recording function will never quit and OBS must be force-quit. Have not tried streaming.

My Mac does have SIP enabled, I may turn that off next reboot and check again.

@fzwoch
Copy link
Owner Author

fzwoch commented Nov 30, 2024

0.7.3 tries a workaround that may make it work for some on Apple silicon devices.

diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go
index 6f40f440e8..e4dfddb377 100644
--- a/src/runtime/signal_unix.go
+++ b/src/runtime/signal_unix.go
@@ -432,6 +432,7 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
 	if sigfwdgo(sig, info, ctx) {
 		return
 	}
+	return
 	c := &sigctxt{info, ctx}
 	gp := sigFetchG(c)
 	setg(gp)
diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s
index 32d1f95d56..3859029a48 100644
--- a/src/runtime/sys_darwin_arm64.s
+++ b/src/runtime/sys_darwin_arm64.s
@@ -339,8 +339,8 @@ TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
 	MOVD	8(R0), R1		// arg 2 old
 	MOVD	0(R0), R0		// arg 1 new
 	CALL	libc_sigaltstack(SB)
-	CBZ	R0, 2(PC)
-	BL	notok<>(SB)
+//	CBZ	R0, 2(PC)
+//	BL	notok<>(SB)
 #endif
 	RET
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests