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] non-Go code set up signal handler without SA_ONSTACK flag #127

Open
st0pli opened this issue Jan 9, 2025 · 3 comments
Open
Labels
help wanted Extra attention is needed troubleshooting Investigating an issue to determine its status

Comments

@st0pli
Copy link
Contributor

st0pli commented Jan 9, 2025

macbookpro m2
The program occasionally crashes and reports the following error:

signal 16 received but handler not on signal stack
fatal error: non-Go code set up signal handler without SA_ONSTACK flag

go/src/syscall/zerrors_darwin_arm64.go
SIGURG = Signal(0x10)

go 1.20
go 1.23
All of these versions are available, but not on linux

I found the following description, I don't know if it works:

If a SIGPIPE signal is received, the Go program will invoke the special handling described above if the SIGPIPE is received on a Go thread. If the SIGPIPE is received on a non-Go thread the signal will be forwarded to the non-Go handler, if any; if there is none the default system handler will cause the program to terminate.

@st0pli
Copy link
Contributor Author

st0pli commented Jan 10, 2025

This code is working.

package main

import (
	"github.com/mappu/miqt/qt"
	"os"
	"syscall"
)

/*
#include <stdint.h>
#include <stdio.h>

#ifdef __cplusplus
#include <csignal>
#else
#include <signal.h>
#endif

void Ignore(int sigNum);

void Ignore(int sigNum) {
    struct sigaction sa;
    sa.sa_handler = SIG_DFL;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags |= SA_ONSTACK;
    sigaction(sigNum, &sa, NULL);
}

*/
import "C"

func Ignore(sigNum syscall.Signal) {
	C.Ignore(C.int(sigNum))
}

func main() {
	qt.NewQApplication(os.Args)
        // your code
	Ignore(syscall.SIGURG)
	qt.QApplication_Exec()
}

@st0pli st0pli closed this as completed Jan 10, 2025
@st0pli st0pli reopened this Jan 10, 2025
@mappu
Copy link
Owner

mappu commented Jan 11, 2025

I haven't tried MIQT on Apple Silicon before. I'm interested to hear about any problems.

I think Go uses the SIGURG signal itself, to switch between running goroutines. It should always be caught by Go's internal signal handler:

sigPreempt is the signal used for non-cooperative preemption.

We use SIGURG

Therefore if SIGURG was ignored, or if it was caught by another signal handler, then some goroutine functionality might not work fully.

@mappu mappu added the help wanted Extra attention is needed label Jan 11, 2025
@mappu mappu changed the title non-Go code set up signal handler without SA_ONSTACK flag [Apple Silicon] non-Go code set up signal handler without SA_ONSTACK flag Jan 11, 2025
@st0pli
Copy link
Contributor Author

st0pli commented Jan 15, 2025

The problem has not been found yet, but there is no abnormal exit after doing this, and it continues to find

Update some code
sa.sa_handler = SIG_DFL;
sa.sa_flags |= SA_ONSTACK;

@mappu mappu added the troubleshooting Investigating an issue to determine its status label Feb 1, 2025
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 troubleshooting Investigating an issue to determine its status
Projects
None yet
Development

No branches or pull requests

2 participants