Commit c7f7bbbf authored by Russ Cox's avatar Russ Cox

runtime: fix build on linux

In addition to the compile failure fixed in signal*.c,
preserving the signal mask led to very strange crashes.
Testing shows that looking for SIG_IGN is all that
matters to get along with nohup, so reintroduce
sigset_zero instead of trying to preserve the signal mask.

TBR=iant
CC=golang-dev
https://golang.org/cl/7323067
parent f8f2727a
...@@ -290,7 +290,6 @@ struct M ...@@ -290,7 +290,6 @@ struct M
GCStats gcstats; GCStats gcstats;
bool racecall; bool racecall;
void* racepc; void* racepc;
void* sigset;
uint32 moreframesize_minalloc; uint32 moreframesize_minalloc;
uintptr settype_buf[1024]; uintptr settype_buf[1024];
......
...@@ -128,7 +128,7 @@ runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart) ...@@ -128,7 +128,7 @@ runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
// under nohup and do not set explicit handler. // under nohup and do not set explicit handler.
if(i == SIGHUP) { if(i == SIGHUP) {
runtime·memclr((byte*)&sa, sizeof sa); runtime·memclr((byte*)&sa, sizeof sa);
runtime·sigaction(i, nil, &sa); runtime·rt_sigaction(i, nil, &sa, sizeof(sa.sa_mask));
if(sa.k_sa_handler == SIG_IGN) if(sa.k_sa_handler == SIG_IGN)
return; return;
} }
......
...@@ -138,7 +138,8 @@ runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart) ...@@ -138,7 +138,8 @@ runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
// under nohup and do not set explicit handler. // under nohup and do not set explicit handler.
if(i == SIGHUP) { if(i == SIGHUP) {
runtime·memclr((byte*)&sa, sizeof sa); runtime·memclr((byte*)&sa, sizeof sa);
runtime·sigaction(i, nil, &sa); if(runtime·rt_sigaction(i, nil, &sa, sizeof(sa.sa_mask)) != 0)
runtime·throw("rt_sigaction read failure");
if(sa.sa_handler == SIG_IGN) if(sa.sa_handler == SIG_IGN)
return; return;
} }
......
...@@ -144,7 +144,7 @@ runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart) ...@@ -144,7 +144,7 @@ runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
// under nohup and do not set explicit handler. // under nohup and do not set explicit handler.
if(i == SIGHUP) { if(i == SIGHUP) {
runtime·memclr((byte*)&sa, sizeof sa); runtime·memclr((byte*)&sa, sizeof sa);
runtime·sigaction(i, nil, &sa); runtime·rt_sigaction(i, nil, &sa, sizeof(sa.sa_mask));
if(sa.sa_handler == SIG_IGN) if(sa.sa_handler == SIG_IGN)
return; return;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
extern SigTab runtime·sigtab[]; extern SigTab runtime·sigtab[];
static Sigset sigset_none;
static Sigset sigset_all = ~(Sigset)0; static Sigset sigset_all = ~(Sigset)0;
static Sigset sigset_prof = 1<<(SIGPROF-1); static Sigset sigset_prof = 1<<(SIGPROF-1);
...@@ -98,8 +99,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void)) ...@@ -98,8 +99,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
} }
runtime·sigprocmask(SIG_SETMASK, &sigset_all, &oset); runtime·sigprocmask(SIG_SETMASK, &sigset_all, &oset);
mp->sigset = runtime·mal(sizeof(Sigset));
*(Sigset*)mp->sigset = oset;
errno = runtime·bsdthread_create(stk, mp, gp, fn); errno = runtime·bsdthread_create(stk, mp, gp, fn);
runtime·sigprocmask(SIG_SETMASK, &oset, nil); runtime·sigprocmask(SIG_SETMASK, &oset, nil);
...@@ -117,8 +116,7 @@ runtime·minit(void) ...@@ -117,8 +116,7 @@ runtime·minit(void)
m->gsignal = runtime·malg(32*1024); // OS X wants >=8K, Linux >=2K m->gsignal = runtime·malg(32*1024); // OS X wants >=8K, Linux >=2K
runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024); runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
if(m->sigset != nil) runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil);
runtime·sigprocmask(SIG_SETMASK, m->sigset, nil);
runtime·setprof(m->profilehz > 0); runtime·setprof(m->profilehz > 0);
} }
......
...@@ -13,6 +13,7 @@ extern int32 runtime·sys_umtx_op(uint32*, int32, uint32, void*, void*); ...@@ -13,6 +13,7 @@ extern int32 runtime·sys_umtx_op(uint32*, int32, uint32, void*, void*);
#define CTL_HW 6 #define CTL_HW 6
#define HW_NCPU 3 #define HW_NCPU 3
static Sigset sigset_none;
static Sigset sigset_all = { ~(uint32)0, ~(uint32)0, ~(uint32)0, ~(uint32)0, }; static Sigset sigset_all = { ~(uint32)0, ~(uint32)0, ~(uint32)0, ~(uint32)0, };
static int32 static int32
...@@ -90,8 +91,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void)) ...@@ -90,8 +91,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
} }
runtime·sigprocmask(&sigset_all, &oset); runtime·sigprocmask(&sigset_all, &oset);
mp->sigset = runtime·mal(sizeof(Sigset));
*(Sigset*)mp->sigset = oset;
runtime·memclr((byte*)&param, sizeof param); runtime·memclr((byte*)&param, sizeof param);
param.start_func = runtime·thr_start; param.start_func = runtime·thr_start;
...@@ -128,8 +127,7 @@ runtime·minit(void) ...@@ -128,8 +127,7 @@ runtime·minit(void)
// Initialize signal handling // Initialize signal handling
m->gsignal = runtime·malg(32*1024); m->gsignal = runtime·malg(32*1024);
runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024); runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
if(m->sigset != nil) runtime·sigprocmask(&sigset_none, nil);
runtime·sigprocmask(m->sigset, nil);
} }
void void
......
...@@ -13,6 +13,7 @@ int32 runtime·open(uint8*, int32, int32); ...@@ -13,6 +13,7 @@ int32 runtime·open(uint8*, int32, int32);
int32 runtime·close(int32); int32 runtime·close(int32);
int32 runtime·read(int32, void*, int32); int32 runtime·read(int32, void*, int32);
static Sigset sigset_none;
static Sigset sigset_all = { ~(uint32)0, ~(uint32)0 }; static Sigset sigset_all = { ~(uint32)0, ~(uint32)0 };
// Linux futex. // Linux futex.
...@@ -148,8 +149,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void)) ...@@ -148,8 +149,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
// Disable signals during clone, so that the new thread starts // Disable signals during clone, so that the new thread starts
// with signals disabled. It will enable them in minit. // with signals disabled. It will enable them in minit.
runtime·rtsigprocmask(SIG_SETMASK, &sigset_all, &oset, sizeof oset); runtime·rtsigprocmask(SIG_SETMASK, &sigset_all, &oset, sizeof oset);
mp->sigset = runtime·mal(sizeof(Sigset));
*(Sigset*)mp->sigset = oset;
ret = runtime·clone(flags, stk, mp, gp, fn); ret = runtime·clone(flags, stk, mp, gp, fn);
runtime·rtsigprocmask(SIG_SETMASK, &oset, nil, sizeof oset); runtime·rtsigprocmask(SIG_SETMASK, &oset, nil, sizeof oset);
...@@ -178,8 +177,7 @@ runtime·minit(void) ...@@ -178,8 +177,7 @@ runtime·minit(void)
// Initialize signal handling. // Initialize signal handling.
m->gsignal = runtime·malg(32*1024); // OS X wants >=8K, Linux >=2K m->gsignal = runtime·malg(32*1024); // OS X wants >=8K, Linux >=2K
runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024); runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
if(m->sigset != nil) runtime·rtsigprocmask(SIG_SETMASK, &sigset_none, nil, sizeof(Sigset));
runtime·rtsigprocmask(SIG_SETMASK, m->sigset, nil, sizeof *m->sigset);
} }
void void
......
...@@ -20,6 +20,7 @@ enum ...@@ -20,6 +20,7 @@ enum
extern SigTab runtime·sigtab[]; extern SigTab runtime·sigtab[];
static Sigset sigset_none;
static Sigset sigset_all = { ~(uint32)0, ~(uint32)0, ~(uint32)0, ~(uint32)0, }; static Sigset sigset_all = { ~(uint32)0, ~(uint32)0, ~(uint32)0, ~(uint32)0, };
extern void runtime·getcontext(UcontextT *context); extern void runtime·getcontext(UcontextT *context);
...@@ -163,9 +164,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void)) ...@@ -163,9 +164,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
uc.uc_link = nil; uc.uc_link = nil;
uc.uc_sigmask = sigset_all; uc.uc_sigmask = sigset_all;
mp->sigset = runtime·mal(sizeof(Sigset));
runtime·sigprocmask(SIG_SETMASK, nil, mp->sigset);
runtime·lwp_mcontext_init(&uc.uc_mcontext, stk, mp, gp, fn); runtime·lwp_mcontext_init(&uc.uc_mcontext, stk, mp, gp, fn);
ret = runtime·lwp_create(&uc, 0, &mp->procid); ret = runtime·lwp_create(&uc, 0, &mp->procid);
...@@ -197,8 +195,7 @@ runtime·minit(void) ...@@ -197,8 +195,7 @@ runtime·minit(void)
// Initialize signal handling // Initialize signal handling
m->gsignal = runtime·malg(32*1024); m->gsignal = runtime·malg(32*1024);
runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024); runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
if(m->sigset != nil) runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil);
runtime·sigprocmask(SIG_SETMASK, m->sigset, nil);
} }
void void
......
...@@ -20,6 +20,7 @@ enum ...@@ -20,6 +20,7 @@ enum
extern SigTab runtime·sigtab[]; extern SigTab runtime·sigtab[];
static Sigset sigset_none;
static Sigset sigset_all = ~(Sigset)0; static Sigset sigset_all = ~(Sigset)0;
extern int64 runtime·tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void)); extern int64 runtime·tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
...@@ -141,8 +142,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void)) ...@@ -141,8 +142,6 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
param.tf_stack = stk; param.tf_stack = stk;
oset = runtime·sigprocmask(SIG_SETMASK, sigset_all); oset = runtime·sigprocmask(SIG_SETMASK, sigset_all);
mp->sigset = runtime·mal(sizeof(Sigset));
*(Sigset*)mp->sigset = oset;
ret = runtime·tfork((byte*)&param, sizeof(param), mp, gp, fn); ret = runtime·tfork((byte*)&param, sizeof(param), mp, gp, fn);
runtime·sigprocmask(SIG_SETMASK, oset); runtime·sigprocmask(SIG_SETMASK, oset);
...@@ -173,8 +172,7 @@ runtime·minit(void) ...@@ -173,8 +172,7 @@ runtime·minit(void)
// Initialize signal handling // Initialize signal handling
m->gsignal = runtime·malg(32*1024); m->gsignal = runtime·malg(32*1024);
runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024); runtime·signalstack((byte*)m->gsignal->stackguard - StackGuard, 32*1024);
if(m->sigset != nil) runtime·sigprocmask(SIG_SETMASK, &sigset_none, nil, sizeof sigset_none);
runtime·sigprocmask(SIG_SETMASK, m->sigset, nil, sizeof *m->sigset);
} }
void void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment