mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-08 19:00:27 +00:00
Work around Rosetta signal handling issue (#455)
Rosetta does something strange to the signal handling registers but setting SA_SIGINFO prevents the issue from happening. Detect Rosetta and set the flag when necessary.
This commit is contained in:
parent
1ce101c5a5
commit
a09500b979
2 changed files with 25 additions and 0 deletions
|
@ -182,6 +182,7 @@ int symlinkat(const char *, int, const char *);
|
|||
int sync_file_range(int, int64_t, int64_t, unsigned);
|
||||
int sys_ptrace(int, ...);
|
||||
int sysctl(const int *, unsigned, void *, size_t *, void *, size_t);
|
||||
int sysctlbyname(const char *, size_t, void *, size_t *, void *, size_t);
|
||||
int tgkill(int, int, int);
|
||||
int tkill(int, int);
|
||||
int tmpfd(void);
|
||||
|
|
|
@ -7174,8 +7174,32 @@ static int WindowsReplThread(void *arg, int tid) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int IsRosetta() {
|
||||
if(!IsXnu()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
size_t size = sizeof(ret);
|
||||
|
||||
if(sysctlbyname("sysctl.proc_translated", sizeof("sysctl.proc_translated"), &ret, &size, NULL, 0) == -1) {
|
||||
if(errno == ENOENT)
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void InstallSignalHandler(int sig, void *handler) {
|
||||
struct sigaction sa = {.sa_sigaction = handler};
|
||||
|
||||
if(IsRosetta()) {
|
||||
// mitigate Rosetta signal handling strangeness
|
||||
// https://github.com/jart/cosmopolitan/issues/455
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
}
|
||||
|
||||
CHECK_NE(-1, sigaction(sig, &sa, 0));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue