39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package main
|
|
|
|
/*
|
|
#define _GNU_SOURCE
|
|
#include <signal.h>
|
|
#include <stdbool.h>
|
|
|
|
// fixSigsegvOnStack adds SA_ONSTACK to the current SIGSEGV handler.
|
|
// Go 1.24+ requires all signal handlers to have SA_ONSTACK set,
|
|
// but WebKit/JavaScriptCore installs a SIGSEGV handler without it.
|
|
void fixSigsegvOnStack(void) {
|
|
struct sigaction act;
|
|
if (sigaction(SIGSEGV, NULL, &act) == 0) {
|
|
if (!(act.sa_flags & SA_ONSTACK)) {
|
|
act.sa_flags |= SA_ONSTACK;
|
|
sigaction(SIGSEGV, &act, NULL);
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
import "C"
|
|
|
|
import "time"
|
|
|
|
// ensureSignalOnStack periodically ensures SIGSEGV handler has SA_ONSTACK.
|
|
// This is needed because WebKit/JavaScriptCore installs a SIGSEGV handler
|
|
// without SA_ONSTACK, which causes Go 1.24+ to crash with:
|
|
// "non-Go code set up signal handler without SA_ONSTACK flag"
|
|
func ensureSignalOnStack() {
|
|
// Apply once after a short delay to let WebKit initialize
|
|
go func() {
|
|
// Retry a few times since WebKit may re-install its handler
|
|
for i := 0; i < 10; i++ {
|
|
time.Sleep(200 * time.Millisecond)
|
|
C.fixSigsegvOnStack()
|
|
}
|
|
}()
|
|
}
|